def correct(self): backup("*.nw*") actions = [] nwi = NwInput.from_file(self.input_file) for e in self.errors: if e == "autoz error": action = { "_set": { "geometry_options": ["units", "angstroms", "noautoz"] } } actions.append(action) elif e == "Bad convergence": t = nwi.tasks[self.ntasks - 1] if "cgmin" in t.theory_directives: nwi.tasks.pop(self.ntasks - 1) else: t.theory_directives["cgmin"] = "" for t in nwi.tasks: if t.operation.startswith("freq"): # You cannot calculate hessian with cgmin. t.theory_directives["nocgmin"] = "" action = {"_set": {"tasks": [t.as_dict() for t in nwi.tasks]}} actions.append(action) else: # For unimplemented errors, this should just cause the job to # die. return {"errors": self.errors, "actions": None} m = Modder() for action in actions: nwi = m.modify_object(action, nwi) nwi.write_file(self.input_file) return {"errors": self.errors, "actions": actions}
def correct(self): backup("*.nw*") actions = [] nwi = NwInput.from_file(self.input_file) for e in self.errors: if e == "autoz error": action = {"_set": {"geometry_options": ["units", "angstroms", "noautoz"]}} actions.append(action) elif e == "Bad convergence": t = nwi.tasks[self.ntasks - 1] if "cgmin" in t.theory_directives: nwi.tasks.pop(self.ntasks - 1) else: t.theory_directives["cgmin"] = "" for t in nwi.tasks: if t.operation.startswith("freq"): #You cannot calculate hessian with cgmin. t.theory_directives["nocgmin"] = "" action = {"_set": {"tasks": [t.as_dict() for t in nwi.tasks]}} actions.append(action) else: # For unimplemented errors, this should just cause the job to # die. return {"errors": self.errors, "actions": None} m = Modder() for action in actions: nwi = m.modify_object(action, nwi) nwi.write_file(self.input_file) return {"errors": self.errors, "actions": actions}
def apply_corrections_to_spec(corrections, spec): modder = Modder() for correction in corrections: actions = correction['actions'] for action in actions: if action['action_type'] == 'modify_object': if action['object']['source'] == 'fw_spec': myobject = spec[action['object']['key']] else: raise NotImplementedError( 'Object source "{}" not implemented in ' 'CheckTask'.format(action['object']['source'])) newobj = modder.modify_object(action['action'], myobject) spec[action['object']['key']] = newobj elif action['action_type'] == 'modify_dict': if action['dict']['source'] == 'fw_spec': mydict = spec[action['dict']['key']] else: raise NotImplementedError( 'Dict source "{}" not implemented in ' 'CheckTask'.format(action['dict']['source'])) modder.modify(action['action'], mydict) else: raise NotImplementedError( 'Action type "{}" not implemented in ' 'CheckTask'.format(action['action_type']))
def apply_corrections(self, fw_to_correct, corrections): # Apply the corrections spec = fw_to_correct.spec modder = Modder() for correction in corrections: actions = correction['actions'] for action in actions: if action['action_type'] == 'modify_object': if action['object']['source'] == 'fw_spec': myobject = spec[action['object']['key']] else: raise NotImplementedError('Object source "{}" not implemented in ' 'CheckTask'.format(action['object']['source'])) newobj = modder.modify_object(action['action'], myobject) spec[action['object']['key']] = newobj elif action['action_type'] == 'modify_dict': if action['dict']['source'] == 'fw_spec': mydict = spec[action['dict']['key']] else: raise NotImplementedError('Dict source "{}" not implemented in ' 'CheckTask'.format(action['dict']['source'])) modder.modify(action['action'], mydict) else: raise NotImplementedError('Action type "{}" not implemented in ' 'CheckTask'.format(action['action_type'])) # Keep track of the corrections that have been applied spec['SRC_check_corrections'] = corrections # Update the task index fws_task_index = int(fw_to_correct.spec['wf_task_index'].split('_')[-1]) new_index = fws_task_index + 1 # Update the Fireworks _queueadapter key #TODO: in the future, see whether the FW queueadapter might be replaced by the qtk_queueadapter ? # ... to be discussed with Anubhav, when the qtk queueadapter is in a qtk toolkit and not anymore # in pymatgen/io/abinit spec['_queueadapter'] = spec['qtk_queueadapter'].get_subs_dict() queue_adapter_update = get_queue_adapter_update(qtk_queueadapter=spec['qtk_queueadapter'], corrections=corrections) # Get and update the task_input if needed # TODO: make this more general ... right now, it is based on AbinitInput and thus is strongly tight # to abinit due to abiinput, deps, ... mytask = fw_to_correct.tasks[0] task_class = mytask.__class__ decoder = MontyDecoder() task_input = decoder.process_decoded(fw_to_correct.spec['_tasks'][0]['abiinput']) initialization_info = fw_to_correct.spec['initialization_info'] deps = mytask.deps # Create the new Setup/Run/Check fireworks SRC_fws = createSRCFireworksOld(task_class=task_class, task_input=task_input, SRC_spec=spec, initialization_info=initialization_info, wf_task_index_prefix=spec['wf_task_index_prefix'], current_task_index=new_index, handlers=self.handlers, validators=self.validators, deps=deps, task_type=mytask.task_type, queue_adapter_update=queue_adapter_update) wf = Workflow(fireworks=SRC_fws['fws'], links_dict=SRC_fws['links_dict']) return FWAction(detours=[wf])
def apply_corrections_to_spec(corrections, spec): modder = Modder() for correction in corrections: actions = correction['actions'] for action in actions: if action['action_type'] == 'modify_object': if action['object']['source'] == 'fw_spec': myobject = spec[action['object']['key']] else: raise NotImplementedError('Object source "{}" not implemented in ' 'CheckTask'.format(action['object']['source'])) newobj = modder.modify_object(action['action'], myobject) spec[action['object']['key']] = newobj elif action['action_type'] == 'modify_dict': if action['dict']['source'] == 'fw_spec': mydict = spec[action['dict']['key']] else: raise NotImplementedError('Dict source "{}" not implemented in ' 'CheckTask'.format(action['dict']['source'])) modder.modify(action['action'], mydict) else: raise NotImplementedError('Action type "{}" not implemented in ' 'CheckTask'.format(action['action_type']))
def correct(self): #pylint: disable=R0915,R0912,R0914 """ "brmix"にてINCARにADDGRIDを追加する """ backup([self.output_filename, "INCAR", "KPOINTS", "POSCAR", "OUTCAR", "vasprun.xml"]) actions = [] vi = VaspInput.from_directory(".") if "tet" in self.errors or "dentet" in self.errors: actions.append({"dict": "INCAR", "action": {"_set": {"ISMEAR": 0}}}) if "inv_rot_mat" in self.errors: actions.append({"dict": "INCAR", "action": {"_set": {"SYMPREC": 1e-8}}}) if "brmix" in self.errors and "NELECT" in vi["INCAR"]: #brmix error always shows up after DAV steps if NELECT is specified self.errors.remove("brmix") if "brmix" in self.errors or "zpotrf" in self.errors: actions.append({"dict": "INCAR", "action": {"_set": {"ISYM": 0}}}) #140814 add actions.append({"dict": "INCAR", "action": {"_set": {"ADDGRID": True}}}) # Based on VASP forum's recommendation, you should delete the # CHGCAR and WAVECAR when dealing with these errors. actions.append({"file": "CHGCAR", "action": {"_file_delete": {'mode': "actual"}}}) actions.append({"file": "WAVECAR", "action": {"_file_delete": {'mode': "actual"}}}) if "subspacematrix" in self.errors or "rspher" in self.errors or \ "real_optlay" in self.errors: actions.append({"dict": "INCAR", "action": {"_set": {"LREAL": False}}}) if "tetirr" in self.errors or "incorrect_shift" in self.errors or \ "rot_matrix" in self.errors: actions.append({"dict": "KPOINTS", "action": {"_set": {"generation_style": "Gamma"}}}) if "amin" in self.errors: actions.append({"dict": "INCAR", "action": {"_set": {"AMIN": "0.01"}}}) if "triple_product" in self.errors: s = vi["POSCAR"].structure trans = SupercellTransformation(((1, 0, 0), (0, 0, 1), (0, 1, 0))) new_s = trans.apply_transformation(s) actions.append({"dict": "POSCAR", "action": {"_set": {"structure": new_s.to_dict}}, "transformation": trans.to_dict}) if "pricel" in self.errors: actions.append({"dict": "INCAR", "action": {"_set": {"SYMPREC": 1e-8, "ISYM": 0}}}) if "brions" in self.errors: potim = float(vi["INCAR"].get("POTIM", 0.5)) + 0.1 actions.append({"dict": "INCAR", "action": {"_set": {"POTIM": potim}}}) if "zbrent" in self.errors: actions.append({"dict": "INCAR", "action": {"_set": {"IBRION": 1}}}) if "too_few_bands" in self.errors: if "NBANDS" in vi["INCAR"]: nbands = int(vi["INCAR"]["NBANDS"]) else: with open("OUTCAR") as f: for line in f: if "NBANDS" in line: try: d = line.split("=") nbands = int(d[-1].strip()) break except (IndexError, ValueError): pass actions.append({"dict": "INCAR", "action": {"_set": {"NBANDS": int(1.1 * nbands)}}}) if "aliasing" in self.errors: with open("OUTCAR") as f: grid_adjusted = False changes_dict = {} for line in f: if "aliasing errors" in line: try: grid_vector = line.split(" NG", 1)[1] value = [int(s) for s in grid_vector.split(" ") if s.isdigit()][0] changes_dict["NG" + grid_vector[0]] = value grid_adjusted = True except (IndexError, ValueError): pass #Ensure that all NGX, NGY, NGZ have been checked if grid_adjusted and 'NGZ' in line: actions.append({"dict": "INCAR", "action": {"_set": changes_dict}}) break m = Modder(actions=[DictActions, FileActions]) modified = [] for a in actions: if "dict" in a: modified.append(a["dict"]) vi[a["dict"]] = m.modify_object(a["action"], vi[a["dict"]]) elif "file" in a: m.modify(a["action"], a["file"]) for f in modified: vi[f].write_file(f) return {"errors": list(self.errors), "actions": actions}
def test_modify_object(self): modder = Modder() o = MyObject(1) self.assertEqual(o.b["a"], 1) mod_o = modder.modify_object({'_set': {'b->a': 20}}, o) self.assertEqual(mod_o.b["a"], 20)
def apply_corrections(self, fw_to_correct, corrections): # Apply the corrections spec = fw_to_correct.spec modder = Modder() for correction in corrections: actions = correction['actions'] for action in actions: if action['action_type'] == 'modify_object': if action['object']['source'] == 'fw_spec': myobject = spec[action['object']['key']] else: raise NotImplementedError( 'Object source "{}" not implemented in ' 'CheckTask'.format(action['object']['source'])) newobj = modder.modify_object(action['action'], myobject) spec[action['object']['key']] = newobj elif action['action_type'] == 'modify_dict': if action['dict']['source'] == 'fw_spec': mydict = spec[action['dict']['key']] else: raise NotImplementedError( 'Dict source "{}" not implemented in ' 'CheckTask'.format(action['dict']['source'])) modder.modify(action['action'], mydict) else: raise NotImplementedError( 'Action type "{}" not implemented in ' 'CheckTask'.format(action['action_type'])) # Keep track of the corrections that have been applied spec['SRC_check_corrections'] = corrections # Update the task index fws_task_index = int( fw_to_correct.spec['wf_task_index'].split('_')[-1]) new_index = fws_task_index + 1 # Update the Fireworks _queueadapter key #TODO: in the future, see whether the FW queueadapter might be replaced by the qtk_queueadapter ? # ... to be discussed with Anubhav, when the qtk queueadapter is in a qtk toolkit and not anymore # in pymatgen/io/abinit spec['_queueadapter'] = spec['qtk_queueadapter'].get_subs_dict() queue_adapter_update = get_queue_adapter_update( qtk_queueadapter=spec['qtk_queueadapter'], corrections=corrections) # Get and update the task_input if needed # TODO: make this more general ... right now, it is based on AbinitInput and thus is strongly tight # to abinit due to abiinput, deps, ... mytask = fw_to_correct.tasks[0] task_class = mytask.__class__ decoder = MontyDecoder() task_input = decoder.process_decoded( fw_to_correct.spec['_tasks'][0]['abiinput']) initialization_info = fw_to_correct.spec['initialization_info'] deps = mytask.deps # Create the new Setup/Run/Check fireworks SRC_fws = createSRCFireworksOld( task_class=task_class, task_input=task_input, SRC_spec=spec, initialization_info=initialization_info, wf_task_index_prefix=spec['wf_task_index_prefix'], current_task_index=new_index, handlers=self.handlers, validators=self.validators, deps=deps, task_type=mytask.task_type, queue_adapter_update=queue_adapter_update) wf = Workflow(fireworks=SRC_fws['fws'], links_dict=SRC_fws['links_dict']) return FWAction(detours=[wf])