Added sample_kind to ModelOutput, without breaking changes#168
Open
Added sample_kind to ModelOutput, without breaking changes#168
sample_kind to ModelOutput, without breaking changes#168Conversation
Luthaf
reviewed
Feb 27, 2026
| } | ||
| void set_sample_kind(std::string sample_kind); | ||
|
|
||
| // For backward compatibility. |
Member
There was a problem hiding this comment.
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; |
Member
There was a problem hiding this comment.
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") { |
Member
There was a problem hiding this comment.
Can you also check that sample_kind is not atom_pair?
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.
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 oldModelOutputmight fail, but old code using the newModelOutputwon't). This is achieved by keeping the possibility to passper_atomas an argument, and setting/getting it as a property, even though from now on the only thingModelOutputstores issample_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