Skip to content

Commit abf0bef

Browse files
shyuepclaude
andcommitted
Fix CI: reorder install steps and clean up ruff/mypy errors
`uv pip install dgl` was running before `uv sync` in both lint and test workflows. setup-uv v8 no longer auto-creates a venv, so the pip install failed with "No virtual environment found." Swap the order: sync first to create the venv, then pip install dgl to override the version. Also clean up lint errors that would surface once install succeeds: - Add PLC0415 to ruff ignore (lazy imports for optional deps like tensorflow/megnet/m3gnet are intentional; 31 violations) - Drop obsolete PD901 ignore (rule was removed from ruff) - Prefix 11 unused unpacked variables with _ (RUF059) - Replace `key=lambda x: Element(x)` with `key=Element` (PLW0108, 5) - Default reduction_params to {} before ** unpack (_composition.py) - Extend type: ignore codes in gbe/describer.py and data/_mp.py - Add `equil` (LAMMPS equilibration filename) to codespell allowlist Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 131a5ef commit abf0bef

16 files changed

Lines changed: 27 additions & 25 deletions

File tree

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
cache-dependency-glob: "uv.lock"
2121
- name: Install dependencies
2222
run: |
23-
uv pip install dgl==2.4.0 -f https://data.dgl.ai/wheels/torch-2.4/repo.html
2423
uv sync --group lint
24+
uv pip install dgl==2.4.0 -f https://data.dgl.ai/wheels/torch-2.4/repo.html
2525
2626
- name: ruff
2727
run: |

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
cache-dependency-glob: "uv.lock"
3939
- name: Install dependencies
4040
run: |
41-
uv pip install dgl==2.4.0 -f https://data.dgl.ai/wheels/torch-2.4/repo.html
4241
uv sync
42+
uv pip install dgl==2.4.0 -f https://data.dgl.ai/wheels/torch-2.4/repo.html
4343
- name: pytest
4444
run: |
4545
uv run pytest tests --cov=maml
@@ -66,8 +66,8 @@ jobs:
6666
cache-dependency-glob: "uv.lock"
6767
- name: Install dependencies
6868
run: |
69-
uv pip install dgl==2.4.0 -f https://data.dgl.ai/wheels/torch-2.4/repo.html
7069
uv sync
70+
uv pip install dgl==2.4.0 -f https://data.dgl.ai/wheels/torch-2.4/repo.html
7171
- run: |
7272
uv build
7373
- name: Publish to PyPi

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ lint.ignore = [
135135
"D105", # Missing docstring in magic method
136136
"D205", # 1 blank line required between summary line and description
137137
"D212", # Multi-line docstring summary should start at the first line
138-
"PD901", # pandas-df-variable-name
139138
"PERF203", # try-except-in-loop
140139
"PERF401", # manual-list-comprehension (TODO fix these or wait for autofix)
140+
"PLC0415", # `import` should be at the top-level of a file (lazy imports for optional deps are intentional)
141141
"PLR", # pylint refactor
142142
"PLW2901", # Outer for loop variable overwritten by inner assignment target
143143
"PT013", # pytest-incorrect-pytest-import
@@ -187,7 +187,8 @@ ignore_missing_imports = true
187187
[tool.codespell]
188188
ignore-words-list = """
189189
titel,alls,ans,nd,mater,nwo,te,hart,ontop,ist,ot,fo,nax,coo,coul,ser,leary,thre,
190-
fase,rute,reson,titels,ges,scalr,strat,struc,hda,nin,ons,pres,kno,loos,lamda,lew
190+
fase,rute,reson,titels,ges,scalr,strat,struc,hda,nin,ons,pres,kno,loos,lamda,lew,
191+
equil
191192
"""
192193
skip = "pymatgen/analysis/aflow_prototypes.json"
193194
check-filenames = true

src/maml/apps/bowsr/model/dft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def predict_energy(self, structure: Structure):
5858
stdout=subprocess.PIPE,
5959
stderr=subprocess.PIPE, # type: ignore
6060
) as p_exe:
61-
stdout, stderr = p_exe.communicate()
61+
_stdout, stderr = p_exe.communicate()
6262
rc = p_exe.returncode
6363
if rc != 0:
6464
error_msg = f"vasp exited with return code {rc}"

src/maml/apps/gbe/describer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def get_elemental_feature(
274274
el = Element(db_entry["pretty_formula"])
275275
f_dict[preset.ar.str_name] = el.atomic_radius
276276
f_dict[preset.a0.str_name] = bulk_s.lattice.a
277-
f_dict[preset.e_coh.str_name] = rester.get_cohesive_energy(db_entry["material_id"]) # type: ignore[attr-defined]
277+
f_dict[preset.e_coh.str_name] = rester.get_cohesive_energy(db_entry["material_id"]) # type: ignore[attr-defined,misc]
278278
f_dict[preset.hb.str_name] = el.brinell_hardness
279279
f_dict[preset.CLTE.str_name] = el.coefficient_of_linear_thermal_expansion
280280

src/maml/apps/pes/_gap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def train(
281281
if str(specie) not in gap_sorted_elements:
282282
gap_sorted_elements.append(str(specie))
283283

284-
self.elements = sorted(gap_sorted_elements, key=lambda x: Element(x))
284+
self.elements = sorted(gap_sorted_elements, key=Element)
285285

286286
atoms_filename = "train.xyz"
287287
xml_filename = "train.xml"
@@ -504,5 +504,5 @@ def get_xml(xml_file):
504504
tree, element_param, potential_label = get_xml(filename)
505505
parameters = dict(xml=tree, element_param=element_param, potential_label=potential_label)
506506
gap = GAPotential(param=parameters)
507-
gap.elements = sorted(element_param.keys(), key=lambda x: Element(x))
507+
gap.elements = sorted(element_param.keys(), key=Element)
508508
return gap

src/maml/apps/pes/_lammps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def calculate(self, structures):
211211

212212
@staticmethod
213213
def _rotate_force_stress(structure, forces, stresses):
214-
_, symmop, rot_matrix = get_lammps_lattice_and_rotation(structure)
214+
_, _symmop, rot_matrix = get_lammps_lattice_and_rotation(structure)
215215
inv_rot_matrix = np.linalg.inv(rot_matrix)
216216
forces = forces.dot(inv_rot_matrix.T)
217217
stresses = stress_list_to_matrix(stresses, stress_format="LAMMPS")
@@ -323,7 +323,7 @@ def add_args(line):
323323
return line + compute_args if line.startswith("compute") else line
324324

325325
compute_args = f"1 0.99363 {self.twojmax} "
326-
el_in_seq = sorted(self.element_profile.keys(), key=lambda x: Element(x))
326+
el_in_seq = sorted(self.element_profile.keys(), key=Element)
327327
cutoffs = [self.element_profile[e]["r"] * self.rcutfac for e in el_in_seq]
328328
weights = [self.element_profile[e]["w"] for e in el_in_seq]
329329
compute_args += " ".join([str(p) for p in cutoffs + weights])

src/maml/apps/pes/_nnp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def str_formatify(string):
521521
df = pd.DataFrame([line.split() for line in lines if "#" not in line])
522522
self.elements = sorted(
523523
(element for element in np.ravel(df[df[0] == "elements"])[1:] if element is not None),
524-
key=lambda x: Element(x),
524+
key=Element,
525525
)
526526

527527
atom_energy = {}
@@ -731,7 +731,7 @@ def train(self, train_structures, train_energies, train_forces, train_stresses=N
731731

732732
self.write_input(**kwargs)
733733
with subprocess.Popen(["nnp-scaling", "100"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p_scaling:
734-
stdout, stderr = p_scaling.communicate()
734+
_stdout, stderr = p_scaling.communicate()
735735
rc = p_scaling.returncode
736736
if rc != 0:
737737
error_msg = f"n2p2 exited with return code {rc}"
@@ -745,7 +745,7 @@ def train(self, train_structures, train_energies, train_forces, train_stresses=N
745745
raise RuntimeError(error_msg)
746746

747747
with open(output, "w") as f, subprocess.Popen(["nnp-train"], stdout=f, stderr=subprocess.PIPE) as p_train:
748-
stdout, stderr = p_train.communicate()
748+
_stdout, stderr = p_train.communicate()
749749
rc = p_train.returncode
750750

751751
if rc != 0:
@@ -821,7 +821,7 @@ def evaluate(self, test_structures, test_energies, test_forces, test_stresses=No
821821
with subprocess.Popen(
822822
["nnp-predict", input_filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE
823823
) as p_evaluation:
824-
stdout, stderr = p_evaluation.communicate()
824+
_stdout, stderr = p_evaluation.communicate()
825825
rc = p_evaluation.returncode
826826
if rc != 0:
827827
error_msg = f"n2p2 exited with return code {rc}"

src/maml/apps/symbolic/_selectors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def select(self, x: np.ndarray, y: np.ndarray, options: dict | None = None) -> n
4747
to scipy.optimize.minimize
4848
Returns: list of int indices.
4949
"""
50-
n_data, n_dim = x.shape
50+
_n_data, n_dim = x.shape
5151
options = options or {"maxiter": 1e4, "ftol": 1e-12}
5252
res = minimize(
5353
lambda beta: self.construct_loss(x=x, y=y, beta=beta),
@@ -535,7 +535,7 @@ def select(self, x: np.ndarray, y: np.ndarray, options: dict | None = None, n_jo
535535
n_job (int): number of cpu
536536
Returns:
537537
"""
538-
n, p = x.shape
538+
_n, p = x.shape
539539
index_array = list(range(p))
540540

541541
def _lstsq(c):

src/maml/apps/symbolic/_selectors_cvxpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def select(self, x: np.ndarray, y: np.ndarray, options: dict | None = None) -> n
4444
Returns: list of int indices.
4545
"""
4646
options = options or {}
47-
n, p = x.shape
47+
_n, p = x.shape
4848
beta = cp.Variable(p)
4949
objective = cp.Minimize(self.construct_loss(x, y, beta))
5050
constraints = self.construct_constraints(x, y, beta)

0 commit comments

Comments
 (0)