Repository navigation
test(md): known-answer tests for the stress -> pressure conversion (S-02) - #79
Merged
Merged
Conversation
S-02 (tracker #75). The MD observables configurational_pressure_gpa / total_pressure_gpa were only asserted to be None (non-3D PBC) or merely unequal to each other; the numeric value, the eV/A^3 -> GPa unit conversion and the sign convention were never checked against an independent calculation. Add three known-answer tests over a synthetic calculator with a caller chosen Voigt stress: * isotropic compression -0.03 eV/A^3 -> +4.807 GPa (positive), and with zero momenta total == configurational, * isotropic tension +0.03 eV/A^3 -> -4.807 GPa (sign not inverted), * only xx+yy+zz enters; a pure shear stress gives exactly 0.0 GPa. The reference constant comes from the exact SI constants (1 eV/A^3 = e/1e-30 Pa = 160.2176634 GPa), not from the product code; the comparisons use rel=1e-6, which is far looser than the 8e-9 rounding difference and far tighter than any wrong factor/unit/sign. Doubling the reference constant fails exactly the two magnitude tests, so the tests are not vacuous. DATA IMPACT: no scientific record invalidated (test-only change). Tracking: #75
hydrogen1222
commented
Nov 1, 2026
hydrogen1222
left a comment
Owner
Author
There was a problem hiding this comment.
Audit review — no blocking concern in the shown test-only diff.
The three known-answer assertions independently pin the pressure sign, eV/ų→GPa conversion and trace-vs-shear contract; CI is green on Python 3.10–3.13. This can be considered for merge after normal branch/current-head checks.
Suggested follow-up (not required to merge this test-only PR): add a genuinely nonzero-momentum, mixed-mass known answer for the include_ideal_gas=True kinetic contribution, since the new test only proves total == configurational when momenta are zero. Keep S-02 marked only partly covered until kinetic and writer paths are checked.
hydrogen1222
marked this pull request as ready for review
November 1, 2026 13:02
This was referenced Nov 1, 2026
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.
Tracking: #75 (Living code audit & exhaustive scientific test campaign)
S-02 — known-answer test for the MD stress → pressure conversion
Test-only. No production code changed.
Blind spot
The tracker's S-02 invariant asks for "Units: … pressure conversion … Independent
hand-calculated known answers". The MD observables
configurational_pressure_gpa/total_pressure_gpawere only ever asserted tobe
None(non-3D PBC) or merely unequal to each other; the numeric value,the unit conversion and the sign convention were never checked against an
independent calculation.
Added tests (
tests/mliport/mliport/test_md_runner.py)test_md_pressure_known_answer_isotropic_compression-0.03 eV/ų→ positive0.03 × 160.2176634 = 4.807 GPa; with zero momentatotal == configurational(ideal-gas term vanishes)test_md_pressure_known_answer_is_tensile_negative+0.03 eV/ų→ negative-4.807 GPa(sign not inverted)test_md_pressure_uses_the_trace_not_all_six_componentsxx+yy+zzenters; a pure shear stress gives exactly0.0GPaThe reference constant is derived independently from the exact SI constants
(
1 eV/ų = e/1e-30 Pa = 160.2176634 GPa,e = 1.602176634e-19 C), not copiedfrom the product code. The product rounds it to
160.21766208(8e-9 relativedifference), so the comparisons use
rel=1e-6— tight enough to catch a wrongfactor, unit or sign, far looser than the rounding.
The tests are not vacuous (mutation check)
Doubling the reference constant makes exactly the two magnitude tests fail:
and the observed values match the hand calculation:
Evidence
main@1ef9a1bea5033dc1a1664d8450f4b4f9edfbd91d, Python 3.12.13,pytest 9.1.1, numpy 2.5.4, CPU-only
.venv-dev.pytest tests/mliport/mliport/test_md_runner.py -q→67 passed.ruff check/ruff format --check→ clean.DATA IMPACT
No scientific record invalidated (test-only change; no stored data touched).
Residual
The same unit conversion is spelled out as a literal in four production sites
(
runners/base.py,runners/md.pyviaMDOutcarWriter.EV_A3_TO_GPA,writers/outcar.py,writers/json_writer.py). This PR pins the MD path only;the 160.2177 vs 160.21766208 rounding difference is ~8e-9 relative and not
physically meaningful, but consolidating the constant would be a follow-up
cleanup, not a correctness fix.