Skip to content

Add an O(3)-symmetrized atomistic model wrapper - #294

Closed
MichelangeloDomina wants to merge 18 commits into
metatensor:mainfrom
MichelangeloDomina:review/symmetrized-model-progressive
Closed

Add an O(3)-symmetrized atomistic model wrapper#294
MichelangeloDomina wants to merge 18 commits into
metatensor:mainfrom
MichelangeloDomina:review/symmetrized-model-progressive

Conversation

@MichelangeloDomina

@MichelangeloDomina MichelangeloDomina commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds metatomic.torch.symmetrized_model: wrap an exported AtomisticModel to
average its predictions over O(3) with a finite rotation quadrature, and to
measure how far the underlying model is from being equivariant.

Everything is selected through regular output requests:

Requested output Result
<name> O(3) average of the underlying output
o3::variance::<name> per-sample equivariance variance
o3::character_projection::<name> squared character-projection contribution per irrep

SymmetrizedModel.wrap() returns a regular exportable AtomisticModel
(metadata, capabilities, neighbor lists, and custom inputs are carried over),
so the wrapped model can be used anywhere the original could, including
TorchScript export.

The conventions (quadrature, variance definition, irrep bookkeeping in
TensorMap keys) are documented in docs/src/torch/reference/symmetrized-model.rst.

Limitations

  • the quadrature is exact only up to a maximal angular momentum; convergence
    should be checked by increasing max_o3_lambda_grid;
  • CPU and CUDA only, float32/float64;
  • explicit TensorBlock gradients are not supported (PyTorch autograd through
    returned values works).

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?

@ppegolo
ppegolo force-pushed the review/symmetrized-model-progressive branch from c2acacf to 7e23329 Compare July 28, 2026 09:06
@ppegolo
ppegolo marked this pull request as ready for review July 28, 2026 12:42
@ppegolo
ppegolo requested review from Luthaf and removed request for ppegolo July 28, 2026 13:20

@Luthaf Luthaf left a comment

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.

I only checked the code, I'll try to do a pass on the tests ASAP

Comment thread docs/src/torch/reference/symmetrized-model.rst Outdated
Comment thread docs/src/torch/reference/symmetrized-model.rst Outdated
Comment thread docs/src/torch/reference/symmetrized-model.rst Outdated
Comment on lines +13 to +33
Output requests
---------------

The requested output name selects both the source output and the calculation:

.. list-table::
:header-rows: 1

* - Requested and returned name
- Result
* - ``<name>``
- O(3) average of the underlying ``<name>`` output
* - ``o3::variance::<name>``
- component-averaged equivariance variance of ``<name>``
* - ``o3::character_projection::<name>``
- unnormalized squared character-projection contributions of ``<name>``

``<name>`` is preserved verbatim. It can therefore be a standard quantity, a
variant such as ``energy/pbe``, or a custom name such as
``mtt::feature::node``. For example,
``o3::variance::energy/pbe`` evaluates the underlying ``energy/pbe`` output.

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.

This is not very clear, but I can rephrase when everything else is done here =)

Comment thread docs/src/torch/reference/symmetrized-model.rst Outdated
Comment thread python/metatomic_torch/metatomic/torch/o3/_projections.py
Comment thread python/metatomic_torch/metatomic/torch/symmetrized_model/_projections.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/symmetrized_model/_wigner_storage.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/symmetrized_model/_model.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/symmetrized_model/_model.py Outdated
@ppegolo
ppegolo force-pushed the review/symmetrized-model-progressive branch from f551943 to 8f87505 Compare July 30, 2026 11:26

@Luthaf Luthaf left a comment

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.

Looks good overall, I mostly have small nits comments.

The one larger thing is that we have two copies of the O3 transformation code, we should only have one.

I only looked at the code, second review for the test coming after that!

Comment thread metatomic-torch/CHANGELOG.md Outdated
Comment thread python/metatomic_torch/metatomic/torch/_quantities.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/model.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/o3/_decompose.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/o3/_decompose.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/o3/_symmetrized.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/o3/_symmetrized.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/o3/_symmetrized.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/o3/_tranformations.py Outdated
Comment thread python/metatomic_torch/metatomic/torch/o3/_utils.py Outdated

@Luthaf Luthaf left a comment

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.

A lot of tests are explicitly testing the private API. I would rather not (it makes changing the implementation a lot harder) unless there is a good reason for it.

We can also likely reduce the number of tests by re-using the O3 transformation code & tests.

Comment thread python/metatomic_torch/tests/symmetrized_model.py Outdated
Comment thread python/metatomic_torch/tests/symmetrized_model.py Outdated
Comment thread python/metatomic_torch/tests/symmetrized_model.py Outdated
Comment thread python/metatomic_torch/tests/symmetrized_model.py Outdated
Comment thread python/metatomic_torch/tests/symmetrized_model.py Outdated
Comment thread python/metatomic_torch/tests/symmetrized_model.py Outdated
Comment thread python/metatomic_torch/tests/symmetrized_model.py
Comment thread python/metatomic_torch/tests/symmetrized_model.py
Comment thread python/metatomic_torch/tests/symmetrized_model.py Outdated
Comment thread python/metatomic_torch/tests/symmetrized_model.py Outdated
ppegolo added 7 commits August 5, 2026 16:15
metatrain does not rename deprecated target names on checkpoint upgrade:
models keep answering to their native (plural) spellings, and metatomic's
AtomisticModel is the alias bridge for engines. Share that bridge's table
and name normalization in _quantities.py and use it when categorizing
outputs for decomposition, so wrapped models trained with plural names
still get per-irrep diagnostics.
O3Transformation.transform_systems and .transform_tensormap cover the
same functionality; keeping both meant a second validation layer and a
second entry point for every operation. transform_tensormap now accepts
integer system_ids of any dtype, converting to long internally.
@Luthaf

Luthaf commented Aug 7, 2026

Copy link
Copy Markdown
Member

merged in #300

@Luthaf Luthaf closed this Aug 7, 2026
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.

3 participants