コード例 #1
0
def get_computer(name='localhost'):
    """Get local computer.

    Sets up local computer with 'name' or reads it from database,
    if it exists.
    
    :param name: Name of local 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.get(name)
    except NotExistent:

        computer = Computer(
            name=name,
            description='localhost computer set up by aiida_gudhi tests',
            hostname='localhost',
            workdir=tempfile.mkdtemp(),
            transport_type='local',
            scheduler_type='direct',
            enabled_state=True)
        computer.store()

    return computer
コード例 #2
0
ファイル: computer.py プロジェクト: chrisjsewell/aiida_core
    def test_get_transport(self):
        """
        Test the get_transport method of Computer
        """
        import tempfile
        from aiida.orm import Computer
        from aiida.orm.backend import construct_backend

        new_comp = Computer(name='bbb',
                            hostname='localhost',
                            transport_type='local',
                            scheduler_type='direct',
                            workdir='/tmp/aiida')
        new_comp.store()

        # Configure the computer - no parameters for local transport
        authinfo = self.backend.authinfos.create(
            computer=new_comp, user=self.backend.users.get_automatic_user())
        authinfo.store()

        transport = new_comp.get_transport()

        # It's on localhost, so I see files that I create
        with transport:
            with tempfile.NamedTemporaryFile() as f:
                self.assertEquals(transport.isfile(f.name), True)
            # Here the file should have been deleted
            self.assertEquals(transport.isfile(f.name), False)
コード例 #3
0
 def setUpClass(cls, *args, **kwargs):
     super(TestVerdiCodeSetup, cls).setUpClass(*args, **kwargs)
     from aiida.orm import Computer
     new_comp = Computer(name='comp',
                         hostname='localhost',
                         transport_type='local',
                         scheduler_type='direct',
                         workdir='/tmp/aiida')
     new_comp.store()
コード例 #4
0
ファイル: test_data.py プロジェクト: chrisjsewell/aiida_core
 def setUpClass(cls):
     super(TestVerdiDataTrajectory, cls).setUpClass()
     new_comp = Computer(name='comp',
                         hostname='localhost',
                         transport_type='local',
                         scheduler_type='direct',
                         workdir='/tmp/aiida')
     new_comp.store()
     cls.ids = cls.create_trajectory_data()
コード例 #5
0
ファイル: test_data.py プロジェクト: chrisjsewell/aiida_core
 def setUpClass(cls):
     super(TestVerdiDataStructure, cls).setUpClass()
     from aiida.orm import Computer
     new_comp = Computer(name='comp',
                         hostname='localhost',
                         transport_type='local',
                         scheduler_type='direct',
                         workdir='/tmp/aiida')
     new_comp.store()
     cls.ids = cls.create_structure_data()
コード例 #6
0
def fixture_computer_localhost(fixture_work_directory):
    """Return a `Computer` instance mocking a localhost setup."""
    from aiida.orm import Computer
    computer = Computer(name='localhost',
                        hostname='localhost',
                        transport_type='local',
                        scheduler_type='direct',
                        workdir=fixture_work_directory).store()
    computer.set_default_mpiprocs_per_machine(1)
    yield computer
コード例 #7
0
ファイル: test_data.py プロジェクト: chrisjsewell/aiida_core
 def setUpClass(cls):
     super(TestVerdiDataRemote, cls).setUpClass()
     new_comp = Computer(name='comp',
                         hostname='localhost',
                         transport_type='local',
                         scheduler_type='direct',
                         workdir=tempfile.mkdtemp())
     new_comp.store()
     b = construct_backend()
     aiidauser = b.users.get_automatic_user()
     authinfo = DbAuthInfo(dbcomputer=new_comp.dbcomputer,
                           aiidauser=aiidauser.dbuser)
     authinfo.save()
コード例 #8
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
コード例 #9
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
コード例 #10
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
コード例 #11
0
ファイル: __init__.py プロジェクト: greschd/aiida-alloy
def get_computer(name=TEST_COMPUTER, 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(name=name)
    except NotExistent:
        if workdir is None:
            workdir = tempfile.mkdtemp()

        computer = Computer(
            name=name,
            description='localhost computer set up by aiida_alloy tests',
            hostname=name,
            workdir=workdir,
            transport_type='local',
            scheduler_type='direct')
        computer.store()
        computer.set_default_mpiprocs_per_machine(1)
        computer.configure()

    return computer
コード例 #12
0
 def get_computer(temp_dir):
     """
     Create and store a new computer, and return it
     """
     from aiida.orm import Computer
     computer = Computer(name='localhost',
                         description='my computer',
                         hostname='localhost',
                         workdir=temp_dir,
                         transport_type='local',
                         scheduler_type='direct',
                         enabled_state=True)
     computer.store()
     return computer
コード例 #13
0
def prepare_computer(computername, workdir):
    """Create new computer in db or read computer from db if it already exists."""
    from aiida.orm import Computer
    from aiida.orm.querybuilder import QueryBuilder

    # first check if computer exists already in database
    qb = QueryBuilder()
    qb.append(Computer, tag='computer')
    all_computers = qb.dict()
    computer_found_in_db = False
    if len(all_computers) > 0:
        for icomp in range(len(all_computers)):
            c = all_computers[icomp].get('computer').get('*')
            if c.get_name() == computername:
                computer_found_in_db = True
                comp = c
    # if it is not there create a new one
    if not computer_found_in_db:
        #comp = Computer(computername, 'test computer', transport_type='local', scheduler_type='direct', workdir=workdir)
        comp = Computer(computername,
                        'test computer',
                        transport_type='local',
                        scheduler_type='direct',
                        workdir=workdir)
        comp.set_default_mpiprocs_per_machine(4)
        comp.store()
        print('computer stored now cofigure')
        comp.configure()
    else:
        print('found computer in database')
    # return computer
    return comp
コード例 #14
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
コード例 #15
0
    def setUp(self):
        from aiida.orm import Computer
        self.comp = Computer.get('comp')

        self.runner = CliRunner()
        self.this_folder = os.path.dirname(__file__)
        self.this_file = os.path.basename(__file__)
コード例 #16
0
ファイル: test_data.py プロジェクト: chrisjsewell/aiida_core
    def setUp(self):
        self.comp = Computer.get('comp')
        self.runner = CliRunner()
        self.this_folder = os.path.dirname(__file__)
        self.this_file = os.path.basename(__file__)

        self.cli_runner = CliRunner()
コード例 #17
0
ファイル: test_generic.py プロジェクト: CasperWA/aiida_core
    def test_deletion(self):
        """Test computer deletion."""
        from aiida.orm import CalcJobNode, Computer
        from aiida.common.exceptions import InvalidOperation

        newcomputer = Computer(name='testdeletioncomputer',
                               hostname='localhost',
                               transport_type='local',
                               scheduler_type='pbspro',
                               workdir='/tmp/aiida').store()

        # This should be possible, because nothing is using this computer
        orm.Computer.objects.delete(newcomputer.id)

        calc = CalcJobNode(computer=self.computer)
        calc.set_option('resources', {
            'num_machines': 1,
            'num_mpiprocs_per_machine': 1
        })
        calc.store()

        # This should fail, because there is at least a calculation
        # using this computer (the one created just above)
        with self.assertRaises(InvalidOperation):
            orm.Computer.objects.delete(self.computer.id)  # pylint: disable=no-member
コード例 #18
0
def set_deneb_defaults(options_template):
    from aiida.orm import Computer

    options_template.max_wallclock_seconds = DEFAULT_OPTIONS[
        'max_wallclock_seconds']
    options_template.resources = DEFAULT_OPTIONS['resources']
    options_template.queue_name = DEFAULT_OPTIONS['queue_name']
    options_template.computer = Computer.get(DEFAULT_OPTIONS['computer'])
コード例 #19
0
    def test_mixed(self):
        from aiida.orm import Computer
        os.environ['VISUAL'] = 'sleep 1; vim -cwq'
        os.environ['EDITOR'] = 'sleep 1; vim -cwq'
        label = 'mixed_computer'

        options_dict = generate_setup_options_dict(
            replace_args={'label': label})
        options_dict_full = options_dict.copy()

        options_dict.pop('non-interactive', 'None')

        non_interactive_options_dict = {}
        non_interactive_options_dict['enabled'] = None

        non_interactive_options_dict['prepend-text'] = options_dict.pop(
            'prepend-text')
        non_interactive_options_dict['append-text'] = options_dict.pop(
            'append-text')
        non_interactive_options_dict['shebang'] = options_dict.pop('shebang')
        non_interactive_options_dict['scheduler'] = options_dict.pop(
            'scheduler')

        # In any case, these would be managed by the visual editor
        user_input = "\n".join(
            generate_setup_options_interactive(options_dict))
        options = generate_setup_options(non_interactive_options_dict)

        result = self.runner.invoke(setup_computer, options, input=user_input)
        self.assertIsNone(
            result.exception,
            msg="There was an unexpected exception. Output: {}".format(
                result.output))

        new_computer = Computer.get(label)
        self.assertIsInstance(new_computer, Computer)

        self.assertEqual(new_computer.description,
                         options_dict_full['description'])
        self.assertEqual(new_computer.hostname, options_dict_full['hostname'])
        self.assertEqual(new_computer.get_transport_type(),
                         options_dict_full['transport'])
        self.assertEqual(new_computer.get_scheduler_type(),
                         options_dict_full['scheduler'])
        self.assertTrue(new_computer.is_enabled())
        self.assertEqual(new_computer.get_mpirun_command(),
                         options_dict_full['mpirun-command'].split())
        self.assertEqual(new_computer.get_shebang(),
                         options_dict_full['shebang'])
        self.assertEqual(new_computer.get_workdir(),
                         options_dict_full['work-dir'])
        self.assertEqual(new_computer.get_default_mpiprocs_per_machine(),
                         int(options_dict_full['mpiprocs-per-machine']))
        # For now I'm not writing anything in them
        self.assertEqual(new_computer.get_prepend_text(),
                         options_dict_full['prepend-text'])
        self.assertEqual(new_computer.get_append_text(),
                         options_dict_full['append-text'])
コード例 #20
0
ファイル: conftest.py プロジェクト: zhubonan/aiida-castep
    def create_computer(self, **kwargs):
        """
        Return a generator for the Computers
        """
        defaults = dict(label='localhost',
                        hostname='localhost',
                        transport_type='core.local'
                        if AIIDA_MAJOR_VERSION > 1 else 'local',
                        scheduler_type='core.direct'
                        if AIIDA_MAJOR_VERSION > 1 else 'direct',
                        workdir=str(self._workdir))

        kwargs.update(defaults)
        computer = Computer(**kwargs).store()
        # Need to configure the computer before using
        # Otherwise there is no AuthInfo
        computer.configure()
        return computer
コード例 #21
0
 def test_data_loaded(self):
     """
     Check that the data is indeed in the DB when calling load_node
     """
     from aiida.orm import Computer
     from aiida.orm import load_node
     self.assertTrue(is_dbenv_loaded())
     self.assertEqual(load_node(self.data_pk).uuid, self.data.uuid)
     self.assertEqual(Computer.get('localhost').uuid, self.computer.uuid)
コード例 #22
0
ファイル: test_data.py プロジェクト: chrisjsewell/aiida_core
    def setUp(self):
        comp = Computer.get('comp')
        self.r = RemoteData()
        p = tempfile.mkdtemp()
        self.r.set_remote_path(p)
        with open(p + '/file.txt', 'w') as f:
            f.write("test string")
        self.r.set_computer(comp)
        self.r.store()

        self.cli_runner = CliRunner()
コード例 #23
0
ファイル: data.py プロジェクト: wangvei/aiida-vasp
def localhost(fresh_aiida_env, localhost_dir):
    """Fixture for a local computer called localhost. This is currently not in the AiiDA fixtures."""
    try:
        computer = Computer.objects.get(name='localhost')
    except NotExistent:
        computer = Computer(name='localhost',
                            hostname='localhost',
                            transport_type='local',
                            scheduler_type='direct',
                            workdir=localhost_dir.strpath).store()
    return computer
コード例 #24
0
    def setUpClass(cls):
        """
        Create some computers to test the ComputerParamType parameter type for the command line infrastructure
        We create an initial computer with a random name and then on purpose create two computers with a name
        that matches exactly the ID and UUID, respectively, of the first one. This allows us to test
        the rules implemented to solve ambiguities that arise when determing the identifier type
        """
        super(TestComputerParamType, cls).setUpClass()

        kwargs = {
            'hostname': 'localhost',
            'transport_type': 'local',
            'scheduler_type': 'direct',
            'workdir': '/tmp/aiida'
        }

        cls.param = ComputerParamType()
        cls.entity_01 = Computer(name='computer_01', **kwargs).store()
        cls.entity_02 = Computer(name=str(cls.entity_01.pk), **kwargs).store()
        cls.entity_03 = Computer(name=str(cls.entity_01.uuid),
                                 **kwargs).store()
コード例 #25
0
 def setUpClass(cls, *args, **kwargs):
     """Create a new computer> I create a new one because I want to configure it and I don't want to
     interfere with other tests"""
     super(TestVerdiComputerCommands, cls).setUpClass(*args, **kwargs)
     from aiida.orm import Computer
     cls.computer_name = "comp_cli_test_computer"
     cls.comp = Computer(name=cls.computer_name,
                         hostname='localhost',
                         transport_type='local',
                         scheduler_type='direct',
                         workdir='/tmp/aiida')
     cls.comp.store()
コード例 #26
0
def get_computer(name='localhost'):
    """Setup localhost computer"""
    from aiida.orm import Computer
    from aiida.common.exceptions import NotExistent

    try:
        computer = Computer.get(name)
    except NotExistent:

        import tempfile
        computer = Computer(
            name=name,
            description='localhost computer set up by aiida_gudhi tests',
            hostname='localhost',
            workdir=tempfile.mkdtemp(),
            transport_type='local',
            scheduler_type='direct',
            enabled_state=True)
        computer.store()

    return computer
コード例 #27
0
 def get_localhost(self):
     """Setup localhost computer"""
     from aiida.orm import Computer
     computer = Computer(
         name='localhost',
         description='my computer',
         hostname='localhost',
         workdir=tempfile.mkdtemp(),
         transport_type='local',
         scheduler_type='direct',
         enabled_state=True)
     return computer
コード例 #28
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

    """

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

    return computer
コード例 #29
0
def test_duplicate(cmd_test_env):
    """Test the duplicate command"""
    from aiida.orm import Computer, Code
    _ = cmd_test_env
    runner = CliRunner()

    runner.invoke(duplicate_fe, ["-Y", "localhost"], catch_exceptions=False)
    assert Computer.get(label='localhost-fw')
    assert Computer.get(
        label='localhost-fw').scheduler_type == "fireworks_scheduler.default"

    runner.invoke(duplicate_fe, ["-Y", "localhost", "--suffix", 'fe'],
                  catch_exceptions=False)
    assert Computer.get(label='localhost-fe')

    runner.invoke(duplicate_fe,
                  ["-Y", "localhost", "--suffix", 'fc', '--include-codes'],
                  catch_exceptions=False)
    assert Computer.get(label='localhost-fc')
    assert Code.get_from_string("bash@localhost-fc")

    runner.invoke(
        duplicate_fe,
        ["-Y", "localhost", "--job-should-keep-env", "--suffix", 'env'],
        catch_exceptions=False)
    assert Computer.get(label='localhost-env')
    assert Computer.get(
        label='localhost-env').scheduler_type == "fireworks_scheduler.keepenv"
コード例 #30
0
    def generate_calc(self):
        from aiida.orm import Code, Computer, CalculationFactory
        from aiida.common.datastructures import calc_states

        CustomCalc = CalculationFactory('simpleplugins.templatereplacer')

        computer = Computer.get("localhost")

        calc = CustomCalc(computer=computer, withmpi=True)
        calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
        calc.store()
        calc._set_state(calc_states.FINISHED)

        return calc
コード例 #31
0
def generate_calc():
    from aiida.orm import Code, Computer, CalculationFactory
    from aiida.common.datastructures import calc_states

    CustomCalc = CalculationFactory('simpleplugins.templatereplacer')

    computer = Computer.get("localhost")

    calc = CustomCalc(computer=computer, withmpi=True)
    calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
    calc.store()
    calc._set_state(calc_states.FINISHED)

    return calc