Skip to content

Commit 3da2472

Browse files
move to ruff formatter (#1375)
See https://astral.sh/blog/the-ruff-formatter. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d58530b commit 3da2472

File tree

9 files changed

+71
-72
lines changed

9 files changed

+71
-72
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ repos:
2727
exclude: "^examples/CH4-lebesgue/.*$"
2828

2929
# Python
30-
- repo: https://github.com/psf/black
31-
rev: 23.10.1
32-
hooks:
33-
- id: black-jupyter
3430
- repo: https://github.com/astral-sh/ruff-pre-commit
3531
rev: v0.1.3
3632
hooks:
3733
- id: ruff
3834
args: ["--fix"]
35+
- id: ruff-format
3936
# numpydoc
4037
- repo: https://github.com/Carreau/velin
4138
rev: 0.0.12

dpgen/auto_test/lib/lammps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ def make_lammps_eval(conf, type_map, interaction, param):
189189
ret += (
190190
"thermo_style custom step pe pxx pyy pzz pxy pxz pyz lx ly lz vol c_mype\n"
191191
)
192-
ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n" # 06/09 give dump.relax
192+
ret += (
193+
"dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n"
194+
) # 06/09 give dump.relax
193195
ret += "run 0\n"
194196
ret += "variable N equal count(all)\n"
195197
ret += "variable V equal vol\n"
@@ -352,9 +354,7 @@ def make_lammps_press_relax(
352354
ret += "variable bp equal %f\n" % bp
353355
ret += "variable xx equal %f\n" % scale2equi
354356
ret += "variable yeta equal 1.5*(${bp}-1)\n"
355-
ret += (
356-
"variable Px0 equal 3*${B0}*(1-${xx})/${xx}^2*exp(${yeta}*(1-${xx}))\n"
357-
)
357+
ret += "variable Px0 equal 3*${B0}*(1-${xx})/${xx}^2*exp(${yeta}*(1-${xx}))\n"
358358
ret += "variable Px equal ${Px0}*${GPa2bar}\n"
359359
ret += "units metal\n"
360360
ret += "dimension 3\n"

dpgen/generator/lib/abacus_scf.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ def make_abacus_scf_input(fp_params, extra_file_path=""):
4545
fp_params["kspacing"] = [
4646
float(i) for i in fp_params["kspacing"].split()
4747
]
48-
assert len(fp_params["kspacing"]) in [
49-
1,
50-
3,
51-
], "'kspacing' only accept a float, or a list of one or three float, or a string of one or three float"
48+
assert (
49+
len(fp_params["kspacing"])
50+
in [
51+
1,
52+
3,
53+
]
54+
), "'kspacing' only accept a float, or a list of one or three float, or a string of one or three float"
5255
ret += "kspacing "
5356
for ikspacing in fp_params["kspacing"]:
5457
assert ikspacing >= 0, "'kspacing' should be non-negative."
@@ -116,25 +119,31 @@ def make_abacus_scf_input(fp_params, extra_file_path=""):
116119
), "'nspin' can anly take 1, 2 or 4"
117120
ret += "nspin %d\n" % fp_params["nspin"]
118121
elif key == "ks_solver":
119-
assert fp_params["ks_solver"] in [
120-
"cg",
121-
"dav",
122-
"lapack",
123-
"genelpa",
124-
"hpseps",
125-
"scalapack_gvx",
126-
], "'ks_sover' should in 'cgx', 'dav', 'lapack', 'genelpa', 'hpseps', 'scalapack_gvx'."
122+
assert (
123+
fp_params["ks_solver"]
124+
in [
125+
"cg",
126+
"dav",
127+
"lapack",
128+
"genelpa",
129+
"hpseps",
130+
"scalapack_gvx",
131+
]
132+
), "'ks_sover' should in 'cgx', 'dav', 'lapack', 'genelpa', 'hpseps', 'scalapack_gvx'."
127133
ret += "ks_solver %s\n" % fp_params["ks_solver"]
128134
elif key == "smearing_method":
129-
assert fp_params["smearing_method"] in [
130-
"gauss",
131-
"gaussian",
132-
"fd",
133-
"fixed",
134-
"mp",
135-
"mp2",
136-
"mv",
137-
], "'smearing_method' should in 'gauss', 'gaussian', 'fd', 'fixed', 'mp', 'mp2', 'mv'. "
135+
assert (
136+
fp_params["smearing_method"]
137+
in [
138+
"gauss",
139+
"gaussian",
140+
"fd",
141+
"fixed",
142+
"mp",
143+
"mp2",
144+
"mv",
145+
]
146+
), "'smearing_method' should in 'gauss', 'gaussian', 'fd', 'fixed', 'mp', 'mp2', 'mv'. "
138147
ret += "smearing_method %s\n" % fp_params["smearing_method"]
139148
elif key == "smearing_sigma":
140149
fp_params["smearing_sigma"] = float(fp_params["smearing_sigma"])

dpgen/generator/lib/calypso_run_opt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ def read_stress_fmax():
9494
try:
9595
f = open("input.dat")
9696
except Exception:
97-
assert os.path.exists(
98-
"../input.dat"
99-
), " now we are in %s, do not find ../input.dat" % (os.getcwd())
97+
assert os.path.exists("../input.dat"), (
98+
" now we are in %s, do not find ../input.dat" % (os.getcwd())
99+
)
100100
f = open("../input.dat")
101101
lines = f.readlines()
102102
f.close()

dpgen/generator/run.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -493,24 +493,26 @@ def make_train(iter_index, jdata, mdata):
493493
):
494494
jinput["training"]["stop_batch"] = training_reuse_stop_batch
495495
if Version("1") <= Version(mdata["deepmd_version"]) < Version("2"):
496-
jinput["training"][
497-
"auto_prob_style"
498-
] = "prob_sys_size; 0:%d:%f; %d:%d:%f" % (
499-
old_range,
500-
training_reuse_old_ratio,
501-
old_range,
502-
len(init_data_sys),
503-
1.0 - training_reuse_old_ratio,
496+
jinput["training"]["auto_prob_style"] = (
497+
"prob_sys_size; 0:%d:%f; %d:%d:%f"
498+
% (
499+
old_range,
500+
training_reuse_old_ratio,
501+
old_range,
502+
len(init_data_sys),
503+
1.0 - training_reuse_old_ratio,
504+
)
504505
)
505506
elif Version("2") <= Version(mdata["deepmd_version"]) < Version("3"):
506-
jinput["training"]["training_data"][
507-
"auto_prob"
508-
] = "prob_sys_size; 0:%d:%f; %d:%d:%f" % (
509-
old_range,
510-
training_reuse_old_ratio,
511-
old_range,
512-
len(init_data_sys),
513-
1.0 - training_reuse_old_ratio,
507+
jinput["training"]["training_data"]["auto_prob"] = (
508+
"prob_sys_size; 0:%d:%f; %d:%d:%f"
509+
% (
510+
old_range,
511+
training_reuse_old_ratio,
512+
old_range,
513+
len(init_data_sys),
514+
1.0 - training_reuse_old_ratio,
515+
)
514516
)
515517
else:
516518
raise RuntimeError(
@@ -1003,11 +1005,12 @@ def revise_lmp_input_model(lmp_lines, task_model_list, trj_freq, deepmd_version=
10031005
trj_freq,
10041006
)
10051007
else:
1006-
lmp_lines[
1007-
idx
1008-
] = "pair_style deepmd %s out_freq %d out_file model_devi.out\n" % (
1009-
graph_list,
1010-
trj_freq,
1008+
lmp_lines[idx] = (
1009+
"pair_style deepmd %s out_freq %d out_file model_devi.out\n"
1010+
% (
1011+
graph_list,
1012+
trj_freq,
1013+
)
10111014
)
10121015
return lmp_lines
10131016

dpgen/tools/auto_gen_param.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ def get_system_list(
149149
map_list=map_list, data_list=data_list
150150
)
151151
else:
152-
origin_one, new_map_iterator = tee(
153-
map_iterator
154-
) # pylint: disable=unused-variable
152+
origin_one, new_map_iterator = tee(map_iterator) # pylint: disable=unused-variable
155153
# tee means copy;new_map_generator will become a copy of map_iterator
156154
system = System(system_prefix)
157155
for idx2 in range(sub_iteration_num):

dpgen/tools/stat_iter.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ def stat_iter(target_folder, param_file="param.json", verbose=True, mute=False):
2626
num, relative_path_doc = line.strip().split(" ")
2727
path_doc = os.path.abspath(relative_path_doc)
2828
num = int(num)
29-
prefix, iter_dirname, stage, out_filename = path_doc.rsplit(
30-
"/", 3
31-
) # pylint: disable=unused-variable
29+
prefix, iter_dirname, stage, out_filename = path_doc.rsplit("/", 3) # pylint: disable=unused-variable
3230
pk_id, out_filename = path_doc.rsplit("/", 1)
3331
iter = int(iter_dirname.split(".")[-1]) # pylint: disable=unused-variable
34-
out_id = int(
35-
out_filename.strip().split(".")[-2]
36-
) # pylint: disable=unused-variable
32+
out_id = int(out_filename.strip().split(".")[-2]) # pylint: disable=unused-variable
3733
out_type = out_filename.strip().split(".")[0]
3834
iter_dict[pk_id][out_type] += num
3935
# for ii in
@@ -52,9 +48,7 @@ def stat_iter(target_folder, param_file="param.json", verbose=True, mute=False):
5248
if line:
5349
# [/home/felix/workplace/SiC/iter.000002/02.fp/task.018.000040/OUTCAR]
5450
path_doc = os.path.abspath(line)
55-
pk_id, task_dirname, OUTCAR_filename = path_doc.rsplit(
56-
"/", 2
57-
) # pylint: disable=unused-variable
51+
pk_id, task_dirname, OUTCAR_filename = path_doc.rsplit("/", 2) # pylint: disable=unused-variable
5852
try:
5953
_sys = dpdata.LabeledSystem(path_doc, type_map=jdata["type_map"])
6054
except Exception:

dpgen/tools/stat_time.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ def stat_time(target_folder, param_file="param.json", verbose=True, mute=False):
5151
# log example :
5252
# .//iter.000000/00.train//003/train.log:# DEEPMD: wall time: 7960.265 s
5353
# print(log.split(':'))
54-
file_path, text1, text2, wall_time = log.split(
55-
":"
56-
) # pylint: disable=unused-variable
54+
file_path, text1, text2, wall_time = log.split(":") # pylint: disable=unused-variable
5755
abs_file_path = os.path.abspath(file_path)
5856
# stage=='00.train'
5957

@@ -122,9 +120,7 @@ def stat_time(target_folder, param_file="param.json", verbose=True, mute=False):
122120
# log example:
123121
# .//iter.000002/01.model_devi//task.018.000075/log.lammps:Total wall time: 0:00:39
124122
# print(log)
125-
file_path, text1, hour, min, sec = log.split(
126-
":"
127-
) # pylint: disable=unused-variable
123+
file_path, text1, hour, min, sec = log.split(":") # pylint: disable=unused-variable
128124
abs_file_path = os.path.abspath(file_path)
129125
wall_time_sec = 3600 * int(hour) + 60 * int(min) + 1 * int(sec)
130126
total_core_sec += wall_time_sec * paral_cores

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ write_to = "dpgen/_version.py"
8080
profile = "black"
8181

8282
[tool.ruff]
83-
target-version = "py39"
8483
select = [
8584
"I", # isort
8685
"E", # errors
@@ -109,3 +108,6 @@ ignore = [
109108
"D404", # TODO: first word of the docstring should not be This
110109
]
111110
ignore-init-module-imports = true
111+
112+
[tool.ruff.pydocstyle]
113+
convention = "numpy"

0 commit comments

Comments
 (0)