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

Fix: ignore UP031 #1683

Merged
merged 7 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:

# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.8.1
hooks:
- id: ruff
args: ["--fix"]
Expand Down
6 changes: 3 additions & 3 deletions dpgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
]:
try:
mm = __import__(modui)
print("%10s %10s %s" % (modui, mm.__version__, mm.__path__[0]))
print("%10s %10s %s" % (modui, mm.__version__, mm.__path__[0])) # noqa: UP031

Check warning on line 51 in dpgen/__init__.py

View check run for this annotation

Codecov / codecov/patch

dpgen/__init__.py#L51

Added line #L51 was not covered by tests
except ImportError:
print("%10s %10s Not Found" % (modui, ""))
print("%10s %10s Not Found" % (modui, "")) # noqa: UP031

Check warning on line 53 in dpgen/__init__.py

View check run for this annotation

Codecov / codecov/patch

dpgen/__init__.py#L53

Added line #L53 was not covered by tests
except AttributeError:
print("%10s %10s unknown version or path" % (modui, ""))
print("%10s %10s unknown version or path" % (modui, "")) # noqa: UP031

Check warning on line 55 in dpgen/__init__.py

View check run for this annotation

Codecov / codecov/patch

dpgen/__init__.py#L55

Added line #L55 was not covered by tests
print()

# reference
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/EOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
# vol = vol / 100.0
vol = self.vol_start + task_num * self.vol_step
# task_num = int((vol - self.vol_start) / self.vol_step)
output_task = os.path.join(path_to_work, "task.%06d" % task_num)
output_task = os.path.join(path_to_work, "task.%06d" % task_num) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
if self.inter_param["type"] == "abacus":
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/Elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
print("gen with norm " + str(norm_strains))
print("gen with shear " + str(shear_strains))
for ii in range(n_dfm):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in [
Expand Down
21 changes: 12 additions & 9 deletions dpgen/auto_test/Gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.symlink(os.path.relpath(equi_contcar), POSCAR)
# task_poscar = os.path.join(output, 'POSCAR')
for ii in range(len(all_slabs)):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
wanghan-iapcm marked this conversation as resolved.
Show resolved Hide resolved
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in ["INCAR", "POTCAR", POSCAR, "conf.lmp", "in.lammps"]:
Expand All @@ -232,9 +232,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
task_list.append(output_task)
# print("# %03d generate " % ii, output_task)
print(
"# %03d generate " % ii,
"# %03d generate " % ii, # noqa: UP031
output_task,
" \t %d atoms" % self.atom_num,
" \t %d atoms" % self.atom_num, # noqa: UP031
)
wanghan-iapcm marked this conversation as resolved.
Show resolved Hide resolved
# make confs
all_slabs[ii].to("POSCAR.tmp", "POSCAR")
Expand Down Expand Up @@ -472,12 +472,15 @@ def _compute_lower(self, output_file, all_tasks, all_res):
)

miller_index = loadfn(os.path.join(ii, "miller.json"))
ptr_data += "%-25s %7.2f %7.3f %8.3f %8.3f\n" % (
str(miller_index) + "-" + structure_dir + ":",
int(ii[-4:]) / self.n_steps,
sfe,
epa,
equi_epa_slab,
ptr_data += (
"%-25s %7.2f %7.3f %8.3f %8.3f\n"
% ( # noqa: UP031
str(miller_index) + "-" + structure_dir + ":",
int(ii[-4:]) / self.n_steps,
sfe,
epa,
equi_epa_slab,
)
wanghan-iapcm marked this conversation as resolved.
Show resolved Hide resolved
)
res_data[int(ii[-4:]) / self.n_steps] = [sfe, epa, equi_epa]

Expand Down
25 changes: 15 additions & 10 deletions dpgen/auto_test/Interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
# task_poscar = os.path.join(output, 'POSCAR')

for ii in range(len(dss)):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in [
Expand Down Expand Up @@ -262,7 +262,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):

super_latt_param = float(pos_line[2].split()[0])

output_task1 = os.path.join(path_to_work, "task.%06d" % (len(dss)))
output_task1 = os.path.join(path_to_work, "task.%06d" % (len(dss))) # noqa: UP031
os.makedirs(output_task1, exist_ok=True)
os.chdir(output_task1)
task_list.append(output_task1)
Expand All @@ -283,7 +283,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

output_task2 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 1)
path_to_work,
"task.%06d" % (len(dss) + 1), # noqa: UP031
)
os.makedirs(output_task2, exist_ok=True)
os.chdir(output_task2)
Expand All @@ -305,7 +306,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

output_task3 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 2)
path_to_work,
"task.%06d" % (len(dss) + 2), # noqa: UP031
)
os.makedirs(output_task3, exist_ok=True)
os.chdir(output_task3)
Expand Down Expand Up @@ -346,7 +348,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
replace_label = idx

output_task4 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 3)
path_to_work,
"task.%06d" % (len(dss) + 3), # noqa: UP031
)
os.makedirs(output_task4, exist_ok=True)
os.chdir(output_task4)
Expand Down Expand Up @@ -380,7 +383,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

output_task5 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 4)
path_to_work,
"task.%06d" % (len(dss) + 4), # noqa: UP031
)
os.makedirs(output_task5, exist_ok=True)
os.chdir(output_task5)
Expand Down Expand Up @@ -414,7 +418,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

output_task6 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 5)
path_to_work,
"task.%06d" % (len(dss) + 5), # noqa: UP031
)
os.makedirs(output_task6, exist_ok=True)
os.chdir(output_task6)
Expand Down Expand Up @@ -453,7 +458,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):

if self.inter_param["type"] == "abacus":
for ii in range(total_task):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.chdir(output_task)
abacus.poscar2stru("POSCAR", self.inter_param, "STRU")
os.remove("POSCAR")
Expand All @@ -478,8 +483,8 @@ def post_process(self, task_list):
type_num = type_map[insert_ele] + 1
conf_line[2] = str(len(type_map_list)) + " atom types"
conf_line[-2] = (
"%6.d" % int(insert_line.split()[0])
+ "%7.d" % type_num
"%6.d" % int(insert_line.split()[0]) # noqa: UP031
+ "%7.d" % type_num # noqa: UP031
wanghan-iapcm marked this conversation as resolved.
Show resolved Hide resolved
+ f"{float(insert_line.split()[2]):16.10f}"
+ f"{float(insert_line.split()[3]):16.10f}"
+ f"{float(insert_line.split()[4]):16.10f}"
Expand Down
8 changes: 4 additions & 4 deletions dpgen/auto_test/Surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
os.symlink(os.path.relpath(equi_contcar), POSCAR)
# task_poscar = os.path.join(output, 'POSCAR')
for ii in range(len(all_slabs)):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in [
Expand All @@ -213,9 +213,9 @@
os.remove(jj)
task_list.append(output_task)
print(
"# %03d generate " % ii,
"# %03d generate " % ii, # noqa: UP031
output_task,
" \t %d atoms" % len(all_slabs[ii].sites),
" \t %d atoms" % len(all_slabs[ii].sites), # noqa: UP031
)
# make confs
all_slabs[ii].to("POSCAR.tmp", "POSCAR")
Expand Down Expand Up @@ -270,7 +270,7 @@
evac = (task_result["energies"][-1] - equi_epa * natoms) / AA * Cf

miller_index = loadfn(os.path.join(ii, "miller.json"))
ptr_data += "%-25s %7.3f %8.3f %8.3f\n" % (
ptr_data += "%-25s %7.3f %8.3f %8.3f\n" % ( # noqa: UP031

Check warning on line 273 in dpgen/auto_test/Surface.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/Surface.py#L273

Added line #L273 was not covered by tests
str(miller_index) + "-" + structure_dir + ":",
evac,
epa,
Expand Down
6 changes: 3 additions & 3 deletions dpgen/auto_test/VASP.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def make_input_file(self, output_dir, task_type, task_param):
isif = 2
if not ("NSW" in incar and incar.get("NSW") == nsw):
dlog.info(
"%s setting NSW to %d"
"%s setting NSW to %d" # noqa: UP031
% (self.make_input_file.__name__, nsw)
)
incar["NSW"] = nsw
Expand All @@ -121,15 +121,15 @@ def make_input_file(self, output_dir, task_type, task_param):

if not ("ISIF" in incar and incar.get("ISIF") == isif):
dlog.info(
"%s setting ISIF to %d" % (self.make_input_file.__name__, isif)
"%s setting ISIF to %d" % (self.make_input_file.__name__, isif) # noqa: UP031
)
incar["ISIF"] = isif

elif cal_type == "static":
nsw = 0
if not ("NSW" in incar and incar.get("NSW") == nsw):
dlog.info(
"%s setting NSW to %d" % (self.make_input_file.__name__, nsw)
"%s setting NSW to %d" % (self.make_input_file.__name__, nsw) # noqa: UP031
)
incar["NSW"] = nsw

Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/Vacancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
# task_poscar = os.path.join(output, 'POSCAR')

for ii in range(len(dss)):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in [
Expand Down
6 changes: 3 additions & 3 deletions dpgen/auto_test/common_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
# conf_dirs.sort()
processes = len(property_list)
pool = Pool(processes=processes)
print("Submit job via %d processes" % processes)
print("Submit job via %d processes" % processes) # noqa: UP031

Check warning on line 105 in dpgen/auto_test/common_prop.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/common_prop.py#L105

Added line #L105 was not covered by tests
conf_dirs = []
for conf in confs:
conf_dirs.extend(glob.glob(conf))
Expand Down Expand Up @@ -181,8 +181,8 @@
for ii in range(len(multiple_ret)):
if not multiple_ret[ii].successful():
print("ERROR:", multiple_ret[ii].get())
raise RuntimeError("Job %d is not successful!" % ii)
print("%d jobs are finished" % len(multiple_ret))
raise RuntimeError("Job %d is not successful!" % ii) # noqa: UP031
print("%d jobs are finished" % len(multiple_ret)) # noqa: UP031

Check warning on line 185 in dpgen/auto_test/common_prop.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/common_prop.py#L184-L185

Added lines #L184 - L185 were not covered by tests


def worker(
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/lib/abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
if lines[-i][1:27] == "STEP OF MOLECULAR DYNAMICS":
max_step = int(lines[-i].split()[-1])
break
return "OUT.%s/STRU_MD_%d" % (suffix, max_step)
return "OUT.%s/STRU_MD_%d" % (suffix, max_step) # noqa: UP031

Check warning on line 336 in dpgen/auto_test/lib/abacus.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/abacus.py#L336

Added line #L336 was not covered by tests
elif calculation == "scf":
return "STRU"
else:
Expand Down
22 changes: 11 additions & 11 deletions dpgen/auto_test/lib/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
ret += "box tilt large\n"
ret += f"read_data {conf}\n"
for ii in range(len(type_map)):
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass)
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031

Check warning on line 184 in dpgen/auto_test/lib/lammps.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lammps.py#L184

Added line #L184 was not covered by tests
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
ret += "compute mype all pe\n"
Expand Down Expand Up @@ -239,7 +239,7 @@
ret += "box tilt large\n"
ret += f"read_data {conf}\n"
for ii in range(len(type_map)):
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass)
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
ret += "compute mype all pe\n"
Expand All @@ -251,11 +251,11 @@
ret += "min_style cg\n"
if change_box:
ret += "fix 1 all box/relax iso 0.0 \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "fix 1 all box/relax aniso 0.0 \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "fix 1 all box/relax tri 0.0 \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "variable N equal count(all)\n"
ret += "variable V equal vol\n"
ret += 'variable E equal "c_mype"\n'
Expand Down Expand Up @@ -296,7 +296,7 @@
ret += "box tilt large\n"
ret += f"read_data {conf}\n"
for ii in range(len(type_map)):
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass)
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031

Check warning on line 299 in dpgen/auto_test/lib/lammps.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lammps.py#L299

Added line #L299 was not covered by tests
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
ret += "compute mype all pe\n"
Expand All @@ -306,7 +306,7 @@
)
ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n"
ret += "min_style cg\n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031

Check warning on line 309 in dpgen/auto_test/lib/lammps.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lammps.py#L309

Added line #L309 was not covered by tests
ret += "variable N equal count(all)\n"
ret += "variable V equal vol\n"
ret += 'variable E equal "c_mype"\n'
Expand Down Expand Up @@ -361,7 +361,7 @@
ret += "box tilt large\n"
ret += f"read_data {conf}\n"
for ii in range(len(type_map)):
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass)
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031

Check warning on line 364 in dpgen/auto_test/lib/lammps.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lammps.py#L364

Added line #L364 was not covered by tests
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
ret += "compute mype all pe\n"
Expand All @@ -372,9 +372,9 @@
ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n"
ret += "min_style cg\n"
ret += "fix 1 all box/relax iso ${Px} \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031

Check warning on line 375 in dpgen/auto_test/lib/lammps.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lammps.py#L375

Added line #L375 was not covered by tests
ret += "fix 1 all box/relax aniso ${Px} \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031

Check warning on line 377 in dpgen/auto_test/lib/lammps.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lammps.py#L377

Added line #L377 was not covered by tests
ret += "variable N equal count(all)\n"
ret += "variable V equal vol\n"
ret += 'variable E equal "c_mype"\n'
Expand Down Expand Up @@ -409,7 +409,7 @@
ret += f"read_data {conf}\n"
ntypes = len(masses)
for ii in range(ntypes):
ret += "mass %d %f\n" % (ii + 1, masses[ii])
ret += "mass %d %f\n" % (ii + 1, masses[ii]) # noqa: UP031

Check warning on line 412 in dpgen/auto_test/lib/lammps.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lammps.py#L412

Added line #L412 was not covered by tests
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
return ret
Expand Down
8 changes: 4 additions & 4 deletions dpgen/auto_test/lib/lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
system["atom_numbs"] = get_natoms_vec(lines)
system["atom_names"] = []
for ii in range(len(system["atom_numbs"])):
system["atom_names"].append("Type_%d" % ii)
system["atom_names"].append("Type_%d" % ii) # noqa: UP031

Check warning on line 148 in dpgen/auto_test/lib/lmp.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lmp.py#L148

Added line #L148 was not covered by tests
lohi, tilt = get_lmpbox(lines)
orig, cell = lmpbox2box(lohi, tilt)
system["orig"] = np.array(orig)
Expand All @@ -165,8 +165,8 @@
ret += "\n"
natoms = sum(system["atom_numbs"])
ntypes = len(system["atom_numbs"])
ret += "%d atoms\n" % natoms
ret += "%d atom types\n" % ntypes
ret += "%d atoms\n" % natoms # noqa: UP031
ret += "%d atom types\n" % ntypes # noqa: UP031

Check warning on line 169 in dpgen/auto_test/lib/lmp.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lmp.py#L168-L169

Added lines #L168 - L169 were not covered by tests
ret += "0 {:f} xlo xhi\n".format(system["cell"][0][0])
ret += "0 {:f} ylo yhi\n".format(system["cell"][1][1])
ret += "0 {:f} zlo zhi\n".format(system["cell"][2][2])
Expand All @@ -179,7 +179,7 @@
ret += "Atoms # atomic\n"
ret += "\n"
for ii in range(natoms):
ret += "%d %d %f %f %f\n" % (
ret += "%d %d %f %f %f\n" % ( # noqa: UP031

Check warning on line 182 in dpgen/auto_test/lib/lmp.py

View check run for this annotation

Codecov / codecov/patch

dpgen/auto_test/lib/lmp.py#L182

Added line #L182 was not covered by tests
ii + 1,
system["atom_types"][ii],
system["coordinates"][ii][0] - system["orig"][0],
Expand Down
Loading
Loading