Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit autoupdate #332

Merged
merged 6 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
rev: v0.4.3
hooks:
- id: ruff
args: [--fix, --ignore, D, --unsafe-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-yaml
exclude: pymatgen/analysis/vesta_cutoffs.yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies: [types-requests]
Expand Down
2 changes: 2 additions & 0 deletions custodian/ansible/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(self, actions=None, strict=True, directory="./") -> None:
mode, unsupported actions are simply ignored without any
errors raised. In strict mode, if an unsupported action is
supplied, a ValueError is raised. Defaults to True.
directory (str): The directory containing the files to be modified.
Defaults to "./".
"""
self.supported_actions = {}
actions = actions if actions is not None else [DictActions]
Expand Down
7 changes: 6 additions & 1 deletion custodian/cp2k/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import re
import time
from typing import ClassVar

import numpy as np
from monty.os.path import zpath
Expand Down Expand Up @@ -56,7 +57,11 @@ class StdErrHandler(ErrorHandler):
is_monitor = True
raises_runtime_error = False

error_msgs = {"seg_fault": ["SIGSEGV"], "out_of_memory": ["insufficient virtual memory"], "abort": ["SIGABRT"]}
error_msgs: ClassVar = {
"seg_fault": ["SIGSEGV"],
"out_of_memory": ["insufficient virtual memory"],
"abort": ["SIGABRT"],
}

def __init__(self, std_err="std_err.txt") -> None:
"""Initialize the handler with the output file to check.
Expand Down
3 changes: 2 additions & 1 deletion custodian/cp2k/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def __init__(self, filename="cp2k.inp", actions=None, strict=True, ci=None, dire
supplied, a ValueError is raised. Defaults to True.
ci (Cp2kInput): A Cp2kInput object from the current directory.
Initialized automatically if not passed (but passing it will
avoid having to reparse the directory).
avoid having to re-parse the directory).
directory (str): The directory containing the Cp2kInput set. Defaults to "./".
"""
self.directory = directory
self.ci = ci or Cp2kInput.from_file(os.path.join(self.directory, filename))
Expand Down
2 changes: 1 addition & 1 deletion custodian/cp2k/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
self.final = final
self.backup = backup
self.suffix = suffix
self.settings_override = settings_override if settings_override else []
self.settings_override = settings_override or []
self.restart = restart

def setup(self, directory="./") -> None:
Expand Down
14 changes: 7 additions & 7 deletions custodian/custodian.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ def __init__(
def _load_checkpoint(directory):
restart = 0
run_log = []
chkpts = glob(os.path.join(directory, "custodian.chk.*.tar.gz"))
if chkpts:
chkpt = sorted(chkpts, key=lambda c: int(c.split(".")[-3]))[0]
restart = int(chkpt.split(".")[-3])
logger.info(f"Loading from checkpoint file {chkpt}...")
with tarfile.open(chkpt) as file:
chk_pts = glob(os.path.join(directory, "custodian.chk.*.tar.gz"))
if chk_pts:
chk_pt = min(chk_pts, key=lambda c: int(c.split(".")[-3]))
restart = int(chk_pt.split(".")[-3])
logger.info(f"Loading from checkpoint file {chk_pt}...")
with tarfile.open(chk_pt) as file:

def is_within_directory(directory, target):
abs_directory = os.path.abspath(directory)
Expand Down Expand Up @@ -381,7 +381,7 @@ def run(self):

try:
# skip jobs until the restart
for job_n, job in islice(enumerate(self.jobs, 1), self.restart, None):
for job_n, job in islice(enumerate(self.jobs, start=1), self.restart, None):
self._run_job(job_n, job)
# We do a dump of the run log after each job.
dumpfn(self.run_log, os.path.join(self.directory, Custodian.LOG_FILE), cls=MontyEncoder, indent=4)
Expand Down
4 changes: 2 additions & 2 deletions custodian/feff/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def __init__(self, actions=None, strict=True, feffinp=None, directory="./") -> N
supplied, a ValueError is raised. Defaults to True.
feffinp (FEFFInput): A FeffInput object from the current directory.
Initialized automatically if not passed (but passing it will
avoid having to reparse the directory).
directory (str): Directory to run in
avoid having to re-parse the directory).
directory (str): The directory containing the FeffInput set. Defaults to "./".
"""
self.directory = directory
self.feffinp = feffinp or FEFFDictSet.from_directory(self.directory)
Expand Down
4 changes: 1 addition & 3 deletions custodian/gaussian/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
This package implements various Gaussian Jobs and Error Handlers.
"""
"""This package implements various Gaussian Jobs and Error Handlers."""

__author__ = "Rasha Atwi"
__version__ = "0.1"
Expand Down
14 changes: 7 additions & 7 deletions custodian/gaussian/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import re
import shutil
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, ClassVar

import numpy as np
from monty.io import zopen
Expand Down Expand Up @@ -47,7 +47,7 @@ class GaussianErrorHandler(ErrorHandler):
"""

# definition of job errors as they appear in Gaussian output file
error_defs = {
error_defs: ClassVar = {
"Optimization stopped": "opt_steps",
"Convergence failure": "scf_convergence",
"FormBX had a problem": "linear_bend",
Expand All @@ -71,15 +71,15 @@ class GaussianErrorHandler(ErrorHandler):
recom_mem_patt = re.compile(
r"Use %mem=([0-9]+)MW to provide the minimum amount of memory required to complete this step."
)
conv_critera = {
conv_criteria: ClassVar = {
"max_force": re.compile(r"\s+(Maximum Force)\s+(-?\d+.?\d*|.*)\s+(-?\d+.?\d*)"),
"rms_force": re.compile(r"\s+(RMS {5}Force)\s+(-?\d+.?\d*|.*)\s+(-?\d+.?\d*)"),
"max_disp": re.compile(r"\s+(Maximum Displacement)\s+(-?\d+.?\d*|.*)\s+(-?\d+.?\d*)"),
"rms_disp": re.compile(r"\s+(RMS {5}Displacement)\s+(-?\d+.?\d*|.*)\s+(-?\d+.?\d*)"),
}

grid_patt = re.compile(r"(-?\d{5})")
GRID_NAMES = [
GRID_NAMES = (
"finegrid",
"fine",
"superfinegrid",
Expand All @@ -90,8 +90,8 @@ class GaussianErrorHandler(ErrorHandler):
"sg1",
"pass0grid",
"pass0",
]
MEM_UNITS = ["kb", "mb", "gb", "tb", "kw", "mw", "gw", "tw"]
)
MEM_UNITS = ("kb", "mb", "gb", "tb", "kw", "mw", "gw", "tw")

activate_better_guess = False

Expand Down Expand Up @@ -504,7 +504,7 @@ def check(self, directory: str = "./") -> bool:
self.recom_mem = GaussianErrorHandler.convert_mem(float(mem), "mw")

if self.check_convergence and "opt" in self.gin.route_parameters:
for k, v in GaussianErrorHandler.conv_critera.items():
for k, v in GaussianErrorHandler.conv_criteria.items():
m = v.search(line)
if m:
if k not in self.conv_data["values"]:
Expand Down
3 changes: 2 additions & 1 deletion custodian/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import tarfile
from glob import glob
from typing import ClassVar


def backup(filenames, prefix="error", directory="./") -> None:
Expand Down Expand Up @@ -60,7 +61,7 @@ class tracked_lru_cache:
Allows Custodian to clear the cache after all the checks have been performed.
"""

cached_functions: set = set()
cached_functions: ClassVar = set()

def __init__(self, func) -> None:
"""
Expand Down
22 changes: 10 additions & 12 deletions custodian/vasp/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import warnings
from collections import Counter
from math import prod
from typing import ClassVar

import numpy as np
from monty.dev import deprecated
Expand Down Expand Up @@ -66,7 +67,7 @@ class VaspErrorHandler(ErrorHandler):

is_monitor = True

error_msgs = {
error_msgs: ClassVar = {
"tet": [
"Tetrahedron method fails",
"tetrahedron method fails",
Expand Down Expand Up @@ -135,20 +136,17 @@ def __init__(
is being redirected. The error messages that are checked are
present in the stdout. Defaults to "vasp.out", which is the
default redirect used by :class:`custodian.vasp.jobs.VaspJob`.
errors_subset_to_detect (list): A subset of errors to catch. The
errors_subset_to_catch (list): A subset of errors to catch. The
default is None, which means all supported errors are detected.
Use this to catch only a subset of supported errors.
E.g., ["eddrmm", "zheev"] will only catch the eddrmm and zheev
errors, and not others. If you wish to only exclude one or
two of the errors, you can create this list by the following
lines:
two of the errors, you can create this list by the following lines:

```
subset = list(VaspErrorHandler().error_msgs)
subset.remove("eddrmm")
subset = list(VaspErrorHandler().error_msgs)
subset.remove("eddrmm")
handler = VaspErrorHandler(errors_subset_to_catch=subset)

handler = VaspErrorHandler(errors_subset_to_catch=subset)
```
vtst_fixes (bool): Whether to consider VTST optimizers. Defaults to
False for compatibility purposes, but if you have VTST, you
would likely benefit from setting this to True.
Expand Down Expand Up @@ -691,7 +689,7 @@ class LrfCommutatorHandler(ErrorHandler):

is_monitor = True

error_msgs = {"lrf_comm": ["LRF_COMMUTATOR internal error"]}
error_msgs: ClassVar = {"lrf_comm": ["LRF_COMMUTATOR internal error"]}

def __init__(self, output_filename: str = "std_err.txt") -> None:
"""Initialize the handler with the output file to check.
Expand Down Expand Up @@ -744,7 +742,7 @@ class StdErrHandler(ErrorHandler):

is_monitor = True

error_msgs = {
error_msgs: ClassVar = {
"kpoints_trans": ["internal error in GENERATE_KPOINTS_TRANS: number of G-vector changed in star"],
"out_of_memory": ["Allocation would exceed memory limit"],
}
Expand Down Expand Up @@ -804,7 +802,7 @@ class AliasingErrorHandler(ErrorHandler):

is_monitor = True

error_msgs = {
error_msgs: ClassVar = {
"aliasing": ["WARNING: small aliasing (wrap around) errors must be expected"],
"aliasing_incar": ["Your FFT grids (NGX,NGY,NGZ) are not sufficient for an accurate"],
}
Expand Down
3 changes: 2 additions & 1 deletion custodian/vasp/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def __init__(self, actions=None, strict=True, vi=None, directory="./") -> None:
supplied, a ValueError is raised. Defaults to True.
vi (VaspInput): A VaspInput object from the current directory.
Initialized automatically if not passed (but passing it will
avoid having to reparse the directory).
avoid having to re-parse the directory).
directory (str): The directory containing the VaspInput set.
"""
self.vi = vi or VaspInput.from_directory(directory)
self.directory = directory
Expand Down
15 changes: 6 additions & 9 deletions custodian/vasp/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def double_relaxation_run(
wall-time handler which will write a read-only STOPCAR to
prevent VASP from deleting it once it finishes. Defaults to
False.
directory (str): Directory where the job was run. Defaults to './'.

Returns:
List of two jobs corresponding to an AFLOW style run.
Expand Down Expand Up @@ -382,12 +383,8 @@ def metagga_opt_run(
metaGGA = incar.get("METAGGA", "SCAN")

# Pre optimize WAVECAR and structure using regular GGA
pre_opt_settings = [
{
"dict": "INCAR",
"action": {"_set": {"METAGGA": None, "LWAVE": True, "NSW": 0}},
}
]
new_settings = {"METAGGA": None, "LWAVE": True, "NSW": 0}
pre_opt_settings = [{"dict": "INCAR", "action": {"_set": new_settings}}]
jobs = [
VaspJob(
vasp_cmd,
Expand Down Expand Up @@ -460,6 +457,7 @@ def full_opt_run(
half_kpts_first_relax (bool): Whether to halve the kpoint grid
for the first relaxation. Speeds up difficult convergence
considerably. Defaults to False.
directory (str): Directory where the job was run. Defaults to './'.
**vasp_job_kwargs: Passthrough kwargs to VaspJob. See
:class:`custodian.vasp.jobs.VaspJob`.

Expand Down Expand Up @@ -558,6 +556,7 @@ def constrained_opt_run(
which is more robust but can be a bit slow. The code does fall
back on the bisection when bfgs gives a nonsensical result,
e.g., negative lattice params.
directory (str): Directory where the job was run. Defaults to './'.
**vasp_job_kwargs: Passthrough kwargs to VaspJob. See
:class:`custodian.vasp.jobs.VaspJob`.

Expand Down Expand Up @@ -807,8 +806,7 @@ def __init__(
self.settings_override = settings_override

def setup(self, directory="./") -> None:
"""
Performs initial setup for VaspNEBJob, including overriding any settings
"""Performs initial setup for VaspNEBJob, including overriding any settings
and backing up.
"""
neb_dirs, neb_sub = self._get_neb_dirs(directory)
Expand All @@ -825,7 +823,6 @@ def setup(self, directory="./") -> None:
if self.half_kpts and os.path.isfile(os.path.join(directory, "KPOINTS")):
kpts = Kpoints.from_file(os.path.join(directory, "KPOINTS"))
kpts.kpts = np.maximum(np.array(kpts.kpts) / 2, 1)
kpts.kpts = kpts.kpts.astype(int).tolist()
if tuple(kpts.kpts[0]) == (1, 1, 1):
kpt_dic = kpts.as_dict()
kpt_dic["generation_style"] = "Gamma"
Expand Down
4 changes: 3 additions & 1 deletion docs/_themes/flask_theme_support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""flasky extensions. flasky pygments style based on tango style."""

from typing import ClassVar

from pygments.style import Style
from pygments.token import (
Comment,
Expand All @@ -23,7 +25,7 @@ class FlaskyStyle(Style):
background_color = "#f8f8f8"
default_style = ""

styles = {
styles: ClassVar = {
# No corresponding class for the following:
# Text: "", # class: ''
Whitespace: "underline #f8f8f8", # class: 'w'
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from custodian import __version__ as CURRENT_VER

NEW_VER = datetime.datetime.today().strftime("%Y.%-m.%-d")
NEW_VER = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y.%-m.%-d")


@task
Expand Down
4 changes: 2 additions & 2 deletions tests/gaussian/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def test_better_guess(self):
self.output_file,
self.stderr_file,
self.backup,
True,
self.directory,
cart_coords=True,
directory=self.directory,
)
jobs = list(job_gen)
assert len(jobs) == 1, "One job should be generated under normal conditions."
Expand Down
Loading