def test_bandgap_check_Vasp(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "bandstructure.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD, "db_file": ">>db_file<<"}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) my_wf = add_namefile(my_wf) # add a slug of fw-name to output files my_wf = add_bandgap_check(my_wf, check_bandgap_params={"max_gap": 0.1}, fw_name_constraint="structure optimization") self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # structure optimization should be completed self.assertEqual(self.lp.fireworks.find_one( {"name": "Si-structure optimization"}, {"state": 1})["state"], "COMPLETED") self.assertEqual(self.lp.fireworks.find_one( {"name": "Si-static"}, {"state": 1})["state"], "DEFUSED")
def test_wf(self): self.wf = self._simulate_vasprun(self.wf) self.assertEqual(len(self.wf.fws), self.ndeformations+2) defo_vis = [fw.tasks[2]['vasp_input_set'] for fw in self.wf.fws if "deform" in fw.name] assert all([vis.user_incar_settings['NSW'] == 99 for vis in defo_vis]) assert all([vis.user_incar_settings['IBRION'] == 2 for vis in defo_vis]) self.lp.add_wf(self.wf) # this is specific to bulk_modulus_wf "fit equation of state" that uses FW tag self.setup_task_docs() rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) if _write_task_docs: self.write_task_docs() # check relaxation d = self.get_task_collection().find_one({"task_label": {"$regex": "structure optimization"}}) self._check_run(d, mode="structure optimization") # check two of the deformation calculations d = self.get_task_collection().find_one({"task_label": {"$regex": "bulk_modulus deformation 0"}}) self._check_run(d, mode="bulk_modulus deformation 0") d = self.get_task_collection().find_one({"task_label": {"$regex": "bulk_modulus deformation 4"}}) self._check_run(d, mode="bulk_modulus deformation 4") # check the final results d = self.get_task_collection(coll_name="eos").find_one() self._check_run(d, mode="fit equation of state")
def test_wf(self): self.wf = self._simulate_vasprun(self.wf) # 2*relax + 3*polarization = 5 self.assertEqual(len(self.wf.fws), 5) # check VASP parameters on polarization calculation for interpolated structures interpolated_polarization_vis = [fw.tasks[7]['incar_update']['lcalcpol'] for fw in self.wf.fws if "polarization" in fw.name and "interpolation" in fw.name] assert all(interpolated_polarization_vis) self.lp.add_wf(self.wf) rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # Check polar relaxation d = self.get_task_collection().find_one({"task_label": "_polar_relaxation"}) self._check_run(d, "_polar_relaxation") # Check nonpolar relaxation d = self.get_task_collection().find_one({"task_label": "_nonpolar_relaxation"}) self._check_run(d, "_nonpolar_relaxation") # Check polarization calculations D = self.get_task_collection().find({"task_label": {"$regex": ".*polarization"}}) for d in D: self._check_run(d, d["task_label"])
def test_wf(self): self.wf = self._simulate_vasprun(self.wf) self.assertEqual(len(self.wf.fws), len(self.raman_config["MODES"]) * 2 + 3) self.lp.add_wf(self.wf) rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # check relaxation d = self.get_task_collection().find_one({"task_label": "structure optimization"}) self._check_run(d, mode="structure optimization") # check phonon DFPT calculation d = self.get_task_collection().find_one({"task_label": "static dielectric"}) self._check_run(d, mode="static dielectric") # check one of the raman static dielectric calculation d = self.get_task_collection().find_one({"task_label": "raman_0_0.005"}) self._check_run(d, mode="raman_0_0.005") # check the final results d = self.get_task_collection(coll_name="raman").find_one() self._check_run(d, mode="raman analysis") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def test_double_FF_opt(self): # location of test files test_double_FF_files = os.path.join(module_dir, "..", "..", "test_files", "double_FF_wf") # define starting molecule and workflow object initial_qcin = QCInput.from_file( os.path.join(test_double_FF_files, "block", "launcher_first", "mol.qin.opt_0")) initial_mol = initial_qcin.molecule real_wf = get_wf_double_FF_opt( molecule=initial_mol, pcm_dielectric=10.0, max_cores=32, qchem_input_params={ "basis_set": "6-311++g**", "overwrite_inputs": { "rem": { "sym_ignore": "true" } } }) # use powerup to replace run with fake run ref_dirs = { "first_FF_no_pcm": os.path.join(test_double_FF_files, "block", "launcher_first"), "second_FF_with_pcm": os.path.join(test_double_FF_files, "block", "launcher_second") } fake_wf = use_fake_qchem(real_wf, ref_dirs) self.lp.add_wf(fake_wf) rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) wf_test = self.lp.get_wf_by_fw_id(1) self.assertTrue( all([s == "COMPLETED" for s in wf_test.fw_states.values()])) first_FF = self.get_task_collection().find_one({ "task_label": "first_FF_no_pcm" }) self.assertEqual(first_FF["calcs_reversed"][0]["input"]["solvent"], None) self.assertEqual(first_FF["num_frequencies_flattened"], 1) first_FF_final_mol = Molecule.from_dict( first_FF["output"]["optimized_molecule"]) second_FF = self.get_task_collection().find_one({ "task_label": "second_FF_with_pcm" }) self.assertEqual(second_FF["calcs_reversed"][0]["input"]["solvent"], {"dielectric": "10.0"}) self.assertEqual(second_FF["num_frequencies_flattened"], 1) second_FF_initial_mol = Molecule.from_dict( second_FF["input"]["initial_molecule"]) self.assertEqual(first_FF_final_mol, second_FF_initial_mol)
def test_chgcar_db_read(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "static_only.yaml", vis=MPStaticSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD, "db_file": ">>db_file<<"}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) # set the flags for storing charge densties my_wf.fws[0].tasks[-1]["parse_chgcar"] = True my_wf.fws[0].tasks[-1]["parse_aeccar"] = True self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) d = self.get_task_collection().find_one() self._check_run(d, mode="static") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()])) chgcar_fs_id = d["calcs_reversed"][0]["chgcar_fs_id"] accar0_fs_id = d["calcs_reversed"][0]["aeccar0_fs_id"] accar2_fs_id = d["calcs_reversed"][0]["aeccar2_fs_id"] self.assertTrue(bool(chgcar_fs_id)) self.assertTrue(bool(accar0_fs_id)) self.assertTrue(bool(accar2_fs_id))
def test_parse_pass_write(self): input_file = "test.qin.opt_1" output_file = "test.qout.opt_1" calc_dir = os.path.join(module_dir, "..", "..", "test_files", "FF_working") p_task = QChemToDb(calc_dir=calc_dir, input_file=input_file, output_file=output_file, db_file=">>db_file<<") fw1 = Firework([p_task]) w_task = WriteInputFromIOSet(qchem_input_set="OptSet", write_to_dir=module_dir) fw2 = Firework([w_task], parents=fw1) wf = Workflow([fw1, fw2]) self.lp.add_wf(wf) rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) test_mol = QCInput.from_file(os.path.join(module_dir, "mol.qin")).molecule np.testing.assert_equal(self.act_mol.species, test_mol.species) np.testing.assert_equal(self.act_mol.cart_coords, test_mol.cart_coords)
def test_parse_pass_rotate_write(self): input_file = "pt_gs_wb97mv_tz_initial.in" output_file = "pt_gs_wb97mv_tz_initial_1_job.out" calc_dir = os.path.join(module_dir, "..", "..", "test_files") p_task = QChemToDb(calc_dir=calc_dir, input_file=input_file, output_file=output_file, db_file=">>db_file<<") fw1 = Firework([p_task]) atom_indexes = [6, 8, 9, 10] angle = 90.0 rot_task = RotateTorsion(atom_indexes=atom_indexes, angle=angle) w_task = WriteInputFromIOSet(qchem_input_set="OptSet", write_to_dir=module_dir) fw2 = Firework([rot_task, w_task], parents=fw1) wf = Workflow([fw1, fw2]) self.lp.add_wf(wf) rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) test_mol = QCInput.from_file(os.path.join(module_dir, "mol.qin")).molecule act_mol = Molecule.from_file( os.path.join(module_dir, "..", "..", "test_files", "pt_rotated_90.0.xyz")) np.testing.assert_equal(act_mol.species, test_mol.species) np.testing.assert_allclose(act_mol.cart_coords, test_mol.cart_coords, atol=0.0001)
def test_wf(self): wf = self._simulate_vasprun(self.wf_1) self.assertEqual(len(self.wf_1.fws), 5) # check vasp parameters for ionic relaxation ads_vis = [ fw.tasks[1]['vasp_input_set'] for fw in self.wf_1.fws if "adsorbate" in fw.name ] for vis in ads_vis: self.assertEqual(vis.incar['EDIFFG'], -0.05) self.assertEqual(vis.incar['ISIF'], 2) self.lp.add_wf(wf) rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # check relaxation d = self.get_task_collection().find_one( {"task_label": "H1-Ir_(1, 0, 0) adsorbate optimization 1"}) self._check_run(d, mode="H1-Ir_(1, 0, 0) adsorbate optimization 1") # Check bulk opt d = self.get_task_collection().find_one( {"task_label": "structure optimization"}) self._check_run(d, mode='oriented_ucell') wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def test_workflow(self): wf = self._get_simulated_wflow() self.assertEqual(wf.name, "Mn3Al - Exchange") # Heisenberg + VampireMC = 2 self.assertEqual(len(wf.fws), 2) fw_ids = self.lp.add_wf(wf) rapidfire(self.lp, fworker=FWorker(env={"db_file": self.db_file})) # Exchange collection exchange_collection = self.get_task_database().exchange # Check Heisenberg model mapping d = exchange_collection.find_one({"task_name": "heisenberg model"}) self._check_run(d, "heisenberg model") # Check Vampire MC d = exchange_collection.find_one({"task_name": "vampire caller"}) self._check_run(d, "vampire caller") # Check for "COMPLETED" status fw_id = list(fw_ids.values())[0] wf = self.lp.get_wf_by_fw_id(fw_id) is_completed = [s == "COMPLETED" for s in wf.fw_states.values()] self.assertTrue(all(is_completed))
def load_config(config, name="base"): """ Load a LaunchPad, FWorker of QueueAdapter from the configuration files. Args: config (str): Type of configuration file to load. Either "launchpad", "fworker" or "qadapter". name (str): Name of the configuration. Defaults to "base". Returns: Either a LaunchPad, FWorker or QueuAdapter, depending on the "config" argument. """ try: if config == "launchpad": return LaunchPad.from_file( os.path.join(os.path.expanduser("~"), ".workflow_config", "launchpad", name + "_launchpad.yaml")) if config == "fworker": return FWorker.from_file( os.path.join(os.path.expanduser("~"), ".workflow_config", "fworker", name + "_fworker.yaml")) if config == "qadapter": return CommonAdapter.from_file( os.path.join(os.path.expanduser("~"), ".workflow_config", "fworker", name + "_qadapter.yaml")) except FileNotFoundError: raise FileNotFoundError( "Did not find the corresponding configuration file in " + os.path.join(os.path.expanduser("~"), ".workflow_config") + ". Use 'vsc config " + config + "' to set up the " + name + " configuration for the " + config + ".")
def test_early_exit(self): os.chdir(MODULE_DIR) script_text = "echo hello from process $PPID; sleep 2" fw1 = Firework(ScriptTask.from_str(shell_cmd=script_text, parameters={"stdout_file": "task.out"}), fw_id=1) fw2 = Firework(ScriptTask.from_str(shell_cmd=script_text, parameters={"stdout_file": "task.out"}), fw_id=2) fw3 = Firework(ScriptTask.from_str(shell_cmd=script_text, parameters={"stdout_file": "task.out"}), fw_id=3) fw4 = Firework(ScriptTask.from_str(shell_cmd=script_text, parameters={"stdout_file": "task.out"}), fw_id=4) wf = Workflow([fw1, fw2, fw3, fw4], {1: [2, 3], 2: [4], 3: [4]}) self.lp.add_wf(wf) launch_multiprocess(self.lp, FWorker(), 'DEBUG', 0, 2, sleep_time=0.5) fw2 = self.lp.get_fw_by_id(2) fw3 = self.lp.get_fw_by_id(3) with open(os.path.join(fw2.launches[0].launch_dir, "task.out")) as f: fw2_text = f.read() with open(os.path.join(fw3.launches[0].launch_dir, "task.out")) as f: fw3_text = f.read() self.assertNotEqual(fw2_text, fw3_text)
def test_single_Vasp_dbinsertion(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD, "db_file": ">>db_file<<"}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) # add an msonable object to additional fields my_wf.fws[0].tasks[-1]['additional_fields'].update( {"test_additional_field": self.struct_si}) self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) d = self.get_task_collection().find_one() self._check_run(d, mode="structure optimization") self._check_run(d, mode="additional field") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def test_single_Vasp_dbinsertion(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={ "vasp_cmd": VASP_CMD, "db_file": ">>db_file<<" }) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) d = self._get_task_collection().find_one() self._check_run(d, mode="structure optimization")
def test_wf(self): # 1 host + 2 end point + 1 pathfinder = 4 self.assertEqual(len(self.wf.fws), 4) fw_ids = self.lp.add_wf(self.wf) rapidfire(self.lp, fworker=FWorker(env={"db_file": db_dir / "db.json"})) # 3 images fws are added after running the workflow run_wf = self.lp.get_wf_by_fw_id(list(fw_ids.values())[0]) self.assertEqual(len(run_wf.fws), 7) # check task docs host_tds = list(self.get_task_collection().find({ "approx_neb._source_wf_uuid": self.wf_id, "approx_neb.calc_type": "host", })) self.assertEqual(len(host_tds), 1) ep_tds = list(self.get_task_collection().find({ "approx_neb._source_wf_uuid": self.wf_id, "approx_neb.calc_type": "end_point", })) self.assertEqual(len(ep_tds), 2) im_tds = list(self.get_task_collection().find({ "approx_neb._source_wf_uuid": self.wf_id, "approx_neb.calc_type": "image", })) self.assertEqual(len(im_tds), 3) # check approx_neb doc aneb_doc = self.get_task_collection(coll_name="approx_neb").find_one( {"wf_uuid": self.wf_id}) for k in ["host", "end_points", "pathfinder", "images"]: self.assertIn(k, aneb_doc) self.assertIn("output", aneb_doc["host"]) self.assertEqual(len(aneb_doc["end_points"]), 2) for e in aneb_doc["end_points"]: self.assertIn("output", e) self.assertEqual(len(aneb_doc["pathfinder"].keys()), 1) self.assertIn("0+1", aneb_doc["pathfinder"]) self.assertIn("0+1", aneb_doc["images"]) self.assertEqual(len(aneb_doc["images"]["0+1"]), 3) for i in aneb_doc["images"]["0+1"]: self.assertIn("output", i) # check workflow finished without error is_completed = [s == "COMPLETED" for s in run_wf.fw_states.values()] self.assertTrue(all(is_completed)) self.assertEqual(len(is_completed), 7) # 3 images fws are added after running the workflow run_wf = self.lp.get_wf_by_fw_id(list(fw_ids.values())[0]) self.assertEqual(len(run_wf.fws), 7)
def setUpClass(cls): cls.fworker = FWorker() try: cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR') cls.lp.reset(password=None, require_password=False) except: raise unittest.SkipTest('MongoDB is not running in localhost:' '27017! Skipping tests.')
def fworker(): scratch_dir = os.path.join(MODULE_DIR, 'scratch_dir') os.mkdir(scratch_dir) yield FWorker(env={ "db_file": os.path.join(MODULE_DIR, "db.json"), 'scratch_dir': scratch_dir }) shutil.rmtree(scratch_dir)
def test_bandstructure_Vasp(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "bandstructure.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={ "vasp_cmd": VASP_CMD, "db_file": ">>db_file<<" }) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) my_wf = add_namefile(my_wf) # add a slug of fw-name to output files self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # make sure the structure relaxation ran OK d = self.get_task_collection().find_one( {"task_label": "structure optimization"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="structure optimization") # make sure the static run ran OK d = self.get_task_collection().find_one({"task_label": "static"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="static") # make sure the uniform run ran OK d = self.get_task_collection().find_one({"task_label": "nscf uniform"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="nscf uniform") # make sure the uniform run ran OK d = self.get_task_collection().find_one({"task_label": "nscf line"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="nscf line") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def __call__(self): copy = self.copy2cmcc() setup = self.TMsetup(copy) opt = self.opt(setup) force = self.hessian(opt) extract = self.extract(force) FF = self.FFsetup(extract) fit = self.FFfit(FF) workflow = Workflow([copy, setup, opt, force, extract, FF, fit], name=self.wfname) # store workflow and launch it locally #launchpad.add_wf(setup) self.launchpad.add_wf(workflow) rapidfire(self.launchpad, FWorker()) return
def test_no_opt_Fragmentation(self): db_file = os.path.join(db_dir, "db.json") mmdb = QChemCalcDb.from_db_file(db_file, admin=True) with open( os.path.join(module_dir, "..", "..", "test_files", "sb40.json")) as f: tmp = json.load(f) for entry in tmp: mmdb.insert(entry) with patch("atomate.qchem.firetasks.fragmenter.FWAction" ) as FWAction_patch: mock_FWAction = MagicMock() FWAction_patch.return_value = mock_FWAction mock_FWAction.as_dict.return_value = { "stored_data": {}, "exit": False, "update_spec": {}, "mod_spec": [], "additions": [], "detours": [], "defuse_children": False, "defuse_workflow": False, } # define starting molecule and workflow object initial_mol = Molecule.from_file( os.path.join(module_dir, "..", "..", "test_files", "top_11", "EC.xyz")) initial_mol.set_charge_and_spin(charge=-1) wf = get_fragmentation_wf( molecule=initial_mol, depth=1, pcm_dielectric=40.0, do_optimization=False, check_db=True, ) self.lp.add_wf(wf) rapidfire( self.lp, fworker=FWorker(env={ "max_cores": 24, "db_file": db_file }), pdb_on_exception=True, ) self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 0) mmdb.reset()
def test_reignite_wf(self): # Defuse workflow containing Zeus self.lp.defuse_wf(self.zeus_fw_id) defused_ids = self.lp.get_fw_ids({'state': 'DEFUSED'}) self.assertIn(self.zeus_fw_id, defused_ids) # Launch any remaining fireworks rapidfire(self.lp, self.fworker, m_dir=MODULE_DIR) # Reignite Zeus and his children's fireworks and launch them self.lp.reignite_wf(self.zeus_fw_id) rapidfire(self.lp, FWorker(), m_dir=MODULE_DIR) # Check for the status of all fireworks Zeus workflow in completed fwids fws_completed = set(self.lp.get_fw_ids({'state': 'COMPLETED'})) self.assertEqual(fws_completed, self.all_ids)
def main(): # set up the LaunchPad and reset it swarmpad = SwarmPad() swarmpad.reset('', require_password=False) firetask1 = ScriptTask.from_str('echo "starting"; sleep 30; echo "ending"') firetask2 = ScriptTask.from_str('echo "hello from BACKGROUND thread #1"') firetask3 = ScriptTask.from_str('echo "hello from BACKGROUND thread #2"') # Combine [firetasks] parallely to form a ParallelTask par_task = ParallelTask.from_firetasks([firetask1, firetask2]) # Combine the par_task and firetask3 sequentially firework = Firework([par_task, firetask3]) # store workflow and launch it locally swarmpad.add_wf(firework) rapidfire(swarmpad, FWorker())
def test_wf(self): self.wf = get_simulated_wf(self.wf) # 2 * relax + 3 * polarization = 5 self.assertEqual(len(self.wf.fws), 5) # check VASP parameters on polarization calculation for interpolated # structures interpolated_polarization_vis = [ fw.tasks[7]["incar_update"]["lcalcpol"] for fw in self.wf.fws if "polarization" in fw.name and "interpolation" in fw.name ] self.assertTrue(all(interpolated_polarization_vis)) fw_ids = self.lp.add_wf(self.wf) rapidfire(self.lp, fworker=FWorker(env={"db_file": db_dir / "db.json"})) # Check polar relaxation d = self.get_task_collection().find_one( {"task_label": "_polar_relaxation"}) self._check_run(d, "_polar_relaxation") # Check nonpolar relaxation d = self.get_task_collection().find_one( {"task_label": "_nonpolar_relaxation"}) self._check_run(d, "_nonpolar_relaxation") # Check polarization calculations all_d = self.get_task_collection().find( {"task_label": { "$regex": ".*polarization" }}) for d in all_d: self._check_run(d, d["task_label"]) # get a fw that can be used to identify the workflow fw_id = list(fw_ids.values())[0] # check workflow finished without error wf = self.lp.get_wf_by_fw_id(fw_id) is_completed = [s == "COMPLETED" for s in wf.fw_states.values()] self.assertTrue(all(is_completed))
def test_checkout_fw(self): os.chdir(MODULE_DIR) self.lp.add_wf(Firework(ScriptTask.from_str( shell_cmd='echo "hello 1"', parameters={"stdout_file": "task.out"}), fw_id=1)) self.lp.add_wf(Firework(ScriptTask.from_str( shell_cmd='echo "hello 2"', parameters={"stdout_file": "task.out"}), fw_id=2)) launch_multiprocess(self.lp, FWorker(), 'DEBUG', 0, 2, 10) fw1 = self.lp.get_fw_by_id(1) fw2 = self.lp.get_fw_by_id(2) self.assertEqual(fw1.launches[0].state_history[-1]["state"], "COMPLETED") self.assertEqual(fw2.launches[0].state_history[-1]["state"], "COMPLETED") with open(os.path.join(fw1.launches[0].launch_dir, "task.out")) as f: self.assertEqual(f.readlines(), ['hello 1\n']) with open(os.path.join(fw2.launches[0].launch_dir, "task.out")) as f: self.assertEqual(f.readlines(), ['hello 2\n'])
def test_lammps_wflow(self): wf = get_wf_basic(self.input_file_template, self.user_settings, lammps_data=self.data_file, input_filename=self.input_filename, db_file=self.db_file, dump_filenames=self.dump_filenames, name="peo_wflow_test", lammps_cmd=LAMMPS_CMD) if not LAMMPS_CMD: wf = use_fake_lammps(wf, self.reference_files_path) self.lp.add_wf(wf) # run rapidfire(self.lp, fworker=FWorker(env={"db_file": self.db_file})) d = self.get_task_collection().find_one() self._check_run(d)
def test_lammps_wflow(self): lammps_data = LammpsForceFieldData.from_file(self.data_file) log_filename = "peo.log" dump_filename = "peo.dump" dcd_traj_filename = "peo.dcd" timestep = 1 # in fmsec for 'real' units n_timesteps = 1000 dump_freq = 50 T = [300, 300, 100.0] # start, end, damp P = [0, 0, 100.0] # override default settings read from the json file with these user_settings = {"log": log_filename, "timestep": timestep, "run": n_timesteps, "pair_style": "buck/coul/cut 15.0", "pair_coeff": ["1 1 2649.6 0.2674 27.22", "1 2 4320.0 0.2928 137.6", "1 3 14176.0 0.2563 104.0", "2 2 14976.0 0.3236 637.6", "2 3 33702.4 0.2796 503.0", "3 3 75844.8 0.2461 396.9"], "thermo_style": "custom step time temp press pe ke etotal enthalpy fmax fnorm", "fix": "NPT all npt temp {T[0]} {T[1]} {T[2]} iso {P[0]} {P[1]} {P[2]}".format(T=T, P=P), "dump": [ "peodump all custom {} {} id type x y z ix iy iz mol".format(dump_freq, dump_filename), "traj all dcd {} {}".format(dump_freq, dcd_traj_filename)]} if not LAMMPS_CMD: # fake run lammps_bin = "cp ../../reference_files/peo.* ." dry_run = True else: lammps_bin = LAMMPS_CMD dry_run = False wf = wf_from_input_template(self.input_template, lammps_data, "npt.data", user_settings, is_forcefield=True, input_filename="lammps.inp", lammps_bin=lammps_bin, db_file=">>db_file<<", dry_run=dry_run) self.lp.add_wf(wf) # run rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) d = self._get_task_collection().find_one() self._check_run(d)
def test_Fragmentation(self): with patch("atomate.qchem.firetasks.fragmenter.FWAction") as FWAction_patch: mock_FWAction = MagicMock() FWAction_patch.return_value = mock_FWAction mock_FWAction.as_dict.return_value = {'stored_data': {}, 'exit': False, 'update_spec': {}, 'mod_spec': [], 'additions': [], 'detours': [], 'defuse_children': False, 'defuse_workflow': False} # location of test files test_FF_then_fragment_files = os.path.join(module_dir, "..", "..", "test_files", "FF_then_fragment_wf") # define starting molecule and workflow object initial_qcin = QCInput.from_file( os.path.join(test_FF_then_fragment_files, "block", "launcher_first", "mol.qin.opt_0")) initial_mol = initial_qcin.molecule real_wf = get_fragmentation_wf(molecule=initial_mol, depth=0, do_triplets=False) # use powerup to replace run with fake run ref_dirs = { "first FF": os.path.join(test_FF_then_fragment_files, "block", "launcher_first"), "fragment and FF_opt": os.path.join(test_FF_then_fragment_files, "block", "launcher_second") } fake_wf = use_fake_qchem(real_wf, ref_dirs) self.lp.add_wf(fake_wf) rapidfire( self.lp, fworker=FWorker(env={"max_cores": 32, "db_file": os.path.join(db_dir, "db.json")}), pdb_on_exception=True) first_FF = self.get_task_collection().find_one({ "task_label": "first FF" }) self.assertEqual(first_FF["calcs_reversed"][0]["input"]["solvent"], None) self.assertEqual(first_FF["num_frequencies_flattened"], 0) self.assertEqual(len(FWAction_patch.call_args[1]["additions"]), 5 * 3)
def test_wf(self): self.wf = self._simulate_vasprun(self.wf) self.assertEqual(len(self.wf.fws), 3) self.lp.add_wf(self.wf) rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # check relaxation d = self.get_task_collection().find_one( {"task_label": "structure optimization"}) self._check_run(d, mode="structure optimization") # check two of the deformation calculations d = self.get_task_collection().find_one({"task_label": "cs tensor"}) self._check_run(d, mode="cs tensor") d = self.get_task_collection().find_one({"task_label": "efg tensor"}) self._check_run(d, mode="efg tensor") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def fworker(fireworker_file=None, fworker_name="base"): """ Script to set up the configuration of the fireworker. Args: fireworker_file (str): fworker.yaml file from which to configure the fireworker. fworker_name (str): Which fworker configuration to add the fireworker to. Returns: None """ if fireworker_file: fireworker = FWorker.from_file(fireworker_file) else: name = input("Please provide the fireworker name: ") vasp_cmd = input("Please provide the full vasp command: ") fireworker = FWorker(name=name, env={"vasp_cmd": vasp_cmd}) # Make sure the fireworker has the required node categories. if fireworker.category: print( "\nNote: The category in the fireworker file has been adjuster to " "make sure that the jobs submitted on this fireworker only pick up " "the Fireworks with the correct category setting, i.e. corresponding " "to a number of nodes.\n") fireworker.category = ["none", "1nodes"] try: os.makedirs( os.path.join(os.path.expanduser("~"), ".workflow_config", "fworker")) except FileExistsError: pass config_fw_file = os.path.join(os.path.expanduser("~"), ".workflow_config", "fworker", fworker_name + "_fworker.yaml") fireworker.to_file(config_fw_file) print("Fireworker file written to " + config_fw_file + "\n")
def rapid(dummy): lpad = create_launchpad(LOCAL_DB_CONFIG) rapidfire(lpad, FWorker(), nlaunches=25000)