Skip to content

Make torchsim able to use the latest metatomic features#181

Open
HaoZeke wants to merge 13 commits intometatensor:mainfrom
HaoZeke:feat/torchsim-papercuts
Open

Make torchsim able to use the latest metatomic features#181
HaoZeke wants to merge 13 commits intometatensor:mainfrom
HaoZeke:feat/torchsim-papercuts

Conversation

@HaoZeke
Copy link
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 added 2 commits March 17, 2026 21: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)
@HaoZeke HaoZeke requested a review from Luthaf March 17, 2026 21:38
HaoZeke added 8 commits March 17, 2026 22:41
- 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
@Luthaf Luthaf changed the title chore(torchsim): address papercuts Make torchsim able to use the latest metatomic features Mar 18, 2026
HaoZeke added 3 commits March 18, 2026 20:08
- 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
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

2 participants