Fix the argument order of Structure.to in the solver tests - #84
Merged
Conversation
The Unit job fails on Python 3.13 with
ValueError: Invalid fmt='.../tests/res/vasp/pos.vasp',
valid options are ('cif', 'poscar', ...)
in test_get_results for the aenet, openmx, qe and vasp solvers.
These tests call
res.structure.to("POSCAR", os.path.join(self.workdir, "pos.vasp"))
which matches the old pymatgen signature to(fmt, filename). Current
pymatgen takes to(filename, fmt), so the path is passed as the format.
The argument order has therefore been wrong for some time. It stayed
invisible because pymatgen also selected the POSCAR writer whenever the
file name matched *POSCAR*, so the call succeeded while writing to a file
named POSCAR in the current directory instead of the intended
workdir/pos.vasp -- leaving a stray POSCAR in the repository root on every
test run. pymatgen-core 2026.8.13 no longer falls back to that name match,
so the bad format argument now raises.
Pass both arguments by keyword, as the rest of abics already does. This
works on both the old and the new pymatgen, writes the file where the
tests intended, and stops littering the working tree.
Also assert that the file was written where the test asked for it. Nothing
read that file back, which is why the wrong argument order went unnoticed
for so long; the assertion fails on a swapped call even on pymatgen
versions whose file name fallback keeps the call from raising.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cv7Xn4Q8TSpLjpg9aDpuhi
k-yoshimi
force-pushed
the
fix-structure-to-args
branch
from
August 16, 2026 09:29
a47ccce to
c1821c1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
Unitjob fails on Python 3.13 (bothnumpy 1.26.4andlatest):The same failure occurs in
test_aenet,test_openmx,test_qeandtest_vasp.Cause
The four tests call
Structure.towith the old pymatgen signatureto(fmt, filename). Current pymatgen takesto(filename, fmt), so the output path is passed as the format.The argument order has been wrong for some time. It stayed invisible because pymatgen also selected the POSCAR writer whenever the file name matched
*POSCAR*; withfilename="POSCAR"the call succeeded, but it wrote to a file literally namedPOSCARin the current directory instead of the intendedworkdir/pos.vasp. Every test run therefore left a strayPOSCARin the repository root, and the file the tests meant to write was never created.pymatgen-core2026.8.13, released on 2026-08-13, no longer falls back to that file name match, so the bad format argument now raises. This is why the job started failing without any change on our side, and why it still passes on Python 3.9, where an older pymatgen is resolved.Library code is not affected: every live
Structure.tocall underabics/already passesfmtandfilenameby keyword. Only the tests use the positional form.Change
Pass both arguments by keyword in the four tests, matching the style used in
abics/. This is correct on both the old and the new pymatgen, writes the file where the tests intended, and stops littering the working tree.Verification
Run in an environment reproducing the CI package set (
pymatgen-core2026.8.13 withpymatgen2026.5.4):ValueErroras CIpymatgen-core2026.4.16: 31 tests pass, so the change is compatible both waystests/res/*/pos.vaspis now actually written, and no strayPOSCARappears in the repository rootNote (not addressed here)
tests/test_aenetpylammps.pyandtests/test_aenet.pyshare thetests/res/aenetdirectory, and one class'ssetUpClassremoves the other's output. Nothing reads those files back, so there is no failure today, but the tests are not isolated from each other.🤖 Generated with Claude Code
https://claude.ai/code/session_01Cv7Xn4Q8TSpLjpg9aDpuhi