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
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
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
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
def get_computer(name=TEST_COMPUTER): """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.objects.get(name=name) except NotExistent: computer = Computer( name=name, description='localhost computer set up by aiida_qeq tests', hostname=TEST_COMPUTER, workdir=tempfile.mkdtemp(), transport_type='local', scheduler_type='direct') computer.store() computer.configure() return computer
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
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
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
def computer(tmpdir): """ Setup a new computer object. """ from aiida.orm import Computer, User computer = Computer(name='local_computer', hostname='localhost') computer.set_scheduler_type('direct') computer.set_transport_type('local') computer.set_workdir(str(tmpdir)) computer.set_default_mpiprocs_per_machine(1) computer.set_mpirun_command(['mpirun', '-np', '{tot_num_mpiprocs}']) computer.store() computer.configure(user=User.objects.get_default()) yield computer
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
def get_computer(name): """Set up localhost computer""" try: computer = Computer.objects.get(label=name) except NotExistent: computer = Computer( label=name, description='localhost computer set up by aiida_zeopp tests', hostname=name, workdir=tempfile.mkdtemp(), transport_type='local', scheduler_type='direct', ) computer.store() computer.configure() return computer