Skip to content

Fix the argument order of Structure.to in the solver tests - #84

Merged
k-yoshimi merged 1 commit into
developfrom
fix-structure-to-args
Aug 17, 2026
Merged

Fix the argument order of Structure.to in the solver tests#84
k-yoshimi merged 1 commit into
developfrom
fix-structure-to-args

Conversation

@k-yoshimi

Copy link
Copy Markdown
Contributor

Problem

The Unit job fails on Python 3.13 (both numpy 1.26.4 and latest):

ERROR: test_get_results (tests.test_vasp.TestVASP.test_get_results)
  File "tests/test_vasp.py", line 53, in test_get_results
    res.structure.to("POSCAR", os.path.join(self.workdir, "pos.vasp"))
ValueError: Invalid fmt='.../tests/res/vasp/pos.vasp',
valid options are ('cif', 'poscar', 'cssr', 'json', 'yaml', 'yml', 'xsf', 'mcsqs', 'res', 'pwmat', 'aims', '')

The same failure occurs in test_aenet, test_openmx, test_qe and test_vasp.

Cause

The four tests call Structure.to with the old pymatgen signature to(fmt, filename). Current pymatgen takes to(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*; with filename="POSCAR" the call succeeded, but it wrote to a file literally named POSCAR in the current directory instead of the intended workdir/pos.vasp. Every test run therefore left a stray POSCAR in the repository root, and the file the tests meant to write was never created.

pymatgen-core 2026.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.to call under abics/ already passes fmt and filename by 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-core 2026.8.13 with pymatgen 2026.5.4):

  • before the change: the same four tests fail with the same ValueError as CI
  • after the change: 31 tests pass
  • with the older pymatgen-core 2026.4.16: 31 tests pass, so the change is compatible both ways
  • tests/res/*/pos.vasp is now actually written, and no stray POSCAR appears in the repository root

Note (not addressed here)

tests/test_aenetpylammps.py and tests/test_aenet.py share the tests/res/aenet directory, and one class's setUpClass removes 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

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
k-yoshimi force-pushed the fix-structure-to-args branch from a47ccce to c1821c1 Compare August 16, 2026 09:29
@k-yoshimi
k-yoshimi merged commit ac48375 into develop Aug 17, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant