-
In #1917,@borellim raised the issue that distinct instances of the same node are not equal when compared with SummaryThe discussion basically boils down to which equivalence condition should hold (see this comment from @greschd): (a) two nodes are the exact same Python object During the discussion, it was already agreed that (b) should be implemented as a fallback, which was done by @ramirezfranciscof in #4753. What isn't clear yet is if (c) should hold for any node types, i.e. if we should ever compare base equality on the content of a node. Current behaviorFrom the data types in AiiDA-core, AFAIK only Possible changesSeveral options for considering equality by content were considered:
Finally, there is also the question on whether we should consider other data types to compare equality by content, i.e. implement their own Pinging @aiidateam/plugin-developers for comments. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Thanks a lot for the summary @mbercx , very useful. Having read this again, I think I would definitely vote against option 2 as it simply would be too complex to come up with a consistent implementation that would behave intuitively in all cases for all people. I think it is fine to suggest that if users are interested whether the content of two data nodes are identical they define what measure of equality is fine. We can document that they can use the hash, together with the caveats that this comes which, such as only certain attributes being considered. I think this will be the most transparent. Then, whether we choose option 1 or 3: I think there is something to be said for either of them and I would be fine with either of them. I think that ultimately we should just document this clearly. Removing the specific implementation of the That being said, given that these base types were designed more or less to mirror the Python base built ins, there is something to say for them behaving the same in the comparison operator and so adding So since both for me would be fine, maybe the final decision can be done based on backward compatibility: adopting either 1 or 3 could both break existing code, but I think the chances of breaking code by adopting 3 are less compared to adopting 1. So if we had to choose, maybe I would go for 3. TLDR:
|
Beta Was this translation helpful? Give feedback.
-
I agree with all points of @sphuber's comment above: I would go with 3, document we only do it for our base types (listing explicitly what a base type is, to avoid that data types in AiiDA core like StructureData or SingleFileData are mistakenly imagined as "base" types). The only think I don't know is whether we should leave fully open the option to compare also other types by value (and, then, maybe implement a few more, e.g. for SingleFileData); or discourage this behaviour (meaning that we cannot prevent it, but we clearly document that we prefer people don't do it). I guess I would go with the first: we can leave this open, document that most nodes will only be equal if the UUID is the same, and (after fixing |
Beta Was this translation helpful? Give feedback.
-
After discussing this again in the team meeting, the consensus is to move forward with making the Python base types consistently compare by content/value (option 3). So, we'll change/add the For other data types, we will not implement equality comparison by content for now, but also not discourage others from doing so. |
Beta Was this translation helpful? Give feedback.
After discussing this again in the team meeting, the consensus is to move forward with making the Python base types consistently compare by content/value (option 3). So, we'll change/add the
__eq__
method for theDict
data type.For other data types, we will not implement equality comparison by content for now, but also not discourage others from doing so.