Exemplo n.º 1
0
 def incr_inline(inp):
     return {'res': Int(inp.value + 2)}
Exemplo n.º 2
0
 def test_function_inline(inp):
     return {'result': Int(inp.value + 1)}
Exemplo n.º 3
0
 def test_length(self):
     input = {'a': Int(5).store(), 'b': Str('testing').store()}
     d = FrozenDict(dict=input)
     self.assertEqual(len(input), len(d))
Exemplo n.º 4
0
from aiida.orm.data.int import Int
from aiida.work.workchain import WorkChain

class AddAndMultiplyWorkChain(WorkChain):
    ...

    def submit_sub_workchain(self)
        node = self.submit(AddAndMultiplyWorkChain, a=Int(1), b=Int(2), c=Int(3))
Exemplo n.º 5
0
 def test_get_value(self):
     input = {'a': Int(5).store()}
     d = FrozenDict(dict=input)
     self.assertEqual(d['a'], input['a'])
Exemplo n.º 6
0
 def test_iterate(self):
     input = {'a': Int(5).store(), 'b': Str('testing').store()}
     d = FrozenDict(dict=input)
     for k, v in d.iteritems():
         self.assertEqual(input[k], v)
Exemplo n.º 7
0
def main():
    expected_results_calculations = {}
    expected_results_workchains = {}
    code = Code.get_from_string(codename)

    # Submitting the Calculations the old way, creating and storing a JobCalc first and submitting it
    print "Submitting {} old style calculations to the daemon".format(
        number_calculations)
    for counter in range(1, number_calculations + 1):
        inputval = counter
        calc, expected_result = submit_calculation(code=code,
                                                   counter=counter,
                                                   inputval=inputval)
        expected_results_calculations[calc.pk] = expected_result

    # Submitting the Calculations the new way directly through the launchers
    print "Submitting {} new style calculations to the daemon".format(
        number_calculations)
    for counter in range(1, number_calculations + 1):
        inputval = counter
        calc, expected_result = launch_calculation(code=code,
                                                   counter=counter,
                                                   inputval=inputval)
        expected_results_calculations[calc.pk] = expected_result

    # Submitting the Workchains
    print "Submitting {} workchains to the daemon".format(number_workchains)
    for index in range(number_workchains):
        inp = Int(index)
        result, node = run_get_node(NestedWorkChain, inp=inp)
        expected_results_workchains[node.pk] = index

    print "Submitting a workchain with 'submit'."
    builder = NestedWorkChain.get_builder()
    input_val = 4
    builder.inp = Int(input_val)
    proc = submit(builder)
    expected_results_workchains[proc.pk] = input_val

    print "Submitting a workchain with a nested input namespace."
    value = Int(-12)
    pk = submit(NestedInputNamespace, foo={'bar': {'baz': value}}).pk

    print "Submitting a workchain with a dynamic non-db input."
    value = [4, 2, 3]
    pk = submit(DynamicNonDbInput, namespace={'input': value}).pk
    expected_results_workchains[pk] = value

    print "Submitting a workchain with a dynamic db input."
    value = 9
    pk = submit(DynamicDbInput, namespace={'input': Int(value)}).pk
    expected_results_workchains[pk] = value

    print "Submitting a workchain with a mixed (db / non-db) dynamic input."
    value_non_db = 3
    value_db = Int(2)
    pk = submit(DynamicMixedInput,
                namespace={
                    'inputs': {
                        'input_non_db': value_non_db,
                        'input_db': value_db
                    }
                }).pk
    expected_results_workchains[pk] = value_non_db + value_db

    print("Submitting the serializing workchain")
    pk = submit(SerializeWorkChain, test=Int).pk
    expected_results_workchains[pk] = ObjectLoader().identify_object(Int)

    print "Submitting the ListEcho workchain."
    list_value = List()
    list_value.extend([1, 2, 3])
    pk = submit(ListEcho, list=list_value).pk
    expected_results_workchains[pk] = list_value

    print "Submitting a WorkChain which contains a workfunction."
    value = Str('workfunction test string')
    pk = submit(WorkFunctionRunnerWorkChain, input=value).pk
    expected_results_workchains[pk] = value

    print "Submitting a WorkChain which contains an InlineCalculation."
    value = Str('test_string')
    pk = submit(InlineCalcRunnerWorkChain, input=value).pk
    expected_results_workchains[pk] = value

    calculation_pks = sorted(expected_results_calculations.keys())
    workchains_pks = sorted(expected_results_workchains.keys())
    pks = calculation_pks + workchains_pks

    print "Wating for end of execution..."
    start_time = time.time()
    exited_with_timeout = True
    while time.time() - start_time < timeout_secs:
        time.sleep(15)  # Wait a few seconds

        # Print some debug info, both for debugging reasons and to avoid
        # that the test machine is shut down because there is no output

        print "#" * 78
        print "####### TIME ELAPSED: {} s".format(time.time() - start_time)
        print "#" * 78
        print "Output of 'verdi calculation list -a':"
        try:
            print subprocess.check_output(
                ["verdi", "calculation", "list", "-a"],
                stderr=subprocess.STDOUT,
            )
        except subprocess.CalledProcessError as e:
            print "Note: the command failed, message: {}".format(e.message)

        print "Output of 'verdi work list':"
        try:
            print subprocess.check_output(
                ['verdi', 'work', 'list', '-a', '-p1'],
                stderr=subprocess.STDOUT,
            )
        except subprocess.CalledProcessError as e:
            print "Note: the command failed, message: {}".format(e.message)

        print "Output of 'verdi daemon status':"
        try:
            print subprocess.check_output(
                ["verdi", "daemon", "status"],
                stderr=subprocess.STDOUT,
            )
        except subprocess.CalledProcessError as e:
            print "Note: the command failed, message: {}".format(e.message)

        if jobs_have_finished(pks):
            print "Calculation terminated its execution"
            exited_with_timeout = False
            break

    if exited_with_timeout:
        print_daemon_log()
        print ""
        print "Timeout!! Calculation did not complete after {} seconds".format(
            timeout_secs)
        sys.exit(2)
    else:
        # create cached calculations -- these should be FINISHED immediately
        cached_calcs = []
        for counter in range(1, number_calculations + 1):
            calc, expected_result = create_cache_calc(code=code,
                                                      counter=counter,
                                                      inputval=counter)
            cached_calcs.append(calc)
            expected_results_calculations[calc.pk] = expected_result
        # new style cached calculations, with 'run'
        with enable_caching():
            for counter in range(1, number_calculations + 1):
                calc, expected_result = run_calculation(code=code,
                                                        counter=counter,
                                                        inputval=counter)
                cached_calcs.append(calc)
                expected_results_calculations[calc.pk] = expected_result

        if (validate_calculations(expected_results_calculations)
                and validate_workchains(expected_results_workchains)
                and validate_cached(cached_calcs)):
            print_daemon_log()
            print ""
            print "OK, all calculations have the expected parsed result"
            sys.exit(0)
        else:
            print_daemon_log()
            print ""
            print "ERROR! Some return values are different from the expected value"
            sys.exit(3)
Exemplo n.º 8
0
#!/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}
from aiida.orm.data.int import Int
from aiida.work.launch import submit
from aiida.work.workchain import WorkChain


class AddAndMultiplyWorkChain(WorkChain):
    ...


builder = AddAndMultiplyWorkChain.get_builder()
builder.a = Int(1)
builder.b = Int(2)
builder.c = Int(3)

node = submit(builder)
Exemplo n.º 10
0
 def test_run_get_node(self):
     inputs = {'a': Int(2), 'b': Str('test')}
     result, node = run_get_node(DummyProcess, **inputs)
     self.assertIsInstance(node, aiida.orm.Calculation)
Exemplo n.º 11
0
 def test_run(self):
     inputs = {'a': Int(2), 'b': Str('test')}
     result = run(DummyProcess, **inputs)