def test_failing_workchain_with_message(self): result, node = work.run_get_node(PotentialFailureWorkChain, success=Bool(False), through_exit_code=Bool(True)) self.assertEquals(node.exit_status, PotentialFailureWorkChain.EXIT_STATUS) self.assertEquals(node.exit_message, PotentialFailureWorkChain.EXIT_MESSAGE) self.assertEquals(node.is_finished, True) self.assertEquals(node.is_finished_ok, False) self.assertEquals(node.is_failed, True)
def setUpClass(cls, *args, **kwargs): super(TestVerdiRehash, cls).setUpClass(*args, **kwargs) from aiida.orm import Node from aiida.orm.data.bool import Bool from aiida.orm.data.float import Float from aiida.orm.data.int import Int cls.node_base = Node().store() cls.node_bool_true = Bool(True).store() cls.node_bool_false = Bool(False).store() cls.node_float = Float(1.0).store() cls.node_int = Int(1).store()
def test_workchain(self): """ Verify that the attributes of the TestWorkChain can be set but defaults are not there """ builder = TestWorkChain.get_builder() builder.a = Int(2) builder.b = Float(2.3) builder.c.d = Bool(True) self.assertEquals(builder, { 'a': Int(2), 'b': Float(2.3), 'c': { 'd': Bool(True) } })
def test_simple_kill_through_process(self): """ Run the workchain for one step and then kill it. This should have the workchain and its children end up in the KILLED state. """ process = TestWorkChainAbortChildren.MainWorkChain( inputs={'kill': Bool(True)}) # process.add_on_waiting_callback(lambda _: process.pause()) @gen.coroutine def run_async(): yield run_until_waiting(process) process.kill() with self.assertRaises(plumpy.KilledError): result = yield process.future() self.runner.loop.add_callback(process.step_until_terminated) self.runner.loop.run_sync(lambda: run_async()) child = process.calc.get_outputs(link_type=LinkType.CALL)[0] self.assertEquals(child.is_finished_ok, False) self.assertEquals(child.is_excepted, False) self.assertEquals(child.is_killed, True) self.assertEquals(process.calc.is_finished_ok, False) self.assertEquals(process.calc.is_excepted, False) self.assertEquals(process.calc.is_killed, True)
def test_successful_workchain(self): result, node = work.run_get_node(PotentialFailureWorkChain, success=Bool(True)) self.assertEquals(node.exit_status, 0) self.assertEquals(node.is_finished, True) self.assertEquals(node.is_finished_ok, True) self.assertEquals(node.is_failed, False)
def test_dynamic_getters_value(self): """ Verify that getters will return the actual value """ builder = TestWorkChain.get_builder() builder.a = Int(2) builder.b = Float(2.3) builder.c.d = Bool(True) # Verify that the correct type is returned by the getter self.assertTrue(isinstance(builder.a, Int)) self.assertTrue(isinstance(builder.b, Float)) self.assertTrue(isinstance(builder.c.d, Bool)) # Verify that the correct value is returned by the getter self.assertEquals(builder.a, Int(2)) self.assertEquals(builder.b, Float(2.3)) self.assertEquals(builder.c.d, Bool(True))
def test_nested_expose(self): res = work.run(GrandParentExposeWorkChain, sub=dict(sub=dict( a=Int(1), sub_1={ 'b': Float(2.3), 'c': Bool(True) }, sub_2={ 'b': Float(1.2), 'sub_3': { 'c': Bool(False) } }, ))) self.assertEquals( res, { 'sub.sub.a': Float(2.2), 'sub.sub.sub_1.b': Float(2.3), 'sub.sub.sub_1.c': Bool(True), 'sub.sub.sub_2.b': Float(1.2), 'sub.sub.sub_2.sub_3.c': Bool(False) })
def test_expose(self): res = work.run( ParentExposeWorkChain, a=Int(1), sub_1={ 'b': Float(2.3), 'c': Bool(True) }, sub_2={ 'b': Float(1.2), 'sub_3': { 'c': Bool(False) } }, ) self.assertEquals( res, { 'a': Float(2.2), 'sub_1.b': Float(2.3), 'sub_1.c': Bool(True), 'sub_2.b': Float(1.2), 'sub_2.sub_3.c': Bool(False) })
#!/usr/bin/env runaiida from __future__ import print_function from aiida.orm.data.bool import Bool from aiida.orm.data.float import Float from aiida.orm.data.int import Int from aiida.work import run from complex_parent import ComplexParentWorkChain if __name__ == '__main__': result = run(ComplexParentWorkChain, a=Int(1), child_1=dict(b=Float(1.2), c=Bool(True)), child_2=dict(b=Float(2.3), c=Bool(False))) print(result) # { # u'e': 1.2, # u'child_1.d': 1, u'child_1.f': True, # u'child_2.d': 1, u'child_2.f': False # }
def define(cls, spec): super(TestWorkChainAbortChildren.MainWorkChain, cls).define(spec) spec.input('kill', default=Bool(False)) spec.outline(cls.submit_child, cls.check)
def define(cls, spec): super(PotentialFailureWorkChain, cls).define(spec) spec.input('success', valid_type=Bool) spec.input('through_exit_code', valid_type=Bool, default=Bool(False)) spec.exit_code(cls.EXIT_STATUS, 'EXIT_STATUS', cls.EXIT_MESSAGE) spec.outline(cls.failure, cls.success)
def define(cls, spec): super(TestDefaultUniqueness.Child, cls).define(spec) spec.input('a', valid_type=Bool, default=Bool(True))
#!/usr/bin/env runaiida from __future__ import print_function from aiida.orm.data.bool import Bool from aiida.orm.data.float import Float from aiida.orm.data.int import Int from aiida.work import run from simple_parent import SimpleParentWorkChain if __name__ == '__main__': result = run(SimpleParentWorkChain, a=Int(1), b=Float(1.2), c=Bool(True)) print(result) # {u'e': 1.2, u'd': 1, u'f': True}