Skip to content

Support force and stress uncertainty and ensembles - #154

Open
ppegolo wants to merge 3 commits into
derive-model-infofrom
forces_uq
Open

Support force and stress uncertainty and ensembles#154
ppegolo wants to merge 3 commits into
derive-model-infofrom
forces_uq

Conversation

@ppegolo

@ppegolo ppegolo commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Uncertainty estimates were limited to the energy. This adds them for forces and
stresses, through get_forces_uncertainty, get_stress_uncertainty, their
_ensemble counterparts, and get_forces_and_stress_ensemble, which computes
both 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

@ppegolo
ppegolo force-pushed the forces_uq branch 2 times, most recently from 1d9139c to cb5e5c9 Compare July 9, 2026 13:51
@ppegolo
ppegolo marked this pull request as draft July 28, 2026 14:53
@ppegolo
ppegolo marked this pull request as ready for review August 13, 2026 07:09
@ppegolo
ppegolo changed the base branch from main to update-metatrain-2026.4 August 13, 2026 09:14
@ppegolo ppegolo changed the title Implement force and stress uncertainty Support force and stress uncertainty and ensembles Aug 13, 2026
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
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.
@ppegolo
ppegolo requested a review from abmazitov August 13, 2026 16:15
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.

1 participant