Added sample_kind to ModelOutput, without breaking changes#168
Open
Added sample_kind to ModelOutput, without breaking changes#168
sample_kind to ModelOutput, without breaking changes#168Conversation
Luthaf
reviewed
Feb 27, 2026
4b3c32d to
87dc377
Compare
Author
|
This is ready for a final look. I checked that one can take the conda |
Luthaf
reviewed
Mar 16, 2026
dff557b to
ea5e7fd
Compare
Member
|
Do not merge before #186, we need to have at least one release of metatomic-ase that works with an already released version of metatomic-torch |
9353d37 to
4df02e3
Compare
…lity Co-Authored-By: Guillaume Fraux <guillaume.fraux@epfl.ch>
…ts and migrate call sites Mirrors the morfixes pattern for `ModelOutput.quantity`: keep the runtime `TORCH_WARN_DEPRECATION` on the C++ `per_atom` getter/setter, filter it out of test stderr via regex, ignore the matching Python `DeprecationWarning` in pyproject filterwarnings, and migrate internal callers to `sample_kind`. Python (metatomic-torch) - Migrate `_get_requested_inputs` dedup check from `per_atom` to `sample_kind` so the internal path no longer trips its own deprecation. - Add a `.. deprecated::` block to the `per_atom` property docstring in documentation.py. Tests / packaging - conftest.py for all three subpackages: regex-strip the C++ `TORCH_WARN_DEPRECATION` line for `per_atom` from stderr in the autouse fail-on-output fixture, tolerating both Torch 2.3 (`[W model.cpp:N]`) and Torch 2.11+ (`[W<MMDD> HH:MM:SS.fractZ model.cpp:N]`) prefixes. Any other unexpected stderr still fails the test. - `pyproject.toml` for all three subpackages: ignore the matching Python `DeprecationWarning` so tests exercising the field directly do not blow up under `-W error`. - Migrate `ModelOutput(per_atom=...)` constructions in `heat_flux.py`, `tests/heat_flux.py`, and `tests/calculator.py` to `sample_kind=...`. Changelog: add a Deprecated entry for `ModelOutput.per_atom`.
Follow-ups to the per_atom deprecation commit: - `python/metatomic_ase/tests/calculator.py`: collapse the `velocities` ModelOutput constructor to a single line to satisfy `ruff format`. - `python/metatomic_torch/tests/outputs.py`: drop the `assert message in captured.err` checks. With the new Python-layer `ignore:`per_atom`...:DeprecationWarning` filter, TORCH_WARN routes through `PyErr_WarnEx` and is silently dropped, so stderr stays empty. The `pytest.warns` checks still verify that the Python `DeprecationWarning` is emitted.
Torch 2.3 writes the C++ `TORCH_WARN_DEPRECATION` directly to stderr even when the Python-layer `DeprecationWarning` filter is `ignore`, while Torch 2.11 routes entirely through `PyErr_WarnEx` and leaves stderr empty. Asserting `captured.err == ""` mid-test fails on Torch 2.3. Delete the mid-test `capfd.readouterr()` checks and rely on the autouse `fail_test_with_output` fixture in `conftest.py`, which already regex-strips the per_atom warning from stderr at end-of-test across both torch versions. The `pytest.warns(...)` assertions still verify that each getter/setter emits a Python `DeprecationWarning`.
The test previously triggered the per_atom deprecation path through its ModelOutput construction. Rewriting to sample_kind keeps the test on the non-deprecated API, so nothing in the test codebase still relies on the per_atom shim (outside tests that specifically exercise it).
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.
This PR substitutes #165.
It also implements
sample_kind, with the short-term goal of enabling per-pair targets, but in this case in a way that doesn't break backward compatibility (new code using oldModelOutputmight fail, but old code using the newModelOutputwon't). This is achieved by keeping the possibility to passper_atomas an argument, and setting/getting it as a property, even though from now on the only thingModelOutputstores issample_kind.Thanks to @Luthaf for letting me know that one can set optional arguments in torch exportable classes :)
If you agree with merging this one I will finalize it with some more tests ✌️
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request
⚙️ Download Python wheels for this pull-request (you can install these with pip)
📚 Download documentation for this pull-request