Beispiel #1
0
        def parse_calcfunction(**kwargs):
            """A wrapper function that will turn calling the `Parser.parse` method into a `CalcFunctionNode`.

            .. warning:: This implementation of a `calcfunction` uses the `Process.current` to circumvent the limitation
                of not being able to return both output nodes as well as an exit code. However, since this calculation
                function is supposed to emulate the parsing of a `CalcJob`, which *does* have that capability, I have
                to use this method. This method should however not be used in process functions, in other words:

                    Do not try this at home!

            :param kwargs: keyword arguments that are passed to `Parser.parse` after it has been constructed
            """
            from aiida.engine import Process

            if retrieved_temporary_folder is not None:
                kwargs['retrieved_temporary_folder'] = retrieved_temporary_folder

            exit_code = parser.parse(**kwargs)
            outputs = parser.outputs

            if exit_code and exit_code.status:
                # In the case that an exit code was returned, still attach all the registered outputs on the current
                # process as well, which should represent this `CalcFunctionNode`. Otherwise the caller of the
                # `parse_from_node` method will get an empty dictionary as a result, despite the `Parser.parse` method
                # having registered outputs.
                process = Process.current()
                process.out_many(outputs)
                return exit_code

            return dict(outputs)
Beispiel #2
0
    def setUp(self):
        super(TestCalcFunction, self).setUp()
        self.assertIsNone(Process.current())
        self.default_int = Int(256)

        @calcfunction
        def test_calcfunction(data):
            return Int(data.value + 1)

        self.test_calcfunction = test_calcfunction
    def setUp(self):
        super().setUp()
        self.assertIsNone(Process.current())
        self.default_int = Int(256)

        @workfunction
        def test_workfunction(data):
            return data

        self.test_workfunction = test_workfunction
Beispiel #4
0
    def tearDown(self):
        import os
        import shutil
        from aiida.common.folders import CALC_JOB_DRY_RUN_BASE_PATH

        super().tearDown()
        self.assertIsNone(Process.current())

        # Make sure to clean the test directory that will be generated by the dry-run
        filepath = os.path.join(os.getcwd(), CALC_JOB_DRY_RUN_BASE_PATH)
        try:
            shutil.rmtree(filepath)
        except Exception:  # pylint: disable=broad-except
            pass
Beispiel #5
0
 def setUp(self):
     super().setUp()
     self.assertIsNone(Process.current())
     self.process_class = CalculationFactory('templatereplacer')
     self.builder = self.process_class.get_builder()
     self.builder_workchain = ExampleWorkChain.get_builder()
     self.inputs = {
         'dynamic': {
             'namespace': {
                 'alp': orm.Int(1).store()
             }
         },
         'name': {
             'spaced': orm.Int(1).store(),
         },
         'name_spaced': orm.Str('underscored').store(),
         'boolean': orm.Bool(True).store(),
         'metadata': {}
     }
def run_eos_wf(code, pseudo_family, element):
    """Run an equation of state of a bulk crystal structure for the given element."""

    # This will print the pk of the work function
    print('Running run_eos_wf<{}>'.format(Process.current().pid))

    scale_factors = (0.96, 0.98, 1.0, 1.02, 1.04)
    labels = ['c1', 'c2', 'c3', 'c4', 'c5']

    calculations = {}

    # Create an initial bulk crystal structure for the given element, using the calculation function defined earlier
    initial_structure = create_diamond_fcc(element)

    # Loop over the label and scale_factor pairs
    for label, factor in list(zip(labels, scale_factors)):

        # Generated the scaled structure from the initial structure
        structure = rescale(initial_structure, Float(factor))

        # Generate the inputs for the `PwCalculation`
        inputs = generate_scf_input_params(structure, code, pseudo_family)

        # Launch a `PwCalculation` for each scaled structure
        print('Running a scf for {} with scale factor {}'.format(
            element, factor))
        calculations[label] = run(PwCalculation, **inputs)

    # Bundle the individual results from each `PwCalculation` in a single dictionary node.
    # Note: since we are 'creating' new data from existing data, we *have* to go through a `calcfunction`, otherwise
    # the provenance would be lost!
    inputs = {
        label: result['output_parameters']
        for label, result in calculations.items()
    }
    eos = create_eos_dictionary(**inputs)

    # Finally, return the results of this work function
    result = {'initial_structure': initial_structure, 'eos': eos}

    return result
Beispiel #7
0
 def setUp(self):
     super(TestWorkChainAbortChildren, self).setUp()
     self.assertIsNone(Process.current())
Beispiel #8
0
 def tearDown(self):
     super(TestWorkchain, self).tearDown()
     self.assertIsNone(Process.current())
Beispiel #9
0
 def setUp(self):
     super(TestWorkchain, self).setUp()
     self.assertIsNone(Process.current())
Beispiel #10
0
    def setUp(self):
        super().setUp()
        self.assertIsNone(Process.current())

        @workfunction
        def function_return_input(data):
            return data

        @calcfunction
        def function_return_true():
            return get_true_node()

        @workfunction
        def function_args(data_a):
            return data_a

        @workfunction
        def function_args_with_default(data_a=orm.Int(DEFAULT_INT)):
            return data_a

        @calcfunction
        def function_with_none_default(int_a, int_b, int_c=None):
            if int_c is not None:
                return orm.Int(int_a + int_b + int_c)
            return orm.Int(int_a + int_b)

        @workfunction
        def function_kwargs(**kwargs):
            return kwargs

        @workfunction
        def function_args_and_kwargs(data_a, **kwargs):
            result = {'data_a': data_a}
            result.update(kwargs)
            return result

        @workfunction
        def function_args_and_default(data_a, data_b=orm.Int(DEFAULT_INT)):
            return {'data_a': data_a, 'data_b': data_b}

        @workfunction
        def function_defaults(
            data_a=orm.Int(DEFAULT_INT), metadata={
                'label': DEFAULT_LABEL,
                'description': DEFAULT_DESCRIPTION
            }
        ):  # pylint: disable=unused-argument,dangerous-default-value,missing-docstring
            return data_a

        @workfunction
        def function_default_label():
            return

        @workfunction
        def function_exit_code(exit_status, exit_message):
            return ExitCode(exit_status.value, exit_message.value)

        @workfunction
        def function_excepts(exception):
            raise RuntimeError(exception.value)

        @workfunction
        def function_out_unstored():
            return orm.Int(DEFAULT_INT)

        self.function_return_input = function_return_input
        self.function_return_true = function_return_true
        self.function_args = function_args
        self.function_args_with_default = function_args_with_default
        self.function_with_none_default = function_with_none_default
        self.function_kwargs = function_kwargs
        self.function_args_and_kwargs = function_args_and_kwargs
        self.function_args_and_default = function_args_and_default
        self.function_defaults = function_defaults
        self.function_default_label = function_default_label
        self.function_exit_code = function_exit_code
        self.function_excepts = function_excepts
        self.function_out_unstored = function_out_unstored
Beispiel #11
0
 def tearDown(self):
     super(TestProcessNamespace, self).tearDown()
     self.assertIsNone(Process.current())
Beispiel #12
0
 def setUp(self):
     super(TestCalcJob, self).setUp()
     self.assertIsNone(Process.current())
 def setUp(self):
     super().setUp()
     self.assertIsNone(Process.current())
     self.spec = Process.spec()
     self.spec.inputs.valid_type = Data
     self.spec.outputs.valid_type = Data
    def setUp(self):
        super().setUp()
        self.assertIsNone(Process.current())
        self.default_int = Int(256)

        self.test_calcfunction = add_calcfunction
Beispiel #15
0
 def tearDown(self):
     super(TestLaunchers, self).tearDown()
     self.assertIsNone(Process.current())
Beispiel #16
0
 def setUp(self):
     super(TestLaunchers, self).setUp()
     self.assertIsNone(Process.current())
     self.a = orm.Int(1)
     self.b = orm.Int(2)
     self.result = 3
Beispiel #17
0
 def setUp(self):
     super(TestLaunchersDryRun, self).setUp()
     self.assertIsNone(Process.current())
Beispiel #18
0
 def tearDown(self):
     super(TestWorkChainAbortChildren, self).tearDown()
     self.assertIsNone(Process.current())
Beispiel #19
0
 def tearDown(self):
     super(TestCalcJob, self).tearDown()
     self.assertIsNone(Process.current())
Beispiel #20
0
 def setUp(self):
     super(TestProcessNamespace, self).setUp()
     self.assertIsNone(Process.current())
Beispiel #21
0
 def setUp(self):
     super().setUp()
     self.assertIsNone(Process.current())
     self.term_a = orm.Int(1)
     self.term_b = orm.Int(2)
     self.result = 3
Beispiel #22
0
 def tearDown(self):
     super(TestProcessFunction, self).tearDown()
     self.assertIsNone(Process.current())
Beispiel #23
0
 def test_spec_metadata_property(self):
     """`Process.spec_metadata` should return the metadata port namespace of its spec."""
     self.assertIsInstance(Process.spec_metadata, PortNamespace)
     self.assertEqual(Process.spec_metadata,
                      Process.spec().inputs['metadata'])
Beispiel #24
0
 def tearDown(self):
     super(TestProcessBuilder, self).tearDown()
     self.assertIsNone(Process.current())
 def setUp(self):
     super().setUp()
     self.assertIsNone(Process.current())
Beispiel #26
0
 def setUp(self):
     super(TestSerializeWorkChain, self).setUp()
     self.assertIsNone(Process.current())
 def tearDown(self):
     super().tearDown()
     self.assertIsNone(Process.current())
Beispiel #28
0
 def tearDown(self):
     super(TestSerializeWorkChain, self).tearDown()
     self.assertIsNone(Process.current())