Skip to content

Added sample_kind to ModelOutput, without breaking changes#168

Open
pfebrer wants to merge 3 commits intomainfrom
sample_kind
Open

Added sample_kind to ModelOutput, without breaking changes#168
pfebrer wants to merge 3 commits intomainfrom
sample_kind

Conversation

@pfebrer
Copy link

@pfebrer pfebrer commented Feb 26, 2026

This PR substitutes #165.

It also implements sample_kind, with the short-term goal of enabling per-pair targets, but in this case in a way that doesn't break backward compatibility (new code using old ModelOutput might fail, but old code using the new ModelOutput won't). This is achieved by keeping the possibility to pass per_atom as an argument, and setting/getting it as a property, even though from now on the only thing ModelOutput stores is sample_kind.

Thanks to @Luthaf for letting me know that one can set optional arguments in torch exportable classes :)

If you agree with merging this one I will finalize it with some more tests ✌️

📚 Download documentation for this pull-request

}
void set_sample_kind(std::string sample_kind);

// For backward compatibility.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this might be a problem =/

Users of the C++ API are expecting a per_atom field, and this change will break them. We might need a more complex setup with

// used by new code
const std::string& get_sample_kind() const;
void set_sample_kind(std::string sample_kind);

// Used by old C++
[[attribute(deprecated, "use sample_kind")]]
bool per_atom = false;

// Used by old Python
void set_per_atom(bool per_atom);
bool get_per_atom() const;

private:
std::optional<std::string> sample_kind_;

result["quantity"] = self.quantity();
result["unit"] = self.unit();
result["per_atom"] = self.per_atom;
result["sample_kind"] = self.sample_kind;
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 put both fields in the JSON for now, so new code can produce JSON that is understandable by old code.

// Check if the samples names are as expected based on the sample_kind
std::vector<std::string> expected_samples_names;
if (request->per_atom) {
if (request->sample_kind == "atom") {
Copy link
Member

Choose a reason for hiding this comment

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

Can you also check that sample_kind is not atom_pair?

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