-
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
Measurement in Pauli basis #799
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #799 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 47 47
Lines 5726 5752 +26
=========================================
+ Hits 5726 5752 +26
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Does this also work for when a multi-qubit measurement Also, it would be good to pass just a string instead of the c = Circuit(2)
c.add(gates.M(0, 1, basis="XY") |
After discussing with @renatomello, extending this to support a different basis for each qubit measured could be useful. In summary this could accept:
The string representation proposed in the comment above could also be good as it is more compact, however I am a bit against supporting many different types as inputs to a function as it is harder to implement, maintain and document and as a result could also be more confusing for users. With the above addition we already accept two types (gate class or list) and if we add strings we go up to four which could be complicated to handle. @scarrazza let me know what you think. |
I would suggest to keep the gate object and list, but avoid the string because we don't use this interfacing mechanism (string-gate) anywhere in qibo, and it is easier to debug for the user. |
Accepting circuits as initial states
Following the discussion today, we agreed to add tests and merge. |
I fixed the conflicts and I also implemented the list for basis as I realized it was a quick update. @renatomello if you like give a try and let me know if it is what you had in mind. Your example should be modified to c = Circuit(2)
c.add(gates.M(0, 1, basis=[gates.X, gates.Y]) since we decided to not accept strings. |
I tried this code from qibo import gates
from qibo.models import Circuit
nqubits = 2
circuit = Circuit(nqubits)
basis = "XY"
basis = [getattr(gates, pauli) for pauli in basis]
circuit.add(gates.M(*range(nqubits), basis=basis))
print(circuit.draw()) and the gates are being added after the measurement. |
Thanks for checking, should be fixed now. |
It works now. |
Fixes #720. I am copying here the TODO list from #720 (comment)
basis
argument forgates.M
which accepts gate objects (instead of strings).I implemented the first point. @andrea-pasquale @Edoardo-Pedicillo let me know if you would like to have a look at any of the others.
Note that as discussed using the
basis
argument in the measurement gate will add additional gates that rotate to this basis before the measurement. For example:will result to
Also, I implemented the basis rotation only for the Pauli gates (X, Y, Z) as this was requested in the original issue, however it may be possible to do it for any gate. Essentially for a single qubit gate G we need to solve U^dagger Z U = G for U.
Checklist: