Esempio n. 1
0
    def correct(self):

        content = "LSTOP = .TRUE." if not self.electronic_step_stop else \
            "LABORT = .TRUE."
        #Write STOPCAR
        actions = [{
            "file": "STOPCAR",
            "action": {
                "_file_create": {
                    'content': content
                }
            }
        }]

        if self.auto_continue:
            actions.append({
                "file": "STOPCAR",
                "action": {
                    "_file_modify": {
                        'mode': 0o444
                    }
                }
            })

        m = Modder(actions=[FileActions])
        for a in actions:
            m.modify(a["action"], a["file"])
        # Actions is being returned as None so that custodian will stop after
        # STOPCAR is written. We do not want subsequent jobs to proceed.
        return {"errors": ["Walltime reached"], "actions": None}
Esempio n. 2
0
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']))
Esempio n. 3
0
    def correct(self):
        content = "LSTOP = .TRUE."
        chkpt_content = "Index: %d\nTime: \"%s\"" % (self.chk_counter,
                                                     datetime.datetime.now())
        self.chk_counter += 1

        #Write STOPCAR
        actions = [{
            "file": "STOPCAR",
            "action": {
                "_file_create": {
                    'content': content
                }
            }
        }, {
            "file": "chkpt.yaml",
            "action": {
                "_file_create": {
                    'content': chkpt_content
                }
            }
        }]

        m = Modder(actions=[FileActions])
        for a in actions:
            m.modify(a["action"], a["file"])

        # Reset the clock.
        self.start_time = datetime.datetime.now()

        return {"errors": ["Checkpoint reached"], "actions": actions}
Esempio n. 4
0
    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}
Esempio n. 5
0
    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}
Esempio n. 6
0
    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])
Esempio n. 7
0
    def correct(self):

        content = "LSTOP = .TRUE." if not self.electronic_step_stop else "LABORT = .TRUE."
        # Write STOPCAR
        actions = [{"file": "STOPCAR", "action": {"_file_create": {"content": content}}}]
        m = Modder(actions=[FileActions])
        for a in actions:
            m.modify(a["action"], a["file"])
        # Actions is being returned as None so that custodian will stop after
        # STOPCAR is written. We do not want subsequent jobs to proceed.
        return {"errors": ["Walltime reached"], "actions": None}
Esempio n. 8
0
    def correct(self):

        content = "LSTOP = .TRUE." if not self.electronic_step_stop else \
            "LABORT = .TRUE."
        # Write STOPCAR
        actions = [{"file": "STOPCAR",
                    "action": {"_file_create": {'content': content}}}]

        m = Modder(actions=[FileActions])
        for a in actions:
            m.modify(a["action"], a["file"])
        return {"errors": ["Walltime reached"], "actions": None}
Esempio n. 9
0
    def correct(self):
        d = loadfn("chkpt.yaml")
        i = d["Index"]
        name = shutil.make_archive(os.path.join(os.getcwd(), "vasp.chk.%d" % i), "gztar")

        actions = [{"file": "CONTCAR", "action": {"_file_copy": {"dest": "POSCAR"}}}]

        m = Modder(actions=[FileActions])
        for a in actions:
            m.modify(a["action"], a["file"])

        actions.append({"Checkpoint": name})

        return {"errors": ["Stopped run."], "actions": actions}
Esempio n. 10
0
    def correct(self):
        # Write ``stop`` file
        actions = [{
            "file": "stop",
            "action": {
                "_file_create": {
                    'content': ''
                }
            }
        }]

        m = Modder(actions=[FileActions])
        for a in actions:
            m.modify(a["action"], a["file"])
        return {"errors": ["Walltime reached"], "actions": None}
Esempio n. 11
0
    def test_strict_mode(self):
        modder = Modder(actions=[FileActions])
        d = {"Hello": "World"}
        mod = {'_set': {'Hello': 'Universe', 'Bye': 'World'}}
        self.assertRaises(ValueError, modder.modify, mod, d)

        #In non-strict mode, unknown actions are ignored.
        d = {"Hello": "World"}
        modder = Modder(actions=[FileActions], strict=False)
        modder.modify(mod, d)
        self.assertEqual(d, {"Hello": "World"})

        #File actions not supported
        modder = Modder()
        self.assertRaises(ValueError, modder.modify,
                          {'_file_create': {'content': 'Test data'}},
                          'test_file')
Esempio n. 12
0
    def correct(self):
        d = loadfn("chkpt.yaml")
        i = d["Index"]
        name = shutil.make_archive(
            os.path.join(os.getcwd(), "vasp.chk.%d" % i), "gztar")

        actions = [{"file": "CONTCAR",
                    "action": {"_file_copy": {"dest": "POSCAR"}}}]

        m = Modder(actions=[FileActions])
        for a in actions:
            m.modify(a["action"], a["file"])

        actions.append({"Checkpoint": name})

        return {"errors": ["Stopped run."],
                "actions": actions}
Esempio n. 13
0
    def correct(self):
        content = "LSTOP = .TRUE."
        chkpt_content = 'Index: %d\nTime: "%s"' % (self.chk_counter, datetime.datetime.now())
        self.chk_counter += 1

        # Write STOPCAR
        actions = [
            {"file": "STOPCAR", "action": {"_file_create": {"content": content}}},
            {"file": "chkpt.yaml", "action": {"_file_create": {"content": chkpt_content}}},
        ]

        m = Modder(actions=[FileActions])
        for a in actions:
            m.modify(a["action"], a["file"])

        # Reset the clock.
        self.start_time = datetime.datetime.now()

        return {"errors": ["Checkpoint reached"], "actions": actions}
Esempio n. 14
0
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']))
Esempio n. 15
0
    def test_strict_mode(self):
        modder = Modder(actions=[FileActions])
        d = {"Hello": "World"}
        mod = {'_set': {'Hello': 'Universe', 'Bye': 'World'}}
        self.assertRaises(ValueError, modder.modify, mod, d)

        #In non-strict mode, unknown actions are ignored.
        d = {"Hello": "World"}
        modder = Modder(actions=[FileActions], strict=False)
        modder.modify(mod, d)
        self.assertEqual(d, {"Hello": "World"})

        #File actions not supported
        modder = Modder()
        self.assertRaises(ValueError, modder.modify,
                          {'_file_create': {'content': 'Test data'}},
                          'test_file')
Esempio n. 16
0
    def test_strict_mode(self):
        modder = Modder(actions=[FileActions])
        d = {"Hello": "World"}
        mod = {"_set": {"Hello": "Universe", "Bye": "World"}}
        self.assertRaises(ValueError, modder.modify, mod, d)

        # In non-strict mode, unknown actions are ignored.
        d = {"Hello": "World"}
        modder = Modder(actions=[FileActions], strict=False)
        modder.modify(mod, d)
        self.assertEqual(d, {"Hello": "World"})

        # File actions not supported
        modder = Modder()
        self.assertRaises(
            ValueError,
            modder.modify,
            {"_file_create": {"content": "Test data"}},
            "test_file",
        )
Esempio n. 17
0
 def test_dict_modify(self):
     modder = Modder()
     d = {"Hello": "World"}
     mod = {'_set': {'Hello': 'Universe', 'Bye': 'World'}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'Hello': 'Universe'})
     mod = {'_unset': {'Hello': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World'})
     mod = {'_push': {'List': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1]})
     mod = {'_push': {'List': 2}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2]})
     mod = {'_inc': {'num': 5}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2], 'num': 5})
     mod = {'_inc': {'num': 5}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2], 'num': 10})
     mod = {'_rename': {'num': 'number'}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2], 'number': 10})
     mod = {'_add_to_set': {'List': 2}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2], 'number': 10})
     mod = {'_add_to_set': {'List': 3}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2, 3], 'number': 10})
     mod = {'_add_to_set': {'number': 3}}
     self.assertRaises(ValueError, modder.modify, mod, d)
     mod = {'_pull': {'List': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [2, 3], 'number': 10})
     mod = {'_pull_all': {'List': [2, 3]}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [], 'number': 10})
     mod = {'_push_all': {'List': list(range(10))}}
     modder.modify(mod, d)
     self.assertEqual(d, {
         'Bye': 'World',
         'List': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
         'number': 10
     })
     mod = {'_pop': {'List': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {
         'Bye': 'World',
         'List': [0, 1, 2, 3, 4, 5, 6, 7, 8],
         'number': 10
     })
     mod = {'_pop': {'List': -1}}
     modder.modify(mod, d)
     self.assertEqual(d, {
         'Bye': 'World',
         'List': [1, 2, 3, 4, 5, 6, 7, 8],
         'number': 10
     })
     d = {}
     mod = {'_set': {'a->b->c': 100}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100}}})
     mod = {'_set': {'a->b->d': 200}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100, 'd': 200}}})
     mod = {'_set': {'a->b->d': 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100, 'd': 300}}})
     mod = {'_unset': {'a->b->d': 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100}}})
     mod = {'_push': {'a->e->f': 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100}, 'e': {'f': [300]}}})
     mod = {'_push_all': {'a->e->f': [100, 200]}}
     modder.modify(mod, d)
     self.assertEqual(d,
                      {'a': {
                          'b': {
                              'c': 100
                          },
                          'e': {
                              'f': [300, 100, 200]
                          }
                      }})
     mod = {'_inc': {'a->b->c': 2}}
     modder.modify(mod, d)
     self.assertEqual(d,
                      {'a': {
                          'b': {
                              'c': 102
                          },
                          'e': {
                              'f': [300, 100, 200]
                          }
                      }})
     mod = {'_pull': {'a->e->f': 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102}, 'e': {'f': [100, 200]}}})
     mod = {'_pull_all': {'a->e->f': [100, 200]}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102}, 'e': {'f': []}}})
     mod = {'_push_all': {'a->e->f': [101, 201, 301, 401]}}
     modder.modify(mod, d)
     self.assertEqual(
         d, {'a': {
             'b': {
                 'c': 102
             },
             'e': {
                 'f': [101, 201, 301, 401]
             }
         }})
     mod = {'_pop': {'a->e->f': 1}}
     modder.modify(mod, d)
     self.assertEqual(d,
                      {'a': {
                          'b': {
                              'c': 102
                          },
                          'e': {
                              'f': [101, 201, 301]
                          }
                      }})
     mod = {'_pop': {'a->e->f': -1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102}, 'e': {'f': [201, 301]}}})
Esempio n. 18
0
 def test_file_modify(self):
     modder = Modder(actions=[FileActions])
     modder.modify({'_file_create': {'content': 'Test data'}}, 'test_file')
     modder.modify({'_file_copy': {'dest': 'test_file_copy'}}, 'test_file')
     modder.modify({'_file_copy': {'dest1': 'test_file_copy1',
                                   'dest2': 'test_file_copy2'}},
                   'test_file')
     modder.modify({'_file_move': {'dest': 'renamed_test_file'}},
                   'test_file')
     modder.modify({'_file_delete': {'mode': "actual"}},
                   'renamed_test_file')
     modder.modify({'_file_modify': {'mode': 0o666}}, 'test_file_copy')
     modder.modify({'_file_delete': {'mode': "actual"}}, 'test_file_copy')
     modder.modify({'_file_delete': {'mode': "actual"}}, 'test_file_copy1')
     modder.modify({'_file_delete': {'mode': "actual"}}, 'test_file_copy2')
Esempio n. 19
0
 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)
Esempio n. 20
0
 def test_dict_modify(self):
     modder = Modder()
     d = {"Hello": "World"}
     mod = {'_set': {'Hello': 'Universe', 'Bye': 'World'}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'Hello': 'Universe'})
     mod = {'_unset': {'Hello': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World'})
     mod = {'_push': {'List': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1]})
     mod = {'_push': {'List': 2}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2]})
     mod = {'_inc': {'num': 5}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2], 'num': 5})
     mod = {'_inc': {'num': 5}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2], 'num': 10})
     mod = {'_rename': {'num': 'number'}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2], 'number': 10})
     mod = {'_add_to_set': {'List': 2}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2], 'number': 10})
     mod = {'_add_to_set': {'List': 3}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2, 3], 'number': 10})
     mod = {'_add_to_set': {'number': 3}}
     self.assertRaises(ValueError, modder.modify, mod, d)
     mod = {'_pull': {'List': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [2, 3], 'number': 10})
     mod = {'_pull_all': {'List': [2, 3]}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [], 'number': 10})
     mod = {'_push_all': {'List': list(range(10))}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World',
                          'List': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
                          'number': 10})
     mod = {'_pop': {'List': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World',
                          'List': [0, 1, 2, 3, 4, 5, 6, 7, 8],
                          'number': 10})
     mod = {'_pop': {'List':-1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'Bye': 'World', 'List': [1, 2, 3, 4, 5, 6, 7, 8],
                          'number': 10})
     d = {}
     mod = {'_set': {'a->b->c': 100}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100}}})
     mod = {'_set': {'a->b->d': 200}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100, 'd': 200}}})
     mod = {'_set': {'a->b->d': 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100, 'd': 300}}})
     mod = {'_unset': {'a->b->d': 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100}}})
     mod = {'_push': {'a->e->f': 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100}, 'e': {'f': [300]}}})
     mod = {'_push_all': {'a->e->f': [100, 200]}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 100},
                                'e': {'f': [300, 100, 200]}}})
     mod = {'_inc': {'a->b->c': 2}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102},
                                'e': {'f': [300, 100, 200]}}})
     mod = {'_pull': {'a->e->f': 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102}, 'e': {'f': [100, 200]}}})
     mod = {'_pull_all': {'a->e->f': [100, 200]}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102}, 'e': {'f': []}}})
     mod = {'_push_all': {'a->e->f': [101, 201, 301, 401]}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102},
                                'e': {'f': [101, 201, 301, 401]}}})
     mod = {'_pop': {'a->e->f': 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102},
                                'e': {'f': [101, 201, 301]}}})
     mod = {'_pop': {'a->e->f':-1}}
     modder.modify(mod, d)
     self.assertEqual(d, {'a': {'b': {'c': 102}, 'e': {'f': [201, 301]}}})
Esempio n. 21
0
 def test_file_modify(self):
     modder = Modder(actions=[FileActions])
     modder.modify({"_file_create": {"content": "Test data"}}, "test_file")
     modder.modify({"_file_copy": {"dest": "test_file_copy"}}, "test_file")
     modder.modify(
         {"_file_copy": {"dest1": "test_file_copy1", "dest2": "test_file_copy2"}},
         "test_file",
     )
     modder.modify({"_file_move": {"dest": "renamed_test_file"}}, "test_file")
     modder.modify({"_file_delete": {"mode": "actual"}}, "renamed_test_file")
     modder.modify({"_file_modify": {"mode": 0o666}}, "test_file_copy")
     modder.modify({"_file_delete": {"mode": "actual"}}, "test_file_copy")
     modder.modify({"_file_delete": {"mode": "actual"}}, "test_file_copy1")
     modder.modify({"_file_delete": {"mode": "actual"}}, "test_file_copy2")
Esempio n. 22
0
 def test_dict_modify(self):
     modder = Modder()
     d = {"Hello": "World"}
     mod = {"_set": {"Hello": "Universe", "Bye": "World"}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "Hello": "Universe"})
     mod = {"_unset": {"Hello": 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World"})
     mod = {"_push": {"List": 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [1]})
     mod = {"_push": {"List": 2}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [1, 2]})
     mod = {"_inc": {"num": 5}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [1, 2], "num": 5})
     mod = {"_inc": {"num": 5}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [1, 2], "num": 10})
     mod = {"_rename": {"num": "number"}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [1, 2], "number": 10})
     mod = {"_add_to_set": {"List": 2}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [1, 2], "number": 10})
     mod = {"_add_to_set": {"List": 3}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [1, 2, 3], "number": 10})
     mod = {"_add_to_set": {"number": 3}}
     self.assertRaises(ValueError, modder.modify, mod, d)
     mod = {"_pull": {"List": 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [2, 3], "number": 10})
     mod = {"_pull_all": {"List": [2, 3]}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [], "number": 10})
     mod = {"_push_all": {"List": list(range(10))}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "number": 10})
     mod = {"_pop": {"List": 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [0, 1, 2, 3, 4, 5, 6, 7, 8], "number": 10})
     mod = {"_pop": {"List": -1}}
     modder.modify(mod, d)
     self.assertEqual(d, {"Bye": "World", "List": [1, 2, 3, 4, 5, 6, 7, 8], "number": 10})
     d = {}
     mod = {"_set": {"a->b->c": 100}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 100}}})
     mod = {"_set": {"a->b->d": 200}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 100, "d": 200}}})
     mod = {"_set": {"a->b->d": 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 100, "d": 300}}})
     mod = {"_unset": {"a->b->d": 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 100}}})
     mod = {"_push": {"a->e->f": 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 100}, "e": {"f": [300]}}})
     mod = {"_push_all": {"a->e->f": [100, 200]}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 100}, "e": {"f": [300, 100, 200]}}})
     mod = {"_inc": {"a->b->c": 2}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 102}, "e": {"f": [300, 100, 200]}}})
     mod = {"_pull": {"a->e->f": 300}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 102}, "e": {"f": [100, 200]}}})
     mod = {"_pull_all": {"a->e->f": [100, 200]}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 102}, "e": {"f": []}}})
     mod = {"_push_all": {"a->e->f": [101, 201, 301, 401]}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 102}, "e": {"f": [101, 201, 301, 401]}}})
     mod = {"_pop": {"a->e->f": 1}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 102}, "e": {"f": [101, 201, 301]}}})
     mod = {"_pop": {"a->e->f": -1}}
     modder.modify(mod, d)
     self.assertEqual(d, {"a": {"b": {"c": 102}, "e": {"f": [201, 301]}}})
Esempio n. 23
0
 def test_file_modify(self):
     modder = Modder(actions=[FileActions])
     modder.modify({'_file_create': {'content': 'Test data'}}, 'test_file')
     modder.modify({'_file_copy': {'dest': 'test_file_copy'}}, 'test_file')
     modder.modify(
         {
             '_file_copy': {
                 'dest1': 'test_file_copy1',
                 'dest2': 'test_file_copy2'
             }
         }, 'test_file')
     modder.modify({'_file_move': {
         'dest': 'renamed_test_file'
     }}, 'test_file')
     modder.modify({'_file_delete': {
         'mode': "actual"
     }}, 'renamed_test_file')
     modder.modify({'_file_modify': {'mode': 0o666}}, 'test_file_copy')
     modder.modify({'_file_delete': {'mode': "actual"}}, 'test_file_copy')
     modder.modify({'_file_delete': {'mode': "actual"}}, 'test_file_copy1')
     modder.modify({'_file_delete': {'mode': "actual"}}, 'test_file_copy2')
Esempio n. 24
0
 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)
Esempio n. 25
0
    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])
Esempio n. 26
0
    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}