Skip to content

fix(md): reject illegal NPT requests before any output or model load (R10-F01/P2) - #111

Draft
hydrogen1222 wants to merge 2 commits into
mainfrom
fix/r10-f01-md-validation-order
Draft

hydrogen1222 wants to merge 2 commits into
mainfrom
fix/r10-f01-md-validation-order

Conversation

@hydrogen1222

Copy link
Copy Markdown
Owner

Defect (R10-F01, main @ fb2935c7)

Four NPT cross-field contracts were only enforced inside MDRunner, i.e. after
results/, resolved_config.json and the model load:

  1. NPT with a non-Langevin thermostat,
  2. NPT with --no-write-trajectory,
  3. NPT with temperature <= 0,
  4. NPT with npt_tdamp / npt_pdamp <= 0.

Measured with mliport md --ensemble NPT on a Cu4 cell (mace-mh-1):

request on main after this PR
--thermostat NHC results_dir=Y resolved=Y model_loaded=Y, exit 1 N/N/N, exit 1
--no-write-trajectory Y/Y/Y N/N/N
--temp 0 Y/Y/Y N/N/N
--npt-tdamp 0 Y/Y/Y N/N/N

All four are pure configuration facts, so they belong to the resolver.

Fix

resolver._validate_resolved() now checks the NPT contract before anything is
created or loaded, with the same messages (so logs, docs and tests that
quote them keep working). MDRunner keeps its checks for direct API users.

No change for valid runs

NVE, NVT-NHC and NPT md.csv files are byte-identical (md5) between main
and this branch for the same seed/structure/options.

Tests

Red first: five parametrised rejection cases plus one "legal NPT default still
resolves" case in tests/mliport/mliport/test_md_npt.py.

Local: 2322 passed, 48 skipped; ruff check / ruff format --check clean.

DATA IMPACT

No scientific record invalidated or regenerated: only the point at which an
invalid request is rejected changes, and no legal NPT/NVT/NVE output changes.

Residual (not fixed here, tracked in #75)

  • NHC + FixAtoms is still rejected after the model load — it depends on the
    structure, not on configuration.
  • A missing CUDA device still surfaces as a raw torch.load error.

R10-F01. Four NPT cross-field contracts were only enforced inside
``MDRunner``, i.e. after ``results/`` and ``resolved_config.json`` had been
created and after the model was loaded:

  * NPT with a non-Langevin thermostat,
  * NPT with ``--no-write-trajectory``,
  * NPT with ``temperature <= 0``,
  * NPT with ``npt_tdamp``/``npt_pdamp <= 0``.

Measured on main @ fb2935c with ``mliport md --ensemble NPT`` on Cu4: all
four produced ``results_dir=Y resolved=Y model_loaded=Y`` before failing.
They are pure configuration facts, so they are now rejected by
``resolver._validate_resolved()`` with the *same* messages.  The checks stay
in ``MDRunner`` for direct API users.

Verification on the same four requests after the fix: no run directory, no
resolved_config.json, no model load, identical exit code (1) and message.
Legal runs are unchanged: NVE, NVT-NHC and NPT ``md.csv`` files are
byte-identical (md5) to the main build.

Red tests first in tests/mliport/mliport/test_md_npt.py (5 parametrised
cases plus one "legal default still resolves" case).  Local: 2322 passed,
48 skipped; ruff check/format clean.

DATA IMPACT: no scientific record invalidated or regenerated.  Only the
point at which invalid input is rejected changes; no valid NPT/NVT/NVE run
produces different output.

Residual (recorded, out of scope here): NHC + FixAtoms is still rejected
after the model load (it depends on the structure, not on configuration),
and a missing CUDA device still surfaces as a raw torch error.
CI runs ruff@0.5.1 format --check, which reformats the new NPT block's line
wrapping. No behavioural change.

This branch has not been deployed

No deployments
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