From 7fbf27e15689148246da06e16eb6c572c49576ef Mon Sep 17 00:00:00 2001 From: Guido Petretto Date: Wed, 19 Jul 2023 22:03:52 +0200 Subject: [PATCH 1/5] caching parsed output files --- custodian/custodian.py | 4 ++- custodian/utils.py | 32 +++++++++++++++++++++++- custodian/vasp/handlers.py | 29 +++++++++++---------- custodian/vasp/io.py | 36 +++++++++++++++++++++++++++ custodian/vasp/tests/conftest.py | 10 ++++++++ custodian/vasp/tests/test_handlers.py | 6 +++++ custodian/vasp/validators.py | 7 +++--- 7 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 custodian/vasp/io.py diff --git a/custodian/custodian.py b/custodian/custodian.py index 42a6496fa..437f8d10e 100644 --- a/custodian/custodian.py +++ b/custodian/custodian.py @@ -22,7 +22,7 @@ from monty.shutil import gzip_dir from monty.tempfile import ScratchDir -from .utils import get_execution_host_info +from .utils import get_execution_host_info, tracked_lru_cache __author__ = "Shyue Ping Ong, William Davidson Richards" __copyright__ = "Copyright 2012, The Materials Project" @@ -683,6 +683,8 @@ def _do_check(self, handlers, terminate_func=None): self.run_log[-1]["corrections"].extend(corrections) # We do a dump of the run log after each check. dumpfn(self.run_log, Custodian.LOG_FILE, cls=MontyEncoder, indent=4) + # Clear all the cached values to avoid reusing them in a subsequent check + tracked_lru_cache.cache_clear() return len(corrections) > 0 diff --git a/custodian/utils.py b/custodian/utils.py index 489631dde..355b31460 100644 --- a/custodian/utils.py +++ b/custodian/utils.py @@ -1,7 +1,7 @@ """ Utility function and classes. """ - +import functools import logging import os import tarfile @@ -46,3 +46,33 @@ def get_execution_host_info(): except Exception: pass return host or "unknown", cluster or "unknown" + + +class tracked_lru_cache: + """ + Decorator wrapping the functools.lru_cache adding a tracking of the + functions that have been wrapped. + + Exposes a method to clear the cache of all the wrapped functions. + + Used to cache the parsed outputs in handlers/validators, to avoid + multiple parsing of the same file. + Allows Custodian to clear the cache after all the checks have been performed. + """ + + cached_functions: set = set() + + def __init__(self, func): + self.func = functools.lru_cache(func) + functools.update_wrapper(self, func) + + def __call__(self, *args, **kwargs): + result = self.func(*args, **kwargs) + self.cached_functions.add(self.func) + return result + + @classmethod + def cache_clear(cls): + while cls.cached_functions: + f = cls.cached_functions.pop() + f.cache_clear() diff --git a/custodian/vasp/handlers.py b/custodian/vasp/handlers.py index 51bdce957..753c7773e 100644 --- a/custodian/vasp/handlers.py +++ b/custodian/vasp/handlers.py @@ -21,7 +21,7 @@ from monty.serialization import loadfn from pymatgen.core.structure import Structure from pymatgen.io.vasp.inputs import Incar, Kpoints, Poscar, VaspInput -from pymatgen.io.vasp.outputs import Oszicar, Outcar, Vasprun +from pymatgen.io.vasp.outputs import Oszicar from pymatgen.io.vasp.sets import MPScanRelaxSet from pymatgen.transformations.standard_transformations import SupercellTransformation @@ -30,6 +30,7 @@ from custodian.custodian import ErrorHandler from custodian.utils import backup from custodian.vasp.interpreter import VaspModder +from custodian.vasp.io import load_outcar, load_vasprun __author__ = "Shyue Ping Ong, William Davidson Richards, Anubhav Jain, Wei Chen, Stephen Dacek, Andrew Rosen" __version__ = "0.1" @@ -202,7 +203,7 @@ def correct(self): # error count to 1 to skip first fix if self.error_count["brmix"] == 0: try: - assert Outcar(zpath(os.path.join(os.getcwd(), "OUTCAR"))).is_stopped is False + assert load_outcar(zpath(os.path.join(os.getcwd(), "OUTCAR"))).is_stopped is False except Exception: self.error_count["brmix"] += 1 @@ -502,7 +503,7 @@ def correct(self): # resources, seems to be to just increase NCORE slightly. That's what I do here. nprocs = multiprocessing.cpu_count() try: - nelect = Outcar("OUTCAR").nelect + nelect = load_outcar("OUTCAR").nelect except Exception: nelect = 1 # dummy value if nelect < nprocs: @@ -669,7 +670,9 @@ def correct(self): vi = VaspInput.from_directory(".") if "lrf_comm" in self.errors: - if Outcar(zpath(os.path.join(os.getcwd(), "OUTCAR"))).is_stopped is False and not vi["INCAR"].get("LPEAD"): + if load_outcar(zpath(os.path.join(os.getcwd(), "OUTCAR"))).is_stopped is False and not vi["INCAR"].get( + "LPEAD" + ): actions.append({"dict": "INCAR", "action": {"_set": {"LPEAD": True}}}) VaspModder(vi=vi).apply_actions(actions) @@ -882,7 +885,7 @@ def check(self): self.max_drift = incar["EDIFFG"] * -1 try: - outcar = Outcar("OUTCAR") + outcar = load_outcar("OUTCAR") except Exception: # Can't perform check if Outcar not valid return False @@ -904,7 +907,7 @@ def correct(self): vi = VaspInput.from_directory(".") incar = vi["INCAR"] - outcar = Outcar("OUTCAR") + outcar = load_outcar("OUTCAR") # Move CONTCAR to POSCAR actions.append({"file": "CONTCAR", "action": {"_file_copy": {"dest": "POSCAR"}}}) @@ -978,7 +981,7 @@ def check(self): return False try: - v = Vasprun(self.output_vasprun) + v = load_vasprun(self.output_vasprun) if v.converged: return False except Exception: @@ -1027,7 +1030,7 @@ def check(self): Check for error. """ try: - v = Vasprun(self.output_filename) + v = load_vasprun(self.output_filename) if not v.converged: return True except Exception: @@ -1038,7 +1041,7 @@ def correct(self): """ Perform corrections. """ - v = Vasprun(self.output_filename) + v = load_vasprun(self.output_filename) algo = v.incar.get("ALGO", "Normal").lower() actions = [] if not v.converged_electronic: @@ -1148,7 +1151,7 @@ def check(self): Check for error. """ try: - v = Vasprun(self.output_filename) + v = load_vasprun(self.output_filename) # check whether bandgap is zero, tetrahedron smearing was used # and relaxation is performed. if v.eigenvalue_band_properties[0] == 0 and v.incar.get("ISMEAR", 1) < -3 and v.incar.get("NSW", 0) > 1: @@ -1197,7 +1200,7 @@ def check(self): Check for error. """ try: - v = Vasprun(self.output_filename) + v = load_vasprun(self.output_filename) # check whether bandgap is zero and tetrahedron smearing was used if v.eigenvalue_band_properties[0] == 0 and v.incar.get("KSPACING", 1) > 0.22: return True @@ -1246,7 +1249,7 @@ def check(self): """ incar = Incar.from_file("INCAR") try: - outcar = Outcar("OUTCAR") + outcar = load_outcar("OUTCAR") except Exception: # Can't perform check if Outcar not valid return False @@ -1613,7 +1616,7 @@ def check(self): if self.wall_time: run_time = datetime.datetime.now() - self.start_time total_secs = run_time.total_seconds() - outcar = Outcar("OUTCAR") + outcar = load_outcar("OUTCAR") if not self.electronic_step_stop: # Determine max time per ionic step. outcar.read_pattern({"timings": r"LOOP\+.+real time(.+)"}, postprocess=float) diff --git a/custodian/vasp/io.py b/custodian/vasp/io.py new file mode 100644 index 000000000..4104bd44a --- /dev/null +++ b/custodian/vasp/io.py @@ -0,0 +1,36 @@ +from pymatgen.io.vasp.outputs import Outcar, Vasprun + +from custodian.utils import tracked_lru_cache + + +@tracked_lru_cache +def load_vasprun(filepath, **vasprun_kwargs): + """ + Load Vasprun object from file path. + Caches the output for reuse. + + Args: + filepath: path to the vasprun.xml file. + **vasprun_kwargs: kwargs arguments passed to the Vasprun init. + + Returns: + The Vasprun object + """ + vr = Vasprun(filepath, **vasprun_kwargs) + return vr + + +@tracked_lru_cache +def load_outcar(filepath): + """ + Load Outcar object from file path. + Caches the output for reuse. + + Args: + filepath: path to the OUTCAR file. + + Returns: + The Vasprun object + """ + o = Outcar(filepath) + return o diff --git a/custodian/vasp/tests/conftest.py b/custodian/vasp/tests/conftest.py index f53120efc..9078857e4 100644 --- a/custodian/vasp/tests/conftest.py +++ b/custodian/vasp/tests/conftest.py @@ -21,3 +21,13 @@ def patch_get_potential_energy(monkeypatch): Monkeypatch the multiprocessing.cpu_count() function """ monkeypatch.setattr(multiprocessing, "cpu_count", mock_cpu_count) + + +@pytest.fixture(autouse=True) +def clear_tracked_cache(): + """ + Clear the cache of the stored functions between the tests. + """ + from custodian.utils import tracked_lru_cache + + tracked_lru_cache.cache_clear() diff --git a/custodian/vasp/tests/test_handlers.py b/custodian/vasp/tests/test_handlers.py index f88c23c1d..51c7911f1 100644 --- a/custodian/vasp/tests/test_handlers.py +++ b/custodian/vasp/tests/test_handlers.py @@ -17,6 +17,7 @@ from pymatgen.io.vasp.inputs import Incar, Kpoints, Structure, VaspInput +from custodian.utils import tracked_lru_cache from custodian.vasp.handlers import ( AliasingErrorHandler, DriftErrorHandler, @@ -651,6 +652,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") + tracked_lru_cache.cache_clear() shutil.copy("vasprun.xml.electronic_veryfast", "vasprun.xml") h = UnconvergedErrorHandler() @@ -665,6 +667,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") + tracked_lru_cache.cache_clear() shutil.copy("vasprun.xml.electronic_normal", "vasprun.xml") h = UnconvergedErrorHandler() @@ -679,6 +682,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") + tracked_lru_cache.cache_clear() shutil.copy("vasprun.xml.electronic_metagga_fast", "vasprun.xml") h = UnconvergedErrorHandler() @@ -693,6 +697,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") + tracked_lru_cache.cache_clear() shutil.copy("vasprun.xml.electronic_hybrid_fast", "vasprun.xml") h = UnconvergedErrorHandler() @@ -707,6 +712,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") + tracked_lru_cache.cache_clear() shutil.copy("vasprun.xml.electronic_hybrid_all", "vasprun.xml") h = UnconvergedErrorHandler() diff --git a/custodian/vasp/validators.py b/custodian/vasp/validators.py index 2c5fa6ddf..f9aa70093 100644 --- a/custodian/vasp/validators.py +++ b/custodian/vasp/validators.py @@ -6,9 +6,10 @@ import os from collections import deque -from pymatgen.io.vasp import Chgcar, Incar, Outcar, Vasprun +from pymatgen.io.vasp import Chgcar, Incar from custodian.custodian import Validator +from custodian.vasp.io import load_outcar, load_vasprun class VasprunXMLValidator(Validator): @@ -33,7 +34,7 @@ def check(self): Check for error. """ try: - Vasprun("vasprun.xml") + load_vasprun("vasprun.xml") except Exception: exception_context = {} @@ -105,7 +106,7 @@ def check(self): if not is_npt: return False - outcar = Outcar("OUTCAR") + outcar = load_outcar("OUTCAR") patterns = {"MDALGO": r"MDALGO\s+=\s+([\d]+)"} outcar.read_pattern(patterns=patterns) if outcar.data["MDALGO"] == [["3"]]: From 856e65064c0a9ed6fd20369220734ebea8f6812e Mon Sep 17 00:00:00 2001 From: Guido Petretto Date: Thu, 20 Jul 2023 09:12:19 +0200 Subject: [PATCH 2/5] switch to absolute paths --- custodian/utils.py | 10 ++++++++++ custodian/vasp/handlers.py | 20 ++++++++++---------- custodian/vasp/io.py | 4 ++++ custodian/vasp/validators.py | 4 ++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/custodian/utils.py b/custodian/utils.py index 355b31460..3a875f7e2 100644 --- a/custodian/utils.py +++ b/custodian/utils.py @@ -63,16 +63,26 @@ class tracked_lru_cache: cached_functions: set = set() def __init__(self, func): + """ + Args: + func: function to be decorated + """ self.func = functools.lru_cache(func) functools.update_wrapper(self, func) def __call__(self, *args, **kwargs): + """ + Call the decorated function + """ result = self.func(*args, **kwargs) self.cached_functions.add(self.func) return result @classmethod def cache_clear(cls): + """ + Clear the cache of all the decorated functions. + """ while cls.cached_functions: f = cls.cached_functions.pop() f.cache_clear() diff --git a/custodian/vasp/handlers.py b/custodian/vasp/handlers.py index 753c7773e..97915cbf8 100644 --- a/custodian/vasp/handlers.py +++ b/custodian/vasp/handlers.py @@ -503,7 +503,7 @@ def correct(self): # resources, seems to be to just increase NCORE slightly. That's what I do here. nprocs = multiprocessing.cpu_count() try: - nelect = load_outcar("OUTCAR").nelect + nelect = load_outcar(os.path.join(os.getcwd(), "OUTCAR")).nelect except Exception: nelect = 1 # dummy value if nelect < nprocs: @@ -885,7 +885,7 @@ def check(self): self.max_drift = incar["EDIFFG"] * -1 try: - outcar = load_outcar("OUTCAR") + outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR")) except Exception: # Can't perform check if Outcar not valid return False @@ -907,7 +907,7 @@ def correct(self): vi = VaspInput.from_directory(".") incar = vi["INCAR"] - outcar = load_outcar("OUTCAR") + outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR")) # Move CONTCAR to POSCAR actions.append({"file": "CONTCAR", "action": {"_file_copy": {"dest": "POSCAR"}}}) @@ -981,7 +981,7 @@ def check(self): return False try: - v = load_vasprun(self.output_vasprun) + v = load_vasprun(os.path.join(os.getcwd(), self.output_vasprun)) if v.converged: return False except Exception: @@ -1030,7 +1030,7 @@ def check(self): Check for error. """ try: - v = load_vasprun(self.output_filename) + v = load_vasprun(os.path.join(os.getcwd(), self.output_filename)) if not v.converged: return True except Exception: @@ -1041,7 +1041,7 @@ def correct(self): """ Perform corrections. """ - v = load_vasprun(self.output_filename) + v = load_vasprun(os.path.join(os.getcwd(), self.output_filename)) algo = v.incar.get("ALGO", "Normal").lower() actions = [] if not v.converged_electronic: @@ -1151,7 +1151,7 @@ def check(self): Check for error. """ try: - v = load_vasprun(self.output_filename) + v = load_vasprun(os.path.join(os.getcwd(), self.output_filename)) # check whether bandgap is zero, tetrahedron smearing was used # and relaxation is performed. if v.eigenvalue_band_properties[0] == 0 and v.incar.get("ISMEAR", 1) < -3 and v.incar.get("NSW", 0) > 1: @@ -1200,7 +1200,7 @@ def check(self): Check for error. """ try: - v = load_vasprun(self.output_filename) + v = load_vasprun(os.path.join(os.getcwd(), self.output_filename)) # check whether bandgap is zero and tetrahedron smearing was used if v.eigenvalue_band_properties[0] == 0 and v.incar.get("KSPACING", 1) > 0.22: return True @@ -1249,7 +1249,7 @@ def check(self): """ incar = Incar.from_file("INCAR") try: - outcar = load_outcar("OUTCAR") + outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR")) except Exception: # Can't perform check if Outcar not valid return False @@ -1616,7 +1616,7 @@ def check(self): if self.wall_time: run_time = datetime.datetime.now() - self.start_time total_secs = run_time.total_seconds() - outcar = load_outcar("OUTCAR") + outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR")) if not self.electronic_step_stop: # Determine max time per ionic step. outcar.read_pattern({"timings": r"LOOP\+.+real time(.+)"}, postprocess=float) diff --git a/custodian/vasp/io.py b/custodian/vasp/io.py index 4104bd44a..f0b4c048f 100644 --- a/custodian/vasp/io.py +++ b/custodian/vasp/io.py @@ -1,3 +1,7 @@ +""" +Helper functions for dealing with vasp files. +""" + from pymatgen.io.vasp.outputs import Outcar, Vasprun from custodian.utils import tracked_lru_cache diff --git a/custodian/vasp/validators.py b/custodian/vasp/validators.py index f9aa70093..645b1b841 100644 --- a/custodian/vasp/validators.py +++ b/custodian/vasp/validators.py @@ -34,7 +34,7 @@ def check(self): Check for error. """ try: - load_vasprun("vasprun.xml") + load_vasprun(os.path.join(os.getcwd(), "vasprun.xml")) except Exception: exception_context = {} @@ -106,7 +106,7 @@ def check(self): if not is_npt: return False - outcar = load_outcar("OUTCAR") + outcar = load_outcar(os.path.join(os.getcwd(), "OUTCAR")) patterns = {"MDALGO": r"MDALGO\s+=\s+([\d]+)"} outcar.read_pattern(patterns=patterns) if outcar.data["MDALGO"] == [["3"]]: From 58aca7f9a039eafdb80026159e6cdf81f8522c05 Mon Sep 17 00:00:00 2001 From: Guido Petretto Date: Fri, 21 Jul 2023 12:01:12 +0200 Subject: [PATCH 3/5] add tests for caching --- custodian/tests/test_utils.py | 38 +++++++++++++++++++++++++++++++++ custodian/utils.py | 4 ++++ custodian/vasp/tests/test_io.py | 27 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 custodian/tests/test_utils.py create mode 100644 custodian/vasp/tests/test_io.py diff --git a/custodian/tests/test_utils.py b/custodian/tests/test_utils.py new file mode 100644 index 000000000..cdfe2ca5b --- /dev/null +++ b/custodian/tests/test_utils.py @@ -0,0 +1,38 @@ +import unittest + +from custodian.utils import tracked_lru_cache + + +class TrackedLruCacheTest(unittest.TestCase): + def setUp(self): + # clear cache before and after each test to avoid + # unexpected caching from other tests + tracked_lru_cache.cache_clear() + + def test_cache_and_clear(self): + n_calls = 0 + + @tracked_lru_cache + def some_func(x): + nonlocal n_calls + n_calls += 1 + return x + + assert some_func(1) == 1 + assert n_calls == 1 + assert some_func(2) == 2 + assert n_calls == 2 + assert some_func(1) == 1 + assert n_calls == 2 + + assert len(tracked_lru_cache.cached_functions) == 1 + + tracked_lru_cache.cache_clear() + + assert len(tracked_lru_cache.cached_functions) == 0 + + assert some_func(1) == 1 + assert n_calls == 3 + + def tearDown(self): + tracked_lru_cache.cache_clear() diff --git a/custodian/utils.py b/custodian/utils.py index 3a875f7e2..3110c6d13 100644 --- a/custodian/utils.py +++ b/custodian/utils.py @@ -70,6 +70,10 @@ def __init__(self, func): self.func = functools.lru_cache(func) functools.update_wrapper(self, func) + # expose standard lru_cache functions + self.cache_info = self.func.cache_info + self.cache_clear = self.func.cache_clear + def __call__(self, *args, **kwargs): """ Call the decorated function diff --git a/custodian/vasp/tests/test_io.py b/custodian/vasp/tests/test_io.py new file mode 100644 index 000000000..41098cf8f --- /dev/null +++ b/custodian/vasp/tests/test_io.py @@ -0,0 +1,27 @@ +import os +import unittest + +from custodian.utils import tracked_lru_cache +from custodian.vasp.io import load_outcar, load_vasprun + +test_dir = os.path.join(os.path.dirname(__file__), "..", "..", "..", "test_files") + + +class IOTest(unittest.TestCase): + def test_load_outcar(self): + outcar = load_outcar(os.path.join(test_dir, "large_sigma", "OUTCAR")) + assert outcar is not None + outcar2 = load_outcar(os.path.join(test_dir, "large_sigma", "OUTCAR")) + + assert outcar is outcar2 + + assert len(tracked_lru_cache.cached_functions) == 1 + + def test_load_vasprun(self): + vr = load_vasprun(os.path.join(test_dir, "large_sigma", "vasprun.xml")) + assert vr is not None + vr2 = load_vasprun(os.path.join(test_dir, "large_sigma", "vasprun.xml")) + + assert vr is vr2 + + assert len(tracked_lru_cache.cached_functions) == 1 From 9335f94c0c755bce069e06c9c17864a6c393a2d2 Mon Sep 17 00:00:00 2001 From: Guido Petretto Date: Fri, 21 Jul 2023 12:27:54 +0200 Subject: [PATCH 4/5] rename cache clearing method to avoid clashes --- custodian/custodian.py | 2 +- custodian/tests/test_utils.py | 6 +++--- custodian/utils.py | 2 +- custodian/vasp/tests/conftest.py | 2 +- custodian/vasp/tests/test_handlers.py | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/custodian/custodian.py b/custodian/custodian.py index 437f8d10e..6a3b48823 100644 --- a/custodian/custodian.py +++ b/custodian/custodian.py @@ -684,7 +684,7 @@ def _do_check(self, handlers, terminate_func=None): # We do a dump of the run log after each check. dumpfn(self.run_log, Custodian.LOG_FILE, cls=MontyEncoder, indent=4) # Clear all the cached values to avoid reusing them in a subsequent check - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() return len(corrections) > 0 diff --git a/custodian/tests/test_utils.py b/custodian/tests/test_utils.py index cdfe2ca5b..e7fc4de84 100644 --- a/custodian/tests/test_utils.py +++ b/custodian/tests/test_utils.py @@ -7,7 +7,7 @@ class TrackedLruCacheTest(unittest.TestCase): def setUp(self): # clear cache before and after each test to avoid # unexpected caching from other tests - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() def test_cache_and_clear(self): n_calls = 0 @@ -27,7 +27,7 @@ def some_func(x): assert len(tracked_lru_cache.cached_functions) == 1 - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() assert len(tracked_lru_cache.cached_functions) == 0 @@ -35,4 +35,4 @@ def some_func(x): assert n_calls == 3 def tearDown(self): - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() diff --git a/custodian/utils.py b/custodian/utils.py index 3110c6d13..bed379a28 100644 --- a/custodian/utils.py +++ b/custodian/utils.py @@ -83,7 +83,7 @@ def __call__(self, *args, **kwargs): return result @classmethod - def cache_clear(cls): + def tracked_cache_clear(cls): """ Clear the cache of all the decorated functions. """ diff --git a/custodian/vasp/tests/conftest.py b/custodian/vasp/tests/conftest.py index 9078857e4..92030961a 100644 --- a/custodian/vasp/tests/conftest.py +++ b/custodian/vasp/tests/conftest.py @@ -30,4 +30,4 @@ def clear_tracked_cache(): """ from custodian.utils import tracked_lru_cache - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() diff --git a/custodian/vasp/tests/test_handlers.py b/custodian/vasp/tests/test_handlers.py index 51c7911f1..a43d44e0c 100644 --- a/custodian/vasp/tests/test_handlers.py +++ b/custodian/vasp/tests/test_handlers.py @@ -652,7 +652,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() shutil.copy("vasprun.xml.electronic_veryfast", "vasprun.xml") h = UnconvergedErrorHandler() @@ -667,7 +667,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() shutil.copy("vasprun.xml.electronic_normal", "vasprun.xml") h = UnconvergedErrorHandler() @@ -682,7 +682,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() shutil.copy("vasprun.xml.electronic_metagga_fast", "vasprun.xml") h = UnconvergedErrorHandler() @@ -697,7 +697,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() shutil.copy("vasprun.xml.electronic_hybrid_fast", "vasprun.xml") h = UnconvergedErrorHandler() @@ -712,7 +712,7 @@ def test_check_correct_electronic(self): }, ) os.remove("vasprun.xml") - tracked_lru_cache.cache_clear() + tracked_lru_cache.tracked_cache_clear() shutil.copy("vasprun.xml.electronic_hybrid_all", "vasprun.xml") h = UnconvergedErrorHandler() From de7bd4745b6ee8134fc2b0419b61586f5a83de37 Mon Sep 17 00:00:00 2001 From: Guido Petretto Date: Mon, 6 Nov 2023 15:02:47 +0100 Subject: [PATCH 5/5] fix lint --- custodian/vasp/io.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/custodian/vasp/io.py b/custodian/vasp/io.py index f0b4c048f..9b954936e 100644 --- a/custodian/vasp/io.py +++ b/custodian/vasp/io.py @@ -20,8 +20,7 @@ def load_vasprun(filepath, **vasprun_kwargs): Returns: The Vasprun object """ - vr = Vasprun(filepath, **vasprun_kwargs) - return vr + return Vasprun(filepath, **vasprun_kwargs) @tracked_lru_cache @@ -36,5 +35,4 @@ def load_outcar(filepath): Returns: The Vasprun object """ - o = Outcar(filepath) - return o + return Outcar(filepath)