-
Notifications
You must be signed in to change notification settings - Fork 61
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
Serialization of measurements #1431
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1431 +/- ##
=======================================
Coverage 99.94% 99.94%
=======================================
Files 78 78
Lines 11317 11324 +7
=======================================
+ Hits 11311 11318 +7
Misses 6 6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Some suggestions, but they are not incredibly relevant, as the whole measurement storage is a bit convoluted (with many references everywhere), and a greater action should be taken to simplify it (not now, possibly as part of qibo-core
).
The relevant part instead it's that a test is missing. It would be nice to have a test failing before this PR, and now working.
Try to keep features' implementation as separate as possible (and separate from bug fixes). (Ok, this is really a tiny one, but it was worth to mention the general rule) |
Yeah, let's say that rather than a new feature is a side effect of the fix in this case, but I fundamentally agree. |
Ok, I should have addressed everything now, except the |
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.
The test is effective and passing.
Thanks @BrunoLiegiBastonLiegi!
Hello guys, I've installed qibo from this source branch and checked if the with open(circuit_path, "r") as f:
raw = json.load(f)
c = qibo.Circuit.from_dict(raw)
r = c(nshots=settings.get("nshots"))
print(f"Results: {r.samples()}")
|
Do you have a simpler example using only qibo primitives? |
I did a little bit of investigation. It seems that the circuit serialization done with The script is the following: import json
import qibo
c = qibo.Circuit(5)
c.add(qibo.gates.M(0))
with open("circuit.json", "w") as f:
json.dump(c.raw, f)
print(c.raw) Here you have the results: Output on
Output on
It seems that there's a mismatch when loading a circuit on the QPU that was created on CPU and viceversa. The code that raises the following errors is: import json
import qibo
with open("circuit.json") as f:
raw = json.load(f)
c = qibo.Circuit.from_dict(raw) If I create the circuit on CPU => load it on QPU:
If I create the circuit on QPU => load it on CPU:
|
The output on Similarly below, the CPU -> QPU loading seems to fail because the I would say that the CPU and QPU are using two different versions of qibo:
|
Let me check again the environments. If the branch mismatch is the cause, then we are fine. |
I have just tried your code and it works, no crashes. |
Yes, I agree. I was loading the wrong environment on the QPU, my bad. |
This addresses the bug #1426 by implementing a proper serialization of measurement gates and their result.
Furthermore, the possibility to specify the
basis
of measurement gates with strings (for instance"Z"
or["X", "Z", "Y"]
) has been added.I also made some minor modifications to
MeasurementResult
, and I would also like to remove thecircuit
attribute from it. At the moment it is only used to generate the samples when they are not available. However, as I see it, theMeasurementResult
should always be associated with the samples.Checklist: