コード例 #1
0
ファイル: workchain.py プロジェクト: asle85/aiida-core
    def save_instance_state(self, out_state):
        super(WorkChain, self).save_instance_state(out_state)

        # Ask the context to save itself
        bundle = Bundle()
        self.ctx.save_instance_state(bundle)
        out_state[self._CONTEXT] = bundle

        # Save intersteps
        for interstep in self._intersteps:
            bundle = Bundle()
            interstep.save_instance_state(bundle)
            out_state.setdefault(self._INTERSTEPS, []).append(bundle)

        # Save barriers
        for barrier in self._barriers:
            bundle = Bundle()
            barrier.save_instance_state(bundle)
            out_state.setdefault(self._BARRIERS, []).append(bundle)

        # Ask the stepper to save itself
        if self._stepper is not None:
            bundle = Bundle()
            self._stepper.save_position(bundle)
            out_state[self._STEPPER_STATE] = bundle

        out_state[self._ABORTED] = self._aborted
コード例 #2
0
ファイル: process.py プロジェクト: sphuber/plumpy
    def save_instance_state(self, bundle):
        """
        Ask the process to save its current instance state.

        :param bundle: A bundle to save the state to
        :type bundle: :class:`plum.persistence.Bundle`
        """
        # TODO: Add a timeout to this method, the user may not want to wait
        # indefinitely for the lock
        with self.__save_lock:
            # Immutables first
            bundle[self.BundleKeys.CREATION_TIME.value] = self.creation_time
            bundle[self.BundleKeys.CLASS_NAME.value] = util.fullname(self)
            bundle[self.BundleKeys.PID.value] = self.pid

            # Now state stuff
            state_bundle = Bundle()
            self._state.save_instance_state(state_bundle)
            bundle[self.BundleKeys.STATE.value] = state_bundle

            bundle[self.BundleKeys.FINISHED.value] = self._finished
            bundle[self.BundleKeys.TERMINATED.value] = self._terminated

            # Inputs/outputs
            bundle.set_if_not_none(self.BundleKeys.INPUTS.value,
                                   self.raw_inputs)
            bundle[self.BundleKeys.OUTPUTS.value] = Bundle(self._outputs)
コード例 #3
0
 def test_created_bundle(self):
     """
     Check that the bundle after just creating a process is as we expect
     :return:
     """
     proc = DummyProcessWithOutput.new()
     b = Bundle()
     proc.save_instance_state(b)
     self.assertIsNone(b.get('inputs', None))
     self.assertEqual(len(b['outputs']), 0)
コード例 #4
0
ファイル: workchain.py プロジェクト: merkys/aiida_core
    def save_instance_state(self, out_state):
        super(WorkChain, self).save_instance_state(out_state)
        # Ask the context to save itself
        context_state = Bundle()
        self.ctx.save_instance_state(context_state)
        out_state[self._CONTEXT] = context_state

        # Ask the stepper to save itself
        if self._stepper is not None:
            stepper_state = Bundle()
            self._stepper.save_position(stepper_state)
            out_state[self._STEPPER_STATE] = stepper_state
コード例 #5
0
ファイル: workchain.py プロジェクト: asle85/aiida-core
 def save_position(self, out_position):
     if self._stepper is not None:
         stepper_pos = Bundle()
         self._stepper.save_position(stepper_pos)
         out_position[self._STEPPER_POS] = stepper_pos
     out_position[self._CHECK_CONDITION] = self._check_condition
     out_position[self._FINISHED] = self._finished
コード例 #6
0
ファイル: process.py プロジェクト: DropD/plumpy
    def save_instance_state(self, bundle):
        """
        As the process to save its current instance state.

        :param bundle: A bundle to save the state to
        :type bundle: :class:`plum.persistence.Bundle`
        """
        bundle[self.BundleKeys.CLASS_NAME.value] = util.fullname(self)
        bundle[self.BundleKeys.STATE.value] = self.state
        bundle[self.BundleKeys.PID.value] = self.pid
        bundle[self.BundleKeys.FINISHED.value] = self._finished
        bundle[self.BundleKeys.ABORTED.value] = self._aborted
        bundle.set_if_not_none(self.BundleKeys.EXCEPTION.value, self._exception)
        if self._next_transition is not None:
            bundle[self.BundleKeys.NEXT_TRANSITION.value] = \
                self._next_transition.__name__

        bundle.set_if_not_none(self.BundleKeys.ABORT_MSG.value, self._abort_msg)

        # Save inputs and outputs
        bundle.set_if_not_none(self.BundleKeys.INPUTS.value, self.raw_inputs)
        bundle[self.BundleKeys.OUTPUTS.value] = Bundle(self._outputs)

        if self._wait is not None:
            bundle[self.BundleKeys.WAITING_ON.value] = self.save_wait_on_state()
            bundle[self.BundleKeys.WAIT_ON_CALLBACK.value] = \
                self._wait.callback.__name__
コード例 #7
0
ファイル: persistence.py プロジェクト: asle85/aiida-core
    def create_bundle(self, process):
        bundle = Bundle()
        process.save_instance_state(bundle)
        inputs = bundle[Process.BundleKeys.INPUTS.value]
        if inputs:
            bundle[Process.BundleKeys.INPUTS.value] = self._convert_to_ids(inputs)

        return bundle
コード例 #8
0
ファイル: workchain.py プロジェクト: asle85/aiida-core
 def save_position(self, out_position):
     out_position[self._POSITION] = self._pos
     # Save the position of the current step we're working (if it's not a
     # direct function)
     if self._current_stepper is not None:
         stepper_pos = Bundle()
         self._current_stepper.save_position(stepper_pos)
         out_position[self._STEPPER_POS] = stepper_pos
コード例 #9
0
 def save_instance_state(self, out_state):
     super(self.__class__, self).save_instance_state(out_state)
     # Save all the waits lists
     waits = []
     for w in self._wait_list:
         b = Bundle()
         w.save_instance_state(b)
         waits.append(b)
     out_state[self.WAIT_LIST] = waits
コード例 #10
0
ファイル: process.py プロジェクト: DropD/plumpy
    def save_wait_on_state(self):
        """
        Create a saved instance state for the WaitOn the process is currently
        waiting for.  If the wait on is :class:`plum.wait.Unsavable` then
        the process should override this and save some information that allows
        it to recreate it.

        :return: The saved instance state of the wait on
        :rtype: :class:`plum.persistence.bundle.Bundle`
        """
        b = Bundle()
        self.get_waiting_on().save_instance_state(b)
        return b
コード例 #11
0
    def _check_process_against_snapshot(self, snapshot, proc):
        self.assertEqual(snapshot.state, proc.state)

        new_bundle = Bundle()
        proc.save_instance_state(new_bundle)
        self.assertEqual(
            snapshot.bundle, new_bundle,
            "Bundle mismatch with process class {}\n"
            "Snapshot:\n{}\n"
            "Loaded:\n{}".format(proc.__class__, snapshot.bundle, new_bundle))

        self.assertEqual(
            snapshot.outputs, proc.outputs,
            "Outputs mismatch with process class {}\n"
            "Snapshot:\n{}\n"
            "Loaded:\n{}".format(proc.__class__, snapshot.outputs,
                                 proc.outputs))
コード例 #12
0
    def test_restart(self):
        p = _RestartProcess.new()

        future = self.executor.play(p)
        self.assertTrue(wait_until(p, ProcessState.WAITING, timeout=2.))

        # Save the state of the process
        bundle = Bundle()
        p.save_instance_state(bundle)
        self.assertTrue(future.abort(timeout=2.))

        # Load a process from the saved state
        p = _RestartProcess.create_from(bundle)
        self.assertEqual(p.state, ProcessState.WAITING)

        # Now play it
        future = self.executor.play(p)
        p.continue_()
        self.assertEqual(future.result(timeout=1.0), {'finished': True})
コード例 #13
0
ファイル: workChain.py プロジェクト: wsmorgan/aiida_core
    def test_if_block_persistence(self):
        """ This test was created to capture issue #902 """
        wc = IfTest.new_instance()

        while not wc.ctx.s1 and not wc.has_finished():
            wc.tick()
        self.assertTrue(wc.ctx.s1)
        self.assertFalse(wc.ctx.s2)

        # Now bundle the thing
        b = Bundle()
        wc.save_instance_state(b)
        # Abort the current one
        wc.stop()
        wc.destroy(execute=True)

        # Load from saved tate
        wc = IfTest.create_from(b)
        self.assertTrue(wc.ctx.s1)
        self.assertFalse(wc.ctx.s2)

        wc.run_until_complete()
コード例 #14
0
ファイル: workchain.py プロジェクト: asle85/aiida-core
 def save_position(self, out_position):
     out_position[self._POSITION] = self._pos
     if self._current_stepper is not None:
         stepper_pos = Bundle()
         self._current_stepper.save_position(stepper_pos)
         out_position[self._STEPPER_POS] = stepper_pos
コード例 #15
0
ファイル: pickle_persistence.py プロジェクト: DropD/plumpy
 def create_bundle(self, process):
     checkpoint = Bundle()
     process.save_instance_state(checkpoint)
     return checkpoint
コード例 #16
0
ファイル: test_utils.py プロジェクト: sphuber/plumpy
def create_snapshot(proc):
    b = Bundle()
    proc.save_instance_state(b)
    return Snapshot(proc.state, b, proc.outputs.copy())
コード例 #17
0
ファイル: test_utils.py プロジェクト: sphuber/plumpy
 def save_instance_state(self, bundle):
     super(WaitForSignalProcess, self).save_instance_state(bundle)
     bundle[self.BARRIER] = Bundle()
     self._barrier.save_instance_state(bundle[self.BARRIER])
コード例 #18
0
ファイル: test_utils.py プロジェクト: sphuber/plumpy
 def _save(self, p):
     b = Bundle()
     p.save_instance_state(b)
     self.snapshots.append((p.state, b))
     self.outputs.append(p.outputs.copy())