Skip to content

Conversation

@PicoCentauri
Copy link
Contributor

@PicoCentauri PicoCentauri commented Oct 17, 2025

This PR adds a couple of updates to the variants:

  • Allow no default unit present: i.e. now allowed are outputs like "energy/A", "energy/B" without "energy" being present.
  • Add a backwards compatible description attribute to ModelOutputs.
  • Added pick_variant function that will pick a variant based on a name (like "energy"), a ModelCapabilities object and an optional desired_variant. The function will try to pick the user choice and if not given either pick the non-variant or error giving the provided variances. I am not happy with the parameter naming and order. We can discuss it

TODO

  • Update CXX tests
  • Use pick_variant in ase calculator
  • Update Python tests
  • Update docs for variants

Reviewer checklist

  • CHANGELOG updated with public API or any other important changes?

📚 Download documentation for this pull-request

@PicoCentauri PicoCentauri marked this pull request as ready for review October 24, 2025 15:01
@PicoCentauri PicoCentauri force-pushed the variant-additions branch 2 times, most recently from 7ca4e3d to b52ed40 Compare October 24, 2025 15:15
Comment on lines 187 to 189
if uncertainty_threshold is not None:
self._energy_uq_key = pick_output(
"energy_uncertainty", outputs, resolved_variants["energy_uncertainty"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pick_output will raise an error here if the uncertainty_threshold is a number (which is the default) but the model does not have an energy_uncertainty in its outputs. I think this is what one actually wants. If a user desires an uncertainty warning but the model can't do it - we should error.

But this change kinda leads to that one now have to set the uncertainty_threshold to None for all models without an uncertainty output. Before we silently ignored this. We can also change the default of uncertainty_threshold from 0.1 to None.

Copy link
Member

Choose a reason for hiding this comment

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

So I think the behavior should be

  • by default, if the model has an energy_uncertainty output, we use it with a threshold of 0.1 eV/atom without the user having to do anything.
  • if the users specifies a variant for energy_uncertainty but does not touch the threshold, we use the same 0.1 eV/atom threshold
  • the user can explicitly opt-out of the warning by setting the threshold to None.

In the code, we could try to check if there is an energy_uncertainty output before calling pick_output to resolve it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay we can do a check if energy_uncertainty or a variant is in any of the output keys.

Copy link
Member

Choose a reason for hiding this comment

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

I would only check if one variant is present, the one that would be used by pick_outout.

Comment on lines 187 to 189
if uncertainty_threshold is not None:
self._energy_uq_key = pick_output(
"energy_uncertainty", outputs, resolved_variants["energy_uncertainty"]
Copy link
Member

Choose a reason for hiding this comment

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

So I think the behavior should be

  • by default, if the model has an energy_uncertainty output, we use it with a threshold of 0.1 eV/atom without the user having to do anything.
  • if the users specifies a variant for energy_uncertainty but does not touch the threshold, we use the same 0.1 eV/atom threshold
  • the user can explicitly opt-out of the warning by setting the threshold to None.

In the code, we could try to check if there is an energy_uncertainty output before calling pick_output to resolve it.

void ModelCapabilitiesHolder::set_outputs(torch::Dict<std::string, ModelOutput> outputs) {
std::unordered_map<std::string, std::unordered_set<std::string>> variants;

std::unordered_map<std::string, std::vector<std::string>> units;
Copy link
Member

Choose a reason for hiding this comment

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

I would not call this units, variants was fine though

);

// check for variant description warning
#if TORCH_VERSION_MAJOR >= 2 && TORCH_VERSION_MINOR >= 0
Copy link
Member

Choose a reason for hiding this comment

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

we require torch >=2.1, so this check is not needed

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