def test_run_base_class(self): """Verify that it is impossible to run, submit or instantiate a base `CalcJob` class.""" with self.assertRaises(exceptions.InvalidOperation): CalcJob() with self.assertRaises(exceptions.InvalidOperation): launch.run(CalcJob) with self.assertRaises(exceptions.InvalidOperation): launch.run_get_node(CalcJob) with self.assertRaises(exceptions.InvalidOperation): launch.run_get_pk(CalcJob) with self.assertRaises(exceptions.InvalidOperation): launch.submit(CalcJob)
def test_workchain_builder_run_get_pk(self): builder = AddWorkChain.get_builder() builder.a = self.a builder.b = self.b result, pk = launch.run_get_pk(builder) self.assertEquals(result['result'], self.result) self.assertTrue(isinstance(pk, int))
def test_calcfunction_run_get_pk(self): """Test calcfunction run by run_get_pk.""" result, pk = launch.run_get_pk(add, term_a=self.term_a, term_b=self.term_b) self.assertEqual(result, self.result) self.assertTrue(isinstance(pk, int))
def test_workchain_run_get_pk(self): """Test workchain run by run_get_pk.""" result, pk = launch.run_get_pk(AddWorkChain, term_a=self.term_a, term_b=self.term_b) self.assertEqual(result['result'], self.result) self.assertTrue(isinstance(pk, int))
def test_workchain_builder_run_get_pk(self): """Test workchain builder that run by run_get_pk.""" builder = AddWorkChain.get_builder() builder.term_a = self.term_a builder.term_b = self.term_b result, pk = launch.run_get_pk(builder) self.assertEqual(result['result'], self.result) self.assertTrue(isinstance(pk, int))
def run_parse(): """ Creates and runs the parse calculation. """ builder = ParseCalculation.get_builder() builder.code = Code.get_from_string('tbmodels') # single-core on local machine builder.metadata.options = dict( resources=dict(num_machines=1, tot_num_mpiprocs=1), withmpi=False, ) builder.wannier_folder = get_input_folder() result, pid = run_get_pk(builder) print('\nRan calculation with PID', pid) print('Result:', result)
def test_launchers_dry_run_no_provenance(self): """Test the launchers in `dry_run` mode with `store_provenance=False`.""" from aiida.plugins import CalculationFactory ArithmeticAddCalculation = CalculationFactory('arithmetic.add') # pylint: disable=invalid-name code = orm.Code(input_plugin_name='arithmetic.add', remote_computer_exec=[self.computer, '/bin/true']).store() inputs = { 'code': code, 'x': orm.Int(1), 'y': orm.Int(1), 'metadata': { 'dry_run': True, 'store_provenance': False, 'options': { 'resources': { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 } } } } result = launch.run(ArithmeticAddCalculation, **inputs) self.assertEqual(result, {}) result, pk = launch.run_get_pk(ArithmeticAddCalculation, **inputs) self.assertEqual(result, {}) self.assertIsNone(pk) result, node = launch.run_get_node(ArithmeticAddCalculation, **inputs) self.assertEqual(result, {}) self.assertIsInstance(node, orm.CalcJobNode) self.assertFalse(node.is_stored) self.assertIsInstance(node.dry_run_info, dict) self.assertIn('folder', node.dry_run_info) self.assertIn('script_filename', node.dry_run_info) node = launch.submit(ArithmeticAddCalculation, **inputs) self.assertIsInstance(node, orm.CalcJobNode) self.assertFalse(node.is_stored)
def run_slice(): """ Creates and runs the slice calculation. """ builder = SliceCalculation.get_builder() builder.code = Code.get_from_string('tbmodels') builder.tb_model = get_singlefile_instance( description=u'InSb TB model', path='./reference_input/model.hdf5') # single-core on local machine builder.metadata.options = dict(resources=dict(num_machines=1, tot_num_mpiprocs=1), withmpi=False) builder.slice_idx = List(list=[0, 3, 2, 1]) result, pid = run_get_pk(builder) print('\nRan calculation with PID', pid) print('Result:\n', result)
def test_launchers_dry_run(self): """All launchers should work with `dry_run=True`, even `submit` which forwards to `run`.""" from aiida.plugins import CalculationFactory ArithmeticAddCalculation = CalculationFactory('arithmetic.add') # pylint: disable=invalid-name code = orm.Code(input_plugin_name='arithmetic.add', remote_computer_exec=[self.computer, '/bin/true']).store() inputs = { 'code': code, 'x': orm.Int(1), 'y': orm.Int(1), 'metadata': { 'dry_run': True, 'options': { 'resources': { 'num_machines': 1, 'num_mpiprocs_per_machine': 1 } } } } result = launch.run(ArithmeticAddCalculation, **inputs) self.assertEqual(result, {}) result, pk = launch.run_get_pk(ArithmeticAddCalculation, **inputs) self.assertEqual(result, {}) self.assertIsInstance(pk, int) result, node = launch.run_get_node(ArithmeticAddCalculation, **inputs) self.assertEqual(result, {}) self.assertIsInstance(node, orm.CalcJobNode) self.assertIsInstance(node.dry_run_info, dict) self.assertIn('folder', node.dry_run_info) self.assertIn('script_filename', node.dry_run_info) node = launch.submit(ArithmeticAddCalculation, **inputs) self.assertIsInstance(node, orm.CalcJobNode)
def run_symmetrize(): """ Creates and runs the symmetrize calculation. """ builder = SymmetrizeCalculation.get_builder() builder.code = Code.get_from_string('tbmodels') # single-core on local machine builder.metadata.options = dict(resources=dict(num_machines=1, tot_num_mpiprocs=1), withmpi=False) builder.tb_model = get_singlefile_instance( description=u'InAs unsymmetrized TB model', path='./reference_input/model_nosym.hdf5') builder.symmetries = get_singlefile_instance( description=u'InAs symmetries', path='./reference_input/symmetries.hdf5') result, pid = run_get_pk(builder) print('\nRan calculation with PID', pid) print('Result:', result)
def test_workchain_run_get_pk(self): result, pk = launch.run_get_pk(AddWorkChain, a=self.a, b=self.b) self.assertEquals(result['result'], self.result) self.assertTrue(isinstance(pk, int))
def test_calcfunction_run_get_pk(self): result, pk = launch.run_get_pk(add, a=self.a, b=self.b) self.assertEquals(result, self.result) self.assertTrue(isinstance(pk, int))