deprecate(ModelOutput.quantity): mark quantity field as deprecated#199
Open
HaoZeke wants to merge 6 commits intometatensor:mainfrom
Open
deprecate(ModelOutput.quantity): mark quantity field as deprecated#199HaoZeke wants to merge 6 commits intometatensor:mainfrom
HaoZeke wants to merge 6 commits intometatensor:mainfrom
Conversation
7b73a2a to
409b32c
Compare
Luthaf
reviewed
Apr 7, 2026
| /// quantity of the output (e.g. energy, dipole, …). If this is an empty | ||
| /// string, no unit conversion will be performed. | ||
| /// @deprecated This field is no longer required for unit conversion. | ||
| /// The unit parser determines dimensions from the expression itself. |
Member
There was a problem hiding this comment.
Can you do a [[deprecated]] atribute instead, both here and on the setter?
metatomic-torch/src/model.cpp
Outdated
|
|
||
| void ModelOutputHolder::set_quantity(std::string quantity) { | ||
| if (!quantity.empty()) { | ||
| TORCH_WARN( |
Member
There was a problem hiding this comment.
Should be a torch deprecation warning, there is a special macro for it
| yield | ||
| captured = capfd.readouterr() | ||
| # the code should not print anything to stdout or stderr | ||
| # except for expected deprecation warnings |
Member
There was a problem hiding this comment.
These should be explicitly caught at the place where they are emitted in the test, by using the capfd fixture in the tests. I'm doing this in a couple of place already
Comment on lines
+513
to
+517
| # Note: Deprecation warning for quantity is emitted from C++ when | ||
| # ModelOutput is constructed with non-empty quantity. | ||
| # We don't warn here because TorchScript can't handle | ||
| # DeprecationWarning. | ||
|
|
Member
There was a problem hiding this comment.
we should remove the code here that uses quantity
| yield | ||
| captured = capfd.readouterr() | ||
| # the code should not print anything to stdout or stderr | ||
| # except for expected deprecation warnings |
| yield | ||
| captured = capfd.readouterr() | ||
| # the code should not print anything to stdout or stderr | ||
| # except for expected deprecation warnings |
Luthaf
reviewed
Apr 7, 2026
Comment on lines
+50
to
+53
| # consume the once-per-process quantity deprecation warning from C++ | ||
| captured = capfd.readouterr() | ||
| if captured.err: | ||
| assert "ModelOutput.quantity is deprecated" in captured.err |
Member
There was a problem hiding this comment.
We can change the code in the test LJ to remove the need to catch this warning
The quantity field on ModelOutput is no longer required for unit
conversion -- the unit parser now determines dimensions from the
expression itself. Setting a non-empty quantity emits a TORCH_WARN
deprecation notice from C++.
Input unit conversion in _convert_systems_units now gates on
requested.unit instead of requested.quantity, and the redundant
set_info("quantity", ...) call is removed.
- Remove quantity= parameter from ModelOutput calls in tests - Add pytest filterwarnings for the new deprecation warnings - Update conftest.py stderr filters for C++ TORCH_WARN output - Update C++ test warning handler to handle multiple warnings - Check unit info instead of removed quantity info in ASE tests
…and remove quantity-based unit conversion - Add [[deprecated]] attribute to quantity() getter and set_quantity() in model.hpp for compile-time warnings - Switch from TORCH_WARN to TORCH_WARN_DEPRECATION with std::once_flag in set_quantity() for proper runtime deprecation signaling - Remove quantity-based unit conversion logic from model.py; unit conversion now uses declared/requested unit fields directly - Revert conftest.py files to strict stderr checking; catch deprecation warnings explicitly at emission sites using capfd in affected tests and fixtures - Add filterwarnings for ModelOutput.quantity DeprecationWarning in ASE and torchsim pyproject.toml
…antity deprecation Handle the once-per-process quantity deprecation warning in: - model_loading.py lj_model fixture (torchsim) - examples.py test_export_atomistic_model (torch) - heat_flux.py model/model_in_kcal_per_mol fixtures (torch + ase) - heat_flux.py test_wrap (ase)
The reviewer pointed to the existing torch macro; the once_flag was unnecessary custom wrapping. Also add capfd to the remaining torch heat_flux tests that create ModelOutput(quantity=...) in their body.
…f per-test capfd Move C++ TORCH_WARN_DEPRECATION stderr filtering into the autouse conftest fixture via regex, removing the need to add capfd to every individual test and fixture that loads models with quantity set.
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.
The quantity field is no longer required for unit conversion since the unit parser determines dimensions from the expression itself.
Changes:
Contributor (creator of pull-request) checklist
Reviewer checklist