-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative implementation for complex number support #5614
Alternative implementation for complex number support #5614
Conversation
Alternative implementation of aiidateam#5561 These are stored as objects of the form `{'__complex__': True, 'real': x.real, 'imag': x.imag}` with the `__complex__` key being used as the identifier for detecting these objects for deserializations. For serialization/deserialization we use clean_value and a new function deserialize_value. `clean_value` is pulled out of BackendNode and is now done on the level of NodeAttributes and NodeExtras. The deserialization is added to the get/get_many and all routines of these classe Added support for complex attributes in QueryBuilder complex numbers are compared like objects. For comparisons attribute.complex.real/imag can be used Open Questions: - What are the performance implications of the added deserialization? (Since clean_value is already called I think there would be no impact from that side) - Jsonable class should handle complex numbers. Setting attributes work, but the initial check json.loads(json.dumps(...)) fails
For the psql_dos backend the value in filters must be cleaned beforehand since otherwise the cast to JSONB will fail since the complex serialization is not registered in the backend
0f84acb
to
9f746ec
Compare
for more information, see https://pre-commit.ci
Thanks @janssenhenning , apologies for the radio silence on this. Now that we have the hackathon, I think it would be good to have a final discussion about this (maybe in person tomorrow would be good, with those that are interested) and then make a decision on how to best implement this. I went over the issue and your PR again, and I will write a few thoughts down here that I had that I would like to discuss. Current situation
The concept
What is missing
All in all, I think changing this might make sense, and if we do it, we should do it soon. Currently there are no storage backend plugins out there that I know off (other than my own), so we can now still easily change this, but that might change. @giovannipizzi @chrisjsewell do you have time to discuss this tomorrow in person? |
@sphuber Thanks for the detailed answer. Would be happy to discuss today how we could get this into aiida-core 👍 |
See #5561 (comment) for rationale for closing |
Also see #5561
In this PR the serialization isn't done on the low level for each backend but on the
NodeAttributes
/NodeExtras
class. Added a functiondeserialize_value
, which is the counterpart ofclean_value
, which is inserted into the attribute retrieval when the node is stored@sphuber Support for this could also be added on the
BackendNode
and the corresponding extras mixin but I didn't see a clean way to change this without renaming/changing the abstractmethods needed when implementing a backend. In this case you could add something likeset/get_raw_attribute
as the abstractmethods (values are always assumed json-serializable when the node is stored) andset/get_attribute
would add the serialization.atm the
BackendNode
ofpsql_dos
also still callsclean_value
, since this behaviour is explicitly tested on the BackendNode directly in many places.Problems/TODOs:
orm.Entity.fields
interface forQueryBuilder
#5088 would be useful for thisjson.loads(json.dumps(dictionary))
would need to be modified. Simply wrappingdictionary
withclean_value
does not work, since the class wants to support NaN/inf by converting them into strings