예제 #1
0
def retriever():
    configure_logging(daemon=True, daemon_log_file=DAEMON_LOG_FILE)
    from aiida.daemon.execmanager import retrieve_jobs
    LOGGER.info('Checking for calculations to retrieve')
    set_daemon_timestamp(task_name='retriever', when='start')
    retrieve_jobs()
    set_daemon_timestamp(task_name='retriever', when='stop')
예제 #2
0
def manual_tick_all():
    from aiida.daemon.execmanager import submit_jobs, update_jobs, retrieve_jobs
    from aiida.work.daemon import tick_workflow_engine
    from aiida.daemon.workflowmanager import execute_steps
    submit_jobs()
    update_jobs()
    retrieve_jobs()
    execute_steps()  # legacy workflows
    tick_workflow_engine()
예제 #3
0
def retriever():
    from aiida.daemon.execmanager import retrieve_jobs
    print "aiida.daemon.tasks.retrieve:  Checking for calculations to retrieve"
    set_daemon_timestamp(task_name='retriever', when='start')
    retrieve_jobs()
    set_daemon_timestamp(task_name='retriever', when='stop')
예제 #4
0
    def run_tests_on_calcs_with_prefixes(self, prefixes):
        """
        Test immigration, retrieval, and parsing of calcs for all prefixes.

        Prefixes should be a group of prefixes that refer to calculations whose
        Aiida-generated input files should be identical.

        :param prefixes: A group of prefixes that refer to calculations whose
            Aiida-generated input files should be identical.
        :type prefixes: list of str
        """

        # Get the computer's transport and create instance.
        Transport = self.computer.get_transport_class()
        transport = Transport()

        # Initialize arrays for storing data for each job.
        inpt_txts = []

        # Open the transport for the duration of immigrations, so it's not
        # reopened for each one. This would really matter for ssh tranports.
        with transport as t:
            # Loop over all manual prefixes.
            for prefix in prefixes:

                # Define the calc's initialization parameters. These result in
                # calling of the `set_` methods with the specified values.
                init_params = {
                    'computer': self.computer,
                    'resources': {
                        'num_machines': 1,
                        'num_mpiprocs_per_machine': 1
                    },
                    'remote_workdir': TEST_JOB_DIR,
                    'input_file_name': prefix + '.in',
                    'output_file_name': prefix + '.out'
                }
                # Initialize the calculation using the `set_` methods.
                calc = PwimmigrantCalculation(**init_params)
                # Set the code.
                calc.use_code(self.code)

                # Create the input nodes.
                try:
                    calc.create_input_nodes(t)  # Open transport passed.
                except Exception as error:
                    self.fail(
                        "Error creating input nodes for prefix '{}':\n{}\n\n"
                        "".format(prefix, error))

                # Submit a test submission in a temporary directory and store
                # the input file's contents. Need to do this before now,
                # because calc's state is NEW.
                with SandboxFolder() as folder:
                    # Submit test and get the subfolder containing the input
                    # file.
                    subfolder = calc.submit_test(folder, prefix)[0]
                    # Get the path of the input file.
                    inpt_path = os.path.join(subfolder.abspath, prefix + '.in')
                    # Open the input file, read and store it's contents.
                    with open(inpt_path) as f:
                        inpt_txts.append(f.read())

                # Prepare the calc for retrieval and parsing.
                calc.prepare_for_retrieval_and_parsing(transport)

        # Call the daemon's retrieval function, so all immigrated calcs get
        # retrieved and parsed.
        try:
            retrieve_jobs()
        except Exception as error:
            self.fail("Error during retrieval of immigrated calcs:\n{}\n\n"
                      "".format(error))

        # Test the create_input_nodes method by comparing the input files
        # generated above by the submit_test method. The first input file
        # will serve as the reference.
        ref_words = inpt_txts[0].split()
        for txt, prefix in zip(inpt_txts[1:], prefixes[1:]):
            # Loop over the words of the reference and current input files.
            for w1, w2 in zip(ref_words, txt.split()):

                # If the words are not the same, and the reference word is
                # not the calculation's prefix parameter...
                if w2 != w1 and w1.strip("'") not in prefixes:

                    # Try using the regex-based str2val function of
                    # pwinputparser to convert the word strings into python
                    # values.
                    try:
                        val1, val2 = [str2val(x) for x in (w1, w2)]
                    except Exception as error:
                        self.fail(
                            "The strings, '{}' and '{}', of the submit_test "
                            "input files for calcs with prefixes {} and {} "
                            "were not equal and could not be converted to "
                            "python values using the str2val function of "
                            "pwinputparser.\nThe exception thrown was:\n{"
                            "}\n\n".format(w1, w2, prefixes[0], prefix, error))

                    # If both values were converted to floats...
                    if all([type(v) is float for v in val1, val2]):
                        # Test if they differ by more than a specified
                        # tolerance.
                        self.assertAlmostEqual(
                            val1,
                            val2,
                            4,
                            msg="The values, {} and {}, of the submit_test "
                            "input files for calcs with prefixes {} and {} "
                            "are not within the specified number of "
                            "decimal places."
                            "".format(val1, val2, prefixes[0], prefix))

                    # If they weren't floats, then they should have been
                    # identical, so the test fails.
                    else:
                        self.assertEqual(
                            val1,
                            val2,
                            msg="The values, {} and {}, of the submit_test "
                            "input files for calcs with prefixes {} and {} "
                            "did not match. They should have been "
                            "identical!".format(val1, val2, prefixes[0],
                                                prefix))