Skip to content

deprecate(ModelOutput.quantity): mark quantity field as deprecated#199

Open
HaoZeke wants to merge 6 commits intometatensor:mainfrom
HaoZeke:morfixes
Open

deprecate(ModelOutput.quantity): mark quantity field as deprecated#199
HaoZeke wants to merge 6 commits intometatensor:mainfrom
HaoZeke:morfixes

Conversation

@HaoZeke
Copy link
Copy Markdown
Member

@HaoZeke HaoZeke commented Apr 3, 2026

The quantity field is no longer required for unit conversion since the unit parser determines dimensions from the expression itself.

Changes:

  • Add deprecated documentation to C++ header
  • Add TORCH_WARN in C++ setter when quantity is non-empty
  • Add DeprecationWarning in Python when quantity validation runs
  • Update documentation with deprecation notice
  • Add deprecation entries to CHANGELOG

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 force-pushed the morfixes branch 3 times, most recently from 7b73a2a to 409b32c Compare April 5, 2026 00:50
@HaoZeke HaoZeke requested a review from Luthaf April 5, 2026 01:06
/// 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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you do a [[deprecated]] atribute instead, both here and on the setter?


void ModelOutputHolder::set_quantity(std::string quantity) {
if (!quantity.empty()) {
TORCH_WARN(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above

yield
captured = capfd.readouterr()
# the code should not print anything to stdout or stderr
# except for expected deprecation warnings
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as above

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can change the code in the test LJ to remove the need to catch this warning

HaoZeke added 3 commits April 7, 2026 17:02
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
HaoZeke added 3 commits April 7, 2026 19:59
…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.
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.

2 participants