def test_run(self): A = to_db_type('A') B = to_db_type('B') C = to_db_type('C') three = to_db_type(3) # Try the if(..) part Wf.run(inputs={'value': A, 'n': three}) # Check the steps that should have been run for step, finished in Wf.finished_steps.iteritems(): if step not in ['s3', 's4', 'isB']: self.assertTrue( finished, "Step {} was not called by workflow".format(step)) # Try the elif(..) part finished_steps = Wf.run(inputs={'value': B, 'n': three}) # Check the steps that should have been run for step, finished in finished_steps.iteritems(): if step not in ['isA', 's2', 's4']: self.assertTrue( finished, "Step {} was not called by workflow".format(step)) # Try the else... part finished_steps = Wf.run(inputs={'value': C, 'n': three}) # Check the steps that should have been run for step, finished in finished_steps.iteritems(): if step not in ['isA', 's2', 'isB', 's3']: self.assertTrue( finished, "Step {} was not called by workflow".format(step))
def s1(self, ctx): time.sleep(2) self.out("r2", self.inputs.a) class F1WaitFor(FragmentedWorkfunction): @classmethod def _define(cls, spec): spec.dynamic_input() spec.dynamic_output() spec.outline(cls.s1, cls.s2) def s1(self, ctx): p2 = async (long_running, a=self.inputs.inp) ctx.a = 1 ctx.r2 = p2.result() def s2(self, ctx): print("a={}".format(ctx.a)) print("r2={}".format(ctx.r2)) self.out("r1", ctx.r2['r2']) if __name__ == '__main__': five = to_db_type(5) r1 = f1(five) F1.run(inputs={'inp': five}) R1 = F1WaitFor.run(inputs={'inp': five})['r1']
def _run(self, a, b): self.out('value', to_db_type(a.value * b.value))
def prod(a, b): return to_db_type(a.value * b.value)
def sum(a, b): return to_db_type(a.value + b.value)
from aiida.backends.utils import load_dbenv, is_dbenv_loaded __copyright__ = u"Copyright (c), This file is part of the AiiDA platform. For further information please visit http://www.aiida.net/. All rights reserved." __license__ = "MIT license, see LICENSE.txt file." __authors__ = "The AiiDA team." __version__ = "0.7.0" if not is_dbenv_loaded(): load_dbenv() from aiida.workflows2.wf import wf from aiida.workflows2.run import async from aiida.workflows2.db_types import to_db_type _True = to_db_type(True) @wf def simple_wf(): return {'result': _True} @wf def return_input(inp): return {'result': inp} class TestWf(unittest.TestCase): def test_blocking(self): self.assertTrue(simple_wf()['result'].value)
def muliply_wf(a, b): return {'value': to_db_type(a.value * b.value)}
def add_wf(a, b): return {'value': to_db_type(a.value + b.value)}
class MulAdd(Workflow): @staticmethod def _define(spec): spec.process(Mul) spec.process(Add) spec.exposed_inputs('Add') spec.exposed_outputs('Mul') spec.input('c') spec.link(':c', 'Mul:a') spec.link('Add:value', 'Mul:b') if __name__ == '__main__': two = to_db_type(2) three = to_db_type(3) four = to_db_type(4) print "WORKFUNCTION:" simpledata = async (add_multiply_wf, two, three, four).result()['value'] print "output pk:", simpledata.pk print "output value:", simpledata.value print "PROCESS:" simpledata = MulAdd.run(inputs={'a': two, 'b': three, 'c': four})['value'] print "output pk:", simpledata.pk print "output value:", simpledata.value