Exemplo n.º 1
0
    def test_get_proc_outputs(self):
        c = WorkCalculation()
        a = Int(5)
        b = Int(10)
        a.add_link_from(c, u'a', link_type=LinkType.CREATE)
        b.add_link_from(c, u'b', link_type=LinkType.CREATE)
        c.store()
        for n in [a, b, c]:
            n.store()

        from aiida.work.interstep import _get_proc_outputs_from_registry
        outputs = _get_proc_outputs_from_registry(c.pk)
        self.assertListEqual(outputs.keys(), [u'a', u'b'])
        self.assertEquals(outputs['a'], a)
        self.assertEquals(outputs['b'], b)
Exemplo n.º 2
0
 def test_cycle(self):
     """
     Creating a cycle: A data-instance is both input to and returned by a WorkFlowNode
     """
     d = Data().store()
     c = WorkCalculation().store()
     # New provenance design branch
     # ~ c.add_incoming(d, link_type=LinkType.INPUT_WORK, link_label='lala')
     # ~ d.add_incoming(c, link_type=LinkType.RETURN, link_label='lala')
     c.add_link_from(d, link_type=LinkType.INPUT, label='lala')
     d.add_link_from(c, link_type=LinkType.RETURN, label='lala')
     qb = QueryBuilder().append(Node).append(Node)
     rule = UpdateRule(qb, max_iterations=np.inf)
     es = get_basket(node_ids=(d.id,))
     res = rule.run(es)
     self.assertEqual( res['nodes']._set, set([d.id, c.id]))
Exemplo n.º 3
0
 def create_db_record(cls):
     """
     Create a database calculation node that represents what happened in
     this process.
     :return:
     """
     from aiida.orm.calculation.work import WorkCalculation
     calc = WorkCalculation()
     return calc
Exemplo n.º 4
0
    def test_report(self):
        """Test the report command."""
        grandparent = WorkCalculation().store()
        parent = WorkCalculation().store()
        child = WorkCalculation().store()

        parent.add_link_from(grandparent, link_type=LinkType.CALL)
        child.add_link_from(parent, link_type=LinkType.CALL)

        grandparent.logger.log(LOG_LEVEL_REPORT, 'grandparent_message')
        parent.logger.log(LOG_LEVEL_REPORT, 'parent_message')
        child.logger.log(LOG_LEVEL_REPORT, 'child_message')

        result = self.cli_runner.invoke(cmd_work.work_report,
                                        [str(grandparent.pk)])
        self.assertIsNone(result.exception)
        self.assertEquals(len(get_result_lines(result)), 3)

        result = self.cli_runner.invoke(cmd_work.work_report, [str(parent.pk)])
        self.assertIsNone(result.exception)
        self.assertEquals(len(get_result_lines(result)), 2)

        result = self.cli_runner.invoke(cmd_work.work_report, [str(child.pk)])
        self.assertIsNone(result.exception)
        self.assertEquals(len(get_result_lines(result)), 1)

        # Max depth should limit nesting level
        for flag in ['-m', '--max-depth']:
            for flag_value in [1, 2]:
                result = self.cli_runner.invoke(
                    cmd_work.work_report,
                    [str(grandparent.pk), flag,
                     str(flag_value)])
                self.assertIsNone(result.exception)
                self.assertEquals(len(get_result_lines(result)), flag_value)

        # Filtering for other level name such as WARNING should not have any hits and only print the no log message
        for flag in ['-l', '--levelname']:
            result = self.cli_runner.invoke(
                cmd_work.work_report, [str(grandparent.pk), flag, 'WARNING'])
            self.assertIsNone(result.exception)
            self.assertEquals(len(get_result_lines(result)), 1)
            self.assertEquals(
                get_result_lines(result)[0],
                'No log messages recorded for this work calculation')
Exemplo n.º 5
0
    def test_work_show(self):
        """Test verdi work show"""
        workchain_one = WorkCalculation().store()
        workchain_two = WorkCalculation().store()
        workchains = [workchain_one, workchain_two]

        # Running without identifiers should not except and not print anything
        options = []
        result = self.cli_runner.invoke(cmd_work.work_show, options)
        self.assertIsNone(result.exception)
        self.assertEquals(len(get_result_lines(result)), 0)

        # Giving a single identifier should print a non empty string message
        options = [str(workchain_one.pk)]
        result = self.cli_runner.invoke(cmd_work.work_show, options)
        self.assertIsNone(result.exception)
        self.assertTrue(len(get_result_lines(result)) > 0)

        # Giving multiple identifiers should print a non empty string message
        options = [str(workchain.pk) for workchain in workchains]
        result = self.cli_runner.invoke(cmd_work.work_show, options)
        self.assertIsNone(result.exception)
        self.assertTrue(len(get_result_lines(result)) > 0)
Exemplo n.º 6
0
    def test_list(self):
        """Test the list command."""
        from aiida.work.processes import ProcessState

        # Number of output lines in -r/--raw format should be zero when there are no calculations yet
        result = self.cli_runner.invoke(cmd_work.work_list, ['-r'])
        self.assertIsNone(result.exception)
        self.assertEquals(len(get_result_lines(result)), 0)

        calcs = []

        # Create 6 FunctionCalculations and WorkCalculations (one for each ProcessState)
        for state in ProcessState:

            calc = FunctionCalculation()
            calc._set_process_state(state)

            # Set the FunctionCalculation as successful
            if state == ProcessState.FINISHED:
                calc._set_exit_status(0)

            calc.store()
            calcs.append(calc)

            calc = WorkCalculation()
            calc._set_process_state(state)

            # Set the WorkCalculation as failed
            if state == ProcessState.FINISHED:
                calc._set_exit_status(1)

            calc.store()
            calcs.append(calc)

        # Default behavior should yield all active states (CREATED, RUNNING and WAITING) so six in total
        result = self.cli_runner.invoke(cmd_work.work_list, ['-r'])
        self.assertIsNone(result.exception)
        self.assertEquals(len(get_result_lines(result)), 6)

        # Adding the all option should return all entries regardless of process state
        for flag in ['-a', '--all']:
            result = self.cli_runner.invoke(cmd_work.work_list, ['-r', flag])
            self.assertIsNone(result.exception)
            self.assertEquals(len(get_result_lines(result)), 12)

        # Passing the limit option should limit the results
        for flag in ['-l', '--limit']:
            result = self.cli_runner.invoke(cmd_work.work_list,
                                            ['-r', flag, '6'])
            self.assertIsNone(result.exception)
            self.assertEquals(len(get_result_lines(result)), 6)

        # Filtering for a specific process state
        for flag in ['-S', '--process-state']:
            for flag_value in [
                    'created', 'running', 'waiting', 'killed', 'excepted',
                    'finished'
            ]:
                result = self.cli_runner.invoke(cmd_work.work_list,
                                                ['-r', flag, flag_value])
                self.assertIsNone(result.exception)
                self.assertEquals(len(get_result_lines(result)), 2)

        # Filtering for exit status should only get us one
        for flag in ['-E', '--exit-status']:
            for exit_status in ['0', '1']:
                result = self.cli_runner.invoke(cmd_work.work_list,
                                                ['-r', flag, exit_status])
                self.assertIsNone(result.exception)
                self.assertEquals(len(get_result_lines(result)), 1)

        # Passing the failed flag as a shortcut for FINISHED + non-zero exit status
        for flag in ['-X', '--failed']:
            result = self.cli_runner.invoke(cmd_work.work_list, ['-r', flag])
            self.assertIsNone(result.exception)
            self.assertEquals(len(get_result_lines(result)), 1)

        # Projecting on pk should allow us to verify all the pks
        for flag in ['-P', '--project']:
            result = self.cli_runner.invoke(cmd_work.work_list,
                                            ['-r', flag, 'pk'])
            self.assertIsNone(result.exception)
            self.assertEquals(len(get_result_lines(result)), 6)

            for line in get_result_lines(result):
                self.assertIn(line.strip(), [str(calc.pk) for calc in calcs])