-
Notifications
You must be signed in to change notification settings - Fork 62
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 fixes and improvements #647
Conversation
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## master #647 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 88 88
Lines 11663 11702 +39
=========================================
+ Hits 11663 11702 +39
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. |
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.
Thanks for implementing this @stavros11.
Everything looks good to me. Good job!
The unitary() function of a circuit object does not work anymore if a measurement is added. from qibo import gates, models
circuit = models.Circuit(1)
circuit.add(gates.X(0))
print(circuit.unitary())
# array([[0.+0.j, 1.+0.j],
# [1.+0.j, 0.+0.j]])
circuit.add(gates.M(0))
print(circuit.unitary()) raises Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nfs/users/jadwiga.wilkens/qibo/src/qibo/models/circuit.py", line 902, in unitary
return fgate.asmatrix(backend)
File "/nfs/users/jadwiga.wilkens/qibo/src/qibo/gates/special.py", line 102, in asmatrix
return backend.asmatrix_fused(self)
File "/nfs/users/jadwiga.wilkens/qibo/src/qibo/backends/numpy.py", line 117, in asmatrix_fused
gmatrix = gate.asmatrix(self)
File "/nfs/users/jadwiga.wilkens/qibo/src/qibo/gates/measurements.py", line 140, in asmatrix
raise_error(
File "/nfs/users/jadwiga.wilkens/qibo/src/qibo/config.py", line 46, in raise_error
raise exception(message)
NotImplementedError: Measurement gates do not have matrix representation. |
Thanks for reporting this. It was fixed and tested in the latest push. |
This PR implements various improvements in measurements, particularly:
circuit.measurement_gate
and adds all measurements (with and without collapse) in the gate queue.collapse=True
option was not used when measuring a qubit that is reused then it is enabled automatically, as I am not aware of any other physical way that a qubit can be reused without collapsing it.result = c.add(gates.M(0, 1, collapse=True))
which was out of sync with previous versions and the docs (thanks @igres26).Now the
result
is aMeasurementResult
object which hasresult.samples()
,result.frequencies()
and alsoresult.symbols
which is a list ofsympy.Symbols
that can be used to condition later gates on the measurement outcomes.result
object returned byc.add
is now available for non-collapse measurements too.For example
then
r
is aCircuitResult
object that contains the final state vector and all measurements.m0
is aMeasurementResult
object that contains the measurements of qubit 0.m1
is aMeasurementResult
object that contains the measurements of qubit 1.This is complete in terms of developments but I am labeling it as "do not merge" as I would like to make sure it plays well with qibolab before merging.