Skip to content

Add explicit gradients to the LLPR energy ensemble - #1210

Merged
ppegolo merged 2 commits into
metatensor:mainfrom
ppegolo:energy-ensemble-explicit-gradients
Jul 24, 2026
Merged

Add explicit gradients to the LLPR energy ensemble#1210
ppegolo merged 2 commits into
metatensor:mainfrom
ppegolo:energy-ensemble-explicit-gradients

Conversation

@ppegolo

@ppegolo ppegolo commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

The energy_ensemble output can now return positions and strain gradients, so one can get per-ensemble-member forces and stresses straight from the exported model, and can use their spread as an uncertainty estimate or propagate the ensemble to other observables (e.g., phonon bands).

In other words, this feature is required to be able to easily request conservative forces and stress ensembles for a model.

To comply with metatomic, the properties of the energy ensemble TensorMap had to be changed to energy, with a single column enumerating members. Non-energy targets keep the previous ["ensemble_member", <target>] format.

The gradients have to be computed in a loop over members instead of setting is_grads_batched=True to compy with TorchScript.

LLPR tests tend to not use shared testing utilities, so I added a new test file. Probably it could be made to use the shared utilities more, but I think it requires modifying them enough to go outside of the scope of the current PR, so it might be delegated to a different one in the future.

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)?

Maintainer/Reviewer checklist

  • CHANGELOG updated with public API or any other important changes?
  • GPU tests passed (maintainer comment: "cscs-ci run")?

📚 Documentation preview 📚: https://metatrain--1210.org.readthedocs.build/en/1210/

@ppegolo
ppegolo force-pushed the energy-ensemble-explicit-gradients branch 2 times, most recently from 801da6a to 476ae9c Compare July 21, 2026 13:28
@ppegolo
ppegolo requested a review from sofiia-chorna July 21, 2026 14:50
@ppegolo

ppegolo commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

cscs-ci run

@sofiia-chorna sofiia-chorna left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks a lot! i added some questions

Comment thread src/metatrain/llpr/tests/test_energy_ensemble_gradients.py Outdated
Comment thread src/metatrain/llpr/model.py Outdated
Comment thread src/metatrain/llpr/model.py
Comment thread src/metatrain/llpr/model.py
Comment thread src/metatrain/llpr/model.py
@ppegolo
ppegolo force-pushed the energy-ensemble-explicit-gradients branch from 2c86267 to 16f5630 Compare July 24, 2026 11:42

@sofiia-chorna sofiia-chorna left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks! looks good on my side

@sofiia-chorna

Copy link
Copy Markdown
Collaborator

cscs-ci run

@ppegolo
ppegolo merged commit 279e82d into metatensor:main Jul 24, 2026
22 checks passed
@ppegolo
ppegolo deleted the energy-ensemble-explicit-gradients branch July 24, 2026 12:55
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