-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Implement TrialResult JSON serialization #2576
Implement TrialResult JSON serialization #2576
Conversation
Okay I've added a special case for binary-valued arrays. Also, note that this serialization method does not work when the measurement values are Python ints or arbitrary Python objects, since it uses numpy.save with "allow_pickle" set to False to ensure portability. The measurement values must be fixed-width numerical values. I don't think this is a practically relevant limitation. @Strilanc PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking this over, I think we should do something slightly different.
Instead of special casing the numpy array storage for this single method, we should include np.ndarray
as one of our supported types and do all the fancy bitpacking stuff there. That way the benefit will be shared across the library.
This does have some backwards compatibility constraints. We need to continue supporting numpy arrays serialized as a raw list.
Rough list of things to be done:
|
@Strilanc I'm having trouble with (2.). When the JSON deserializer sees a list it will automatically treat it as such; how do you cause it to trigger specialized code upon encountering a generic list that it has no way of knowing originated as a Numpy array? |
(2.) may be possible by implementing our own JSONDecoder subclass... |
But still the issue remains which is that the decoder has no way of knowing whether the list originated from a Numpy array or not. |
I'm not sure I agree with this. Decaying to lists by default plays nicest with json. There's automatic interop with other languages and it's eyeball-able. For special cases where you've got a massive ol' chunk of data (particularly bitstrings or wavefunctions or things which aren't eye-ballable anyways) they can be treated as a binary blob |
Alright, it's fine to just do the one case. We can target specific ones when we run into them, and extract common methods when needed. |
@Strilanc so we're good to leave this PR as is then? |
This is an alternative to #2561 that works for qudits. As mentioned there, it is 8x less space efficient for qubits. We could have a special case to handle binary-valued measurements but maybe we want to be consistent and keep the code simple? I don't know. I should add more test cases but I just wanted to put this out to get feedback on.