Skip to content

Make torchsim able to use the latest metatomic features#181

Merged
Luthaf merged 23 commits intometatensor:mainfrom
HaoZeke:feat/torchsim-papercuts
Mar 26, 2026
Merged

Make torchsim able to use the latest metatomic features#181
Luthaf merged 23 commits intometatensor:mainfrom
HaoZeke:feat/torchsim-papercuts

Conversation

@HaoZeke
Copy link
Copy Markdown
Member

@HaoZeke HaoZeke commented Mar 17, 2026

Close #179.

Contributor (creator of pull-request) checklist

  • Tests updated (for new features and bugfixes)?
  • Documentation updated (for new features)?
  • Issue referenced (for PRs that solve an issue)?

Reviewer checklist

  • CHANGELOG updated with public API or any other important changes?

@HaoZeke HaoZeke requested a review from Luthaf March 17, 2026 21:38
@Luthaf Luthaf changed the title chore(torchsim): address papercuts Make torchsim able to use the latest metatomic features Mar 18, 2026
Comment thread docs/src/engines/torch-sim-architecture.rst Outdated
Comment thread docs/src/engines/torch-sim-batched.rst Outdated
Comment thread docs/src/engines/torch-sim-getting-started.rst Outdated
Comment thread docs/src/engines/torch-sim-model-loading.rst Outdated
Comment thread docs/src/engines/torch-sim.rst Outdated
Comment thread docs/src/engines/torch-sim.rst Outdated
Comment thread docs/src/engines/torch-sim.rst Outdated
Comment thread python/metatomic_torchsim/metatomic_torchsim/_model.py Outdated
Comment thread python/metatomic_torchsim/metatomic_torchsim/_model.py Outdated
Comment thread python/metatomic_torchsim/metatomic_torchsim/_model.py Outdated
HaoZeke added a commit to HaoZeke/metatomic that referenced this pull request Mar 18, 2026
- Remove doc sub-pages (architecture already in Architecture.md,
  getting-started/batched belong as tutorials, model-loading goes
  in docstring)
- Remove toctree and "output variants" / "additional outputs" bullet
  from torch-sim.rst (expected for all engines)
- Revert ts.io.atoms_to_state back to ts.initialize_state (torchsim
  docs convention)
- Reformulate NC docstring to match ASE calculator wording
- Fix variants docstring example per suggestion
- Truncate uncertainty warning atom list to first 20

Verified: 29 passed, 1 skipped on rg.cosmolab
Copy link
Copy Markdown
Member

@Luthaf Luthaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of small documentation improvements!

Comment thread docs/src/engines/torch-sim.rst Outdated
Comment thread docs/src/engines/torch-sim.rst
Comment thread python/metatomic_torchsim/metatomic_torchsim/_model.py
Comment thread python/metatomic_torchsim/metatomic_torchsim/_model.py Outdated
Luthaf pushed a commit to HaoZeke/metatomic that referenced this pull request Mar 24, 2026
- Remove doc sub-pages (architecture already in Architecture.md,
  getting-started/batched belong as tutorials, model-loading goes
  in docstring)
- Remove toctree and "output variants" / "additional outputs" bullet
  from torch-sim.rst (expected for all engines)
- Revert ts.io.atoms_to_state back to ts.initialize_state (torchsim
  docs convention)
- Reformulate NC docstring to match ASE calculator wording
- Fix variants docstring example per suggestion
- Truncate uncertainty warning atom list to first 20

Verified: 29 passed, 1 skipped on rg.cosmolab
@Luthaf Luthaf force-pushed the feat/torchsim-papercuts branch from b5fe8c0 to f9e0fa2 Compare March 24, 2026 15:41
@HaoZeke HaoZeke force-pushed the feat/torchsim-papercuts branch from 7ceea8f to 2ef8b17 Compare March 25, 2026 14:44
Comment thread python/examples/5-torchsim-getting-started.py Outdated
Comment thread docs/src/engines/torch-sim.rst Outdated
@HaoZeke HaoZeke force-pushed the feat/torchsim-papercuts branch from b20f748 to ec615b9 Compare March 26, 2026 12:42
HaoZeke added 18 commits March 26, 2026 13:47
…al outputs

Bring MetatomicModel to feature parity with the ASE calculator:

- variants parameter for output variant selection via pick_output()
- non_conservative flag to read forces/stress directly from model
- uncertainty_threshold for per-atom energy uncertainty warnings
- additional_outputs for requesting arbitrary extra model outputs

Restore documentation sub-pages (getting-started, model-loading,
batched, architecture) that were removed during the merge.

Closes metatensor#179
- Fix NC stress quantity: "stress" -> "pressure" (matching ASE calculator)
- Fix per-system net-force subtraction in batched NC mode
- Validate NC output keys exist in model capabilities at construction
- Validate additional_outputs entries are ModelOutput instances
- Rename misleading test (test_bad_uncertainty_threshold_raises ->
  test_uncertainty_threshold_stored)
- Fix docs API inconsistency (ts.initialize_state -> ts.io.atoms_to_state)
- Gate NC output validation on compute_forces/compute_stress flags
  (avoids spurious ValueError when model has NC forces but not stress)
- Fix docs stress shape notation to use n_systems instead of literal 3
- Precompute evaluation options in __init__ (avoid per-call rebuilding)
- Add shape assertion for uncertainty values
- Strengthen additional_outputs validation (check _method_names)
- Full NC test coverage: forces, stress, batched per-system subtraction,
  missing-output error, variant selection
- Full UQ test coverage: warning emission, high-threshold no-warning,
  None disables, negative threshold rejection
- Variant test: "doubled" gives 2x base energy
- Additional outputs test: energy_ensemble stored correctly
- Use lj_model_ext fixture (with_extension=True) to test missing NC error
- Default uncertainty_threshold to None (not 0.1) since pure-PyTorch
  LJ model always has energy_uncertainty output, causing warnings-as-
  errors in all tests
- Gate pick_output calls for NC keys on compute_forces/compute_stress
  (pick_output raises before our validation if model lacks the output)
- Fix test regex: "not found" matches pick_output error message
- Apply ruff format
filterwarnings = ["error"] converts warnings to exceptions, so
warnings.catch_warnings(record=True) never captures them. Use
pytest.warns(UserWarning) which properly overrides the filter.
- Convert state.pbc (bool or array) to Tensor for System() constructor
- Fix test regex to match "uncertainties are larger" (pytest.raises
  matches against str(exception) which wraps differently)

Verified: 29 passed, 1 skipped on rg.cosmolab
- Remove doc sub-pages (architecture already in Architecture.md,
  getting-started/batched belong as tutorials, model-loading goes
  in docstring)
- Remove toctree and "output variants" / "additional outputs" bullet
  from torch-sim.rst (expected for all engines)
- Revert ts.io.atoms_to_state back to ts.initialize_state (torchsim
  docs convention)
- Reformulate NC docstring to match ASE calculator wording
- Fix variants docstring example per suggestion
- Truncate uncertainty warning atom list to first 20

Verified: 29 passed, 1 skipped on rg.cosmolab
- Remove stale CHANGELOG entry about deleted doc sub-pages
- Hoist pbc bool-to-Tensor conversion above per-system loop
- Convert uncertainty shape assert to ValueError (survives -O)
- Always resolve both NC keys via pick_output when non_conservative=True
  (match ASE behavior: validate model supports outputs at construction)
- Simplify additional_outputs validation to match ASE pattern (assert
  isinstance ScriptObject, no internal method duck-typing)
- Add test: stress-only NC mode (compute_forces=False)
- Add test: NC variant doubled verifies 2x energy
- Add test: invalid additional_outputs raises AssertionError

Verified: 31 passed, 1 skipped on rg.cosmolab
- Default uncertainty_threshold=0.1 to match ASE calculator
- Add additional_outputs bullet to supported outputs docs with link
  to API documentation
- Mention r-RESPA / multiple time stepping in NC docstring
- All non-UQ tests pass uncertainty_threshold=None to avoid
  warnings-as-errors with the pure-PyTorch LJ model
Per review: these belong as tutorials under the torch-sim engine page.
Architecture stays in Architecture.md (developer docs). Model-loading
content distilled into the MetatomicModel docstring.
Replace plain RST tutorials with sphinx-gallery Python scripts that
are self-contained and runnable in the docs build environment. Each
tutorial exports a minimal constant-energy model and demonstrates the
MetatomicModel / TorchSim workflow end-to-end.
@HaoZeke HaoZeke force-pushed the feat/torchsim-papercuts branch from ec615b9 to 3664a09 Compare March 26, 2026 12:47
HaoZeke and others added 5 commits March 26, 2026 14:05
Use HarmonicEnergy (E = k*sum(pos^2)) instead of ConstantEnergy so
autograd can compute forces/stress. Pass AtomisticModel directly to
MetatomicModel to avoid TorchScript save/load. Fix NVE loop to
re-evaluate model each step.
SimState has no velocities attribute; the integrator manages momenta
internally. Remove the manual velocity initialization.
SimState has no velocities; use nve_init to create MDState with
Maxwell-Boltzmann momenta, then nve_step for integration.
@Luthaf Luthaf merged commit 18ff8de into metatensor:main Mar 26, 2026
10 checks passed
@HaoZeke HaoZeke deleted the feat/torchsim-papercuts branch March 27, 2026 13:48
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.

Paper cuts post torchsim migration

3 participants