Support force and stress uncertainty and ensembles - #154
Open
ppegolo wants to merge 3 commits into
Open
Conversation
ppegolo
force-pushed
the
forces_uq
branch
2 times, most recently
from
July 9, 2026 13:51
1d9139c to
cb5e5c9
Compare
ppegolo
marked this pull request as draft
July 28, 2026 14:53
ppegolo
marked this pull request as ready for review
August 13, 2026 07:09
Uncertainty estimates were previously limited to the energy. This adds them for forces and stresses, via two routes that the calculator exposes through `get_forces_ensemble` / `get_forces_uncertainty`, the stress equivalents, and `get_forces_and_stress_ensemble`: - "conservative": the energy ensemble is differentiated with respect to positions and cell, so each member's forces are the gradient of that member's energy and are conservative by construction. The per-member mean over atoms is removed to restore translational invariance. Forces and stresses share a single backward pass when asked for together. - "direct": models carrying a separately-trained vectorial force head expose `mtt::aux::non_conservative_forces_ensemble` and the matching `_uncertainty` output, sampled in that head's last-layer weight space. This is much cheaper than differentiating the ensemble, but the forces are not conservative. The two are genuinely different estimates, not two implementations of one, so the method is selectable. It defaults to whichever matches the regime the calculator was built in, and in conservative mode the direct ensemble is re-centered on the conservative forces so that only the spread differs. Stress has no "direct" counterpart: models do not carry an ensemble for `non_conservative_stress`.
The list of models with uncertainty estimates is gone, so the errors of the force and stress ensembles now say what the documentation says, and the calculator is asked whether the model provides an uncertainty at all.
ppegolo
changed the base branch from
update-metatrain-2026.4
to
derive-model-info
August 13, 2026 15:26
The calculator was two thirds uncertainty estimates, most of it plumbing: requesting outputs from the model and reshaping what comes back. That part now lives in `_uncertainty`, taking what it needs as arguments, and the calculator is left with the questions only it can answer: whether the model provides these outputs, and which atoms to run on.
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.
Uncertainty estimates were limited to the energy. This adds them for forces and
stresses, through
get_forces_uncertainty,get_stress_uncertainty, their_ensemblecounterparts, andget_forces_and_stress_ensemble, which computesboth in one backward pass.
Forces come either from differentiating the energy ensemble, which keeps them
conservative, or from a direct force head for the models that have one, which is
much cheaper but not conservative. The two are different estimates rather than
two ways of getting one, so the method is selectable, and defaults to whichever
matches how the calculator was built. Stress only has the first: no model
carries an ensemble for
non_conservative_stress.No checkpoint on HuggingFace has a direct force head yet, so that route only
works with locally trained models.
One of the points to discuss: whether to actually default to NC-force uncertainty, when
available, as conservative ones are very expensive