Esempio n. 1
0
 def logger(self):
     """Return the internal logger."""
     try:
         return self._logger
     except AttributeError:
         raise exceptions.InternalError(
             'No self._logger configured for {}!')
Esempio n. 2
0
 def get_user_email(self):
     """A string with the email of the User."""
     try:
         return self.user_email
     except AttributeError:
         raise exceptions.InternalError(
             'The AiiDA Test implementation should define a self.user_email in the setUpClass_method'
         )
Esempio n. 3
0
 def get_computer(self):
     """An ORM Computer object present in the DB."""
     try:
         return self.computer
     except AttributeError:
         raise exceptions.InternalError(
             'The AiiDA Test implementation should define a self.computer in the setUpClass_method'
         )
Esempio n. 4
0
    def get_submit_script(self, job_tmpl):
        """Return the submit script as a string.

        :parameter job_tmpl: a `aiida.schedulers.datastrutures.JobTemplate` instance.

        The plugin returns something like

        #!/bin/bash <- this shebang line is configurable to some extent
        scheduler_dependent stuff to choose numnodes, numcores, walltime, ...
        prepend_computer [also from calcinfo, joined with the following?]
        prepend_code [from calcinfo]
        output of _get_script_main_content
        postpend_code
        postpend_computer
        """
        if not isinstance(job_tmpl, JobTemplate):
            raise exceptions.InternalError(
                'job_tmpl should be of type JobTemplate')

        empty_line = ''

        # I fill the list with the lines, and finally join them and return
        script_lines = []

        if job_tmpl.shebang:
            script_lines.append(job_tmpl.shebang)
        elif job_tmpl.shebang == '':
            # Here I check whether the shebang was set explicitly as an empty line.
            # In such a case, the first line is empty, if that's what the user wants:
            script_lines.append(job_tmpl.shebang)
        elif job_tmpl.shebang is None:
            script_lines.append('#!/bin/bash')
        else:
            raise ValueError('Invalid shebang set: {}'.format(
                job_tmpl.shebang))
        script_lines.append(self._get_submit_script_header(job_tmpl))
        script_lines.append(empty_line)

        if job_tmpl.prepend_text:
            script_lines.append(job_tmpl.prepend_text)
            script_lines.append(empty_line)

        script_lines.append(
            self._get_run_line(job_tmpl.codes_info, job_tmpl.codes_run_mode))
        script_lines.append(empty_line)

        if job_tmpl.append_text:
            script_lines.append(job_tmpl.append_text)
            script_lines.append(empty_line)

        footer = self._get_submit_script_footer(job_tmpl)  # pylint: disable=assignment-from-none
        if footer:
            script_lines.append(footer)
            script_lines.append(empty_line)

        return '\n'.join(script_lines)
Esempio n. 5
0
def validate_traversal_rules(ruleset=GraphTraversalRules.DEFAULT, **kwargs):
    """
    Validates the keywords with a ruleset template and returns a parsed dictionary
    ready to be used.

    :type ruleset: :py:class:`aiida.common.links.GraphTraversalRules`
    :param ruleset: Ruleset template used to validate the set of rules.
    :param bool input_calc_forward: will traverse INPUT_CALC links in the forward direction.
    :param bool input_calc_backward: will traverse INPUT_CALC links in the backward direction.
    :param bool create_forward: will traverse CREATE links in the forward direction.
    :param bool create_backward: will traverse CREATE links in the backward direction.
    :param bool return_forward: will traverse RETURN links in the forward direction.
    :param bool return_backward: will traverse RETURN links in the backward direction.
    :param bool input_work_forward: will traverse INPUT_WORK links in the forward direction.
    :param bool input_work_backward: will traverse INPUT_WORK links in the backward direction.
    :param bool call_calc_forward: will traverse CALL_CALC links in the forward direction.
    :param bool call_calc_backward: will traverse CALL_CALC links in the backward direction.
    :param bool call_work_forward: will traverse CALL_WORK links in the forward direction.
    :param bool call_work_backward: will traverse CALL_WORK links in the backward direction.
    """
    from aiida.common import exceptions

    if not isinstance(ruleset, GraphTraversalRules):
        raise TypeError(
            'ruleset input must be of type aiida.common.links.GraphTraversalRules\ninstead, it is: {}'.format(
                type(ruleset)
            )
        )

    rules_applied = {}
    links_forward = []
    links_backward = []

    for name, rule in ruleset.value.items():

        follow = rule.default

        if name in kwargs:

            if not rule.toggleable:
                raise ValueError('input rule {} is not toggleable for ruleset {}'.format(name, ruleset))

            follow = kwargs.pop(name)

            if not isinstance(follow, bool):
                raise ValueError('the value of rule {} must be boolean, but it is: {}'.format(name, follow))

        if follow:

            if rule.direction == 'forward':
                links_forward.append(rule.link_type)
            elif rule.direction == 'backward':
                links_backward.append(rule.link_type)
            else:
                raise exceptions.InternalError(
                    'unrecognized direction `{}` for graph traversal rule'.format(rule.direction)
                )

        rules_applied[name] = follow

    if kwargs:
        error_message = 'unrecognized keywords: {}'.format(', '.join(kwargs.keys()))
        raise exceptions.ValidationError(error_message)

    valid_output = {
        'rules_applied': rules_applied,
        'forward': links_forward,
        'backward': links_backward,
    }

    return valid_output
Esempio n. 6
0
def validate_traversal_rules(
        ruleset: GraphTraversalRules = GraphTraversalRules.DEFAULT,
        **traversal_rules: bool) -> dict:
    """
    Validates the keywords with a ruleset template and returns a parsed dictionary
    ready to be used.

    :param ruleset: Ruleset template used to validate the set of rules.
    :param input_calc_forward: will traverse INPUT_CALC links in the forward direction.
    :param input_calc_backward: will traverse INPUT_CALC links in the backward direction.
    :param create_forward: will traverse CREATE links in the forward direction.
    :param create_backward: will traverse CREATE links in the backward direction.
    :param return_forward: will traverse RETURN links in the forward direction.
    :param return_backward: will traverse RETURN links in the backward direction.
    :param input_work_forward: will traverse INPUT_WORK links in the forward direction.
    :param input_work_backward: will traverse INPUT_WORK links in the backward direction.
    :param call_calc_forward: will traverse CALL_CALC links in the forward direction.
    :param call_calc_backward: will traverse CALL_CALC links in the backward direction.
    :param call_work_forward: will traverse CALL_WORK links in the forward direction.
    :param call_work_backward: will traverse CALL_WORK links in the backward direction.
    """
    if not isinstance(ruleset, GraphTraversalRules):
        raise TypeError(
            f'ruleset input must be of type aiida.common.links.GraphTraversalRules\ninstead, it is: {type(ruleset)}'
        )

    rules_applied: Dict[str, bool] = {}
    links_forward: List[LinkType] = []
    links_backward: List[LinkType] = []

    for name, rule in ruleset.value.items():

        follow = rule.default

        if name in traversal_rules:

            if not rule.toggleable:
                raise ValueError(
                    f'input rule {name} is not toggleable for ruleset {ruleset}'
                )

            follow = traversal_rules.pop(name)

            if not isinstance(follow, bool):
                raise ValueError(
                    f'the value of rule {name} must be boolean, but it is: {follow}'
                )

        if follow:

            if rule.direction == 'forward':
                links_forward.append(rule.link_type)
            elif rule.direction == 'backward':
                links_backward.append(rule.link_type)
            else:
                raise exceptions.InternalError(
                    f'unrecognized direction `{rule.direction}` for graph traversal rule'
                )

        rules_applied[name] = follow

    if traversal_rules:
        error_message = f"unrecognized keywords: {', '.join(traversal_rules.keys())}"
        raise exceptions.ValidationError(error_message)

    valid_output = {
        'rules_applied': rules_applied,
        'forward': links_forward,
        'backward': links_backward,
    }

    return valid_output