Esempio n. 1
0
def get_computer(name=LOCALHOST_NAME, workdir=None):
    """Get AiiDA computer.
    Loads computer 'name' from the database, if exists.
    Sets up local computer 'name', if it isn't found in the DB.

    :param name: Name of computer to load or set up.
    :param workdir: path to work directory
        Used only when creating a new computer.
    :return: The computer node
    :rtype: :py:class:`aiida.orm.Computer`
    """
    from aiida.orm import Computer
    from aiida.common.exceptions import NotExistent

    try:
        computer = Computer.objects.get(label=name)
    except NotExistent:
        if workdir is None:
            workdir = tempfile.mkdtemp()

        computer = Computer(
            label=name,
            description='localhost computer set up by aiida_diff tests',
            hostname=name,
            workdir=workdir,
            transport_type='local',
            scheduler_type='direct')
        computer.store()
        computer.set_minimum_job_poll_interval(0.)
        computer.configure()

    return computer
Esempio n. 2
0
def get_or_create_local_computer(work_directory, name="localhost"):
    """Retrieve or setup a local computer.

    Parameters
    ----------
    work_directory : str
        path to a local directory for running computations in
    name : str
        name of the computer

    Returns
    -------
    aiida.orm.computers.Computer

    """
    from aiida.common import NotExistent
    from aiida.orm import Computer

    try:
        computer = Computer.objects.get(label=name)
    except NotExistent:
        computer = Computer(
            label=name,
            hostname="localhost",
            description="localhost computer, set up by aiida_crystal17 tests",
            transport_type="local",
            scheduler_type="direct",
            workdir=os.path.abspath(work_directory),
        )
        computer.store()
        computer.set_minimum_job_poll_interval(0.0)
        computer.configure()

    return computer
Esempio n. 3
0
def aiida_localhost(temp_dir):  # pylint: disable=redefined-outer-name
    """Get an AiiDA computer for localhost.

    Usage::

      def test_1(aiida_localhost):
          name = aiida_localhost.get_name()
          # proceed to set up code or use 'aiida_local_code_factory' instead


    :return: The computer node
    :rtype: :py:class:`aiida.orm.Computer`
    """
    from aiida.orm import Computer
    from aiida.common.exceptions import NotExistent

    name = 'localhost-test'

    try:
        computer = Computer.objects.get(name=name)
    except NotExistent:
        computer = Computer(
            name=name,
            description='localhost computer set up by test manager',
            hostname=name,
            workdir=temp_dir,
            transport_type='local',
            scheduler_type='direct')
        computer.store()
        computer.set_minimum_job_poll_interval(0.)
        computer.configure()

    return computer
Esempio n. 4
0
def test_validate_transfer_inputs(aiida_localhost, tmp_path, temp_dir):
    """Test the `TransferCalculation` validators."""
    from aiida.orm import Computer
    from aiida.calculations.transfer import check_node_type, validate_transfer_inputs

    fake_localhost = Computer(
        label='localhost-fake',
        description='extra localhost computer set up by test',
        hostname='localhost-fake',
        workdir=temp_dir,
        transport_type='local',
        scheduler_type='direct'
    )
    fake_localhost.store()
    fake_localhost.set_minimum_job_poll_interval(0.)
    fake_localhost.configure()

    inputs = {
        'source_nodes': {
            'unused_node': orm.RemoteData(computer=aiida_localhost, remote_path=str(tmp_path)),
        },
        'instructions':
        orm.Dict(
            dict={
                'local_files': [('inexistent_node', None, None)],
                'remote_files': [('inexistent_node', None, None)],
                'symlink_files': [('inexistent_node', None, None)],
            }
        ),
        'metadata': {
            'computer': fake_localhost
        },
    }
    expected_list = []
    expected_list.append((
        f' > remote node `unused_node` points to computer `{aiida_localhost}`, '
        f'not the one being used (`{fake_localhost}`)'
    ))
    expected_list.append(check_node_type('local_files', 'inexistent_node', None, orm.FolderData))
    expected_list.append(check_node_type('remote_files', 'inexistent_node', None, orm.RemoteData))
    expected_list.append(check_node_type('symlink_files', 'inexistent_node', None, orm.RemoteData))
    expected_list.append(' > node `unused_node` provided as inputs is not being used')

    expected = '\n\n'
    for addition in expected_list:
        expected = expected + addition + '\n'

    result = validate_transfer_inputs(inputs, None)
    assert result == expected

    result = check_node_type('list_name', 'node_label', None, orm.RemoteData)
    expected = ' > node `node_label` requested on list `list_name` not found among inputs'
    assert result == expected

    result = check_node_type('list_name', 'node_label', orm.FolderData(), orm.RemoteData)
    expected_type = orm.RemoteData.class_node_type
    expected = f' > node `node_label`, requested on list `list_name` should be of type `{expected_type}`'
    assert result == expected