def test_remote(self): import tempfile from aiida.orm.code import Code from aiida.orm.computer import Computer from aiida.common.exceptions import ValidationError with self.assertRaises(ValueError): # remote_computer_exec has length 2 but is not a list or tuple _ = Code(remote_computer_exec='ab') # invalid code path with self.assertRaises(ValueError): _ = Code(remote_computer_exec=(self.computer, '')) # Relative path is invalid for remote code with self.assertRaises(ValueError): _ = Code(remote_computer_exec=(self.computer, 'subdir/run.exe')) # first argument should be a computer, not a string with self.assertRaises(TypeError): _ = Code(remote_computer_exec=('localhost', '/bin/ls')) code = Code(remote_computer_exec=(self.computer, '/bin/ls')) with tempfile.NamedTemporaryFile() as f: f.write("#/bin/bash\n\necho test run\n") f.flush() code.add_path(f.name, 'test.sh') with self.assertRaises(ValidationError): # There are files inside code.store() # If there are no files, I can store code.remove_path('test.sh') code.store() self.assertEquals(code.get_remote_computer().pk, self.computer.pk) self.assertEquals(code.get_remote_exec_path(), '/bin/ls') self.assertEquals(code.get_execname(), '/bin/ls') self.assertTrue(code.can_run_on(self.computer.dbcomputer)) self.assertTrue(code.can_run_on(self.computer)) othercomputer = Computer(name='another_localhost', hostname='localhost', transport_type='local', scheduler_type='pbspro', workdir='/tmp/aiida').store() self.assertFalse(code.can_run_on(othercomputer))
def test_session_update_and_expiration_2(self): """ expire_on_commit=True & committing computer and code objects with their built-in store function. """ from aiida.backends.sqlalchemy.models.user import DbUser from aiida.orm.computer import Computer from aiida.orm.code import Code from aiida.orm.user import User session = aiida.backends.sqlalchemy.get_scoped_session() self.set_connection(expire_on_commit=True) user = User(email=get_configured_user_email()) session.add(user._dbuser) session.commit() defaults = dict(name='localhost', hostname='localhost', transport_type='local', scheduler_type='pbspro', workdir='/tmp/aiida') computer = Computer(**defaults) computer.store() code = Code() code.set_remote_computer_exec((computer, '/x.x')) code.store() self.drop_connection()
def test_session_update_and_expiration_3(self): """ expire_on_commit=False & adding manually and committing computer and code objects. """ from aiida.orm.computer import Computer from aiida.orm.code import Code from aiida.orm.user import User self.set_connection(expire_on_commit=False) session = aiida.backends.sqlalchemy.get_scoped_session() user = User(email=get_configured_user_email()) session.add(user._dbuser) session.commit() defaults = dict(name='localhost', hostname='localhost', transport_type='local', scheduler_type='pbspro', workdir='/tmp/aiida') computer = Computer(**defaults) session.add(computer._dbcomputer) session.commit() code = Code() code.set_remote_computer_exec((computer, '/x.x')) session.add(code.dbnode) session.commit() self.drop_connection()
def setUpClass(cls): super(QETestCase, cls).setUpClass() cls.calc_params = { 'computer': cls.computer, 'resources': { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 } } cls.code = Code(remote_computer_exec=(cls.computer, '/x.x')).store()
def setUpClass(cls): super(LocalTestCase, cls).setUpClass() # Change transport type to local. cls.computer.set_transport_type('local') # Configure authinfo for cls.computer and cls.user. authinfo = DbAuthInfo(dbcomputer=cls.computer.dbcomputer, aiidauser=cls.user) authinfo.set_auth_params({}) authinfo.save() # Set up a code linked to cls.computer. The path is just a fake string. cls.code = Code(remote_computer_exec=(cls.computer, '/x.x')).store()
def test_code_local(self): code = Code(local_executable='test.sh') with self.assertRaises(ValidationError): # No file with name test.sh code.store() with tempfile.NamedTemporaryFile() as f: f.write("#/bin/bash\n\necho test run\n") f.flush() code.add_path(f.name, 'test.sh') code.store() self.assertTrue(code.can_run_on(self.computer)) self.assertTrue(code.get_local_executable(), 'test.sh') self.assertTrue(code.get_execname(), 'stest.sh')
def setUp(self): """ """ from aiida import work from aiida.orm.code import Code from aiida.orm.nodes.parameter import Dict from aiida.orm.nodes.structure import StructureData from aiida.orm.nodes.remote import RemoteData from ase.spacegroup import crystal from aiida_quantumespresso.calculations.pw import PwCalculation from aiida_yambo.calculations.gw import YamboCalculation from aiida.common.links import LinkType from aiida.orm.computer import Computer as AiidaOrmComputer from aiida.common.datastructures import calc_states from aiida.plugins.utils import DataFactory runner = work.Runner(poll_interval=0., rmq_config=None, enable_persistence=None) work.set_runner(runner) self.computer = AiidaOrmComputer(name="testcase") # conf_attrs hostname, description, enabled_state, transport_type, scheduler_type, workdir # mpirun_command , default_mpiprocs_per_machine, self.computer._set_hostname_string("localhost") self.computer._set_enabled_state_string('True') self.computer._set_transport_type_string("local") self.computer._set_scheduler_type_string("direct") self.computer._set_workdir_string("/tmp/testcase/{username}/base") self.computer.store() create_authinfo(computer=self.computer).store() self.code_yambo = Code() self.code_yambo.label = "yambo" os_env = os.environ.copy() yambo_path = subprocess.check_output(['which', 'mock_yambo'], env=os_env).strip() self.code_yambo.set_remote_computer_exec((self.computer, yambo_path)) self.code_yambo.set_input_plugin_name('yambo.yambo') self.code_p2y = Code() self.code_p2y.label = "p2y" p2y_path = subprocess.check_output(['which', 'mock_p2y'], env=os_env).strip() self.code_p2y.set_remote_computer_exec((self.computer, p2y_path)) self.code_p2y.set_input_plugin_name('yambo.yambo') self.code_yambo.store() self.code_p2y.store() self.calc_pw = PwCalculation() self.calc_pw.set_computer(self.computer) self.calc_pw.set_resources({ "num_machines": 1, "num_mpiprocs_per_machine": 16, 'default_mpiprocs_per_machine': 16 }) StructureData = DataFactory('structure') cell = [[15.8753100000, 0.0000000000, 0.0000000000], [0.0000000000, 15.8753100000, 0.0000000000], [0.0000000000, 0.0000000000, 2.4696584760]] s = StructureData(cell=cell) self.calc_pw.use_structure(s) print((self.calc_pw.store_all(), " pw calc")) pw_remote_folder = RemoteData(computer=self.computer, remote_path="/tmp/testcase/work/calcPW") print((pw_remote_folder.store(), "pw remote data")) self.calc_pw._set_state(calc_states.PARSING) pw_remote_folder.add_link_from(self.calc_pw, label='remote_folder', link_type=LinkType.CREATE) outputs = Dict( dict={ "lsda": False, "number_of_bands": 80, "number_of_electrons": 8.0, "number_of_k_points": 147, "non_colinear_calculation": False }) outputs.store() outputs.add_link_from(self.calc_pw, label='output_parameters', link_type=LinkType.CREATE) self.calc = YamboCalculation() self.calc.set_computer(self.computer) self.calc.use_code(self.code_p2y) p2y_settings = { u'ADDITIONAL_RETRIEVE_LIST': [u'r-*', u'o-*', u'l-*', u'l_*', u'LOG/l-*_CPU_1'], u'INITIALISE': True } yambo_settings = { u'ADDITIONAL_RETRIEVE_LIST': [u'r-*', u'o-*', u'l-*', u'l_*', u'LOG/l-*_CPU_1'] } self.calc.use_settings(Dict(dict=p2y_settings)) self.calc.set_resources({ "num_machines": 1, "num_mpiprocs_per_machine": 16, 'default_mpiprocs_per_machine': 16 }) self.calc.use_parent_calculation(self.calc_pw) print((self.calc.store_all(), " yambo calc")) self.calc._set_state(calc_states.PARSING) a = 5.388 cell = crystal('Si', [(0, 0, 0)], spacegroup=227, cellpar=[a, a, a, 90, 90, 90], primitive_cell=True) self.struc = StructureData(ase=cell) self.struc.store() self.parameters = Dict( dict={ "BndsRnXp": [1.0, 48.0], "Chimod": "Hartree", "DysSolver": "n", "FFTGvecs": 25, "FFTGvecs_units": "Ry", "GbndRnge": [1.0, 48.0], "HF_and_locXC": True, "LongDrXp": [1.0, 0.0, 0.0], "NGsBlkXp": 2, "NGsBlkXp_units": "Ry", "QPkrange": [[1, 145, 3, 5]], "SE_CPU": "1 2 4", "SE_ROLEs": "q qp b", "X_all_q_CPU": "1 1 4 2", "X_all_q_ROLEs": "q k c v", "em1d": True, "gw0": True, "ppa": True, "rim_cut": True }) self.yambo_settings = Dict( dict={ "ADDITIONAL_RETRIEVE_LIST": [ "r-*", "o-*", "l-*", "l_*", "LOG/l-*_CPU_1", "aiida/ndb.QP", "aiida/ndb.HF_and_locXC" ] }) self.p2y_settings = Dict( dict={ "ADDITIONAL_RETRIEVE_LIST": [ 'r-*', 'o-*', 'l-*', 'l_*', 'LOG/l-*_CPU_1', 'aiida/ndb.QP', 'aiida/ndb.HF_and_locXC' ], 'INITIALISE': True }) self.yambo_calc_set = Dict( dict={ 'resources': { "num_machines": 1, "num_mpiprocs_per_machine": 16 }, 'max_wallclock_seconds': 60 * 29, 'max_memory_kb': 1 * 88 * 1000000, "queue_name": "s3parvc3", #'custom_scheduler_commands': u"#PBS -A Pra14_3622" , 'environment_variables': { "OMP_NUM_THREADS": "1" } }) self.p2y_calc_set = Dict( dict={ 'resources': { "num_machines": 1, "num_mpiprocs_per_machine": 2 }, 'max_wallclock_seconds': 60 * 2, 'max_memory_kb': 1 * 10 * 1000000, "queue_name": "s3parvc3", # 'custom_scheduler_commands': u"#PBS -A Pra14_3622" , 'environment_variables': { "OMP_NUM_THREADS": "2" } }) self.remote_folder = RemoteData(computer=self.computer, remote_path="/tmp/testcase/work/calcX") self.remote_folder.store() self.remote_folder.add_link_from(self.calc, label='remote_folder', link_type=LinkType.CREATE) self.calc._set_state(calc_states.FINISHED)