-
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
Fix to classical registers in to_qasm #1284
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1284 +/- ##
==========================================
- Coverage 99.85% 99.84% -0.01%
==========================================
Files 73 73
Lines 10690 10689 -1
==========================================
- Hits 10674 10672 -2
- Misses 16 17 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I think the issue with #1283 is in from qibo import Circuit, gates
qasm = 'OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[2];\ncreg m0[2];\ny q[0];\nx q[1];\nmeasure q[0] -> m0[0];\nmeasure q[1] -> m0[1];'
qibo_cirq = Circuit.from_qasm(qasm)
for gate in qibo_cirq.queue:
if isinstance(gate, gates.M):
print(gate, gate.qubits, gate.register_name) prints
instead of
that I would expect. This has undesired effects if the circuit is simulated: result = qibo_cirq(nshots=10000) then
Allowing different measurements with the same |
Ah I see. When I rewrote the
should not raise an error. In my opinion, it is perfectly fine to, in some sense, 'append' measurements to a register. Therefore, now I see three different options:
are not gonna be associated to the merged measurement anymore.
Probably the last one is indeed the easiest and less bug prone option... |
Thanks for explaining, that makes sense. I agree that it is fine to provide this possibility, but of course as it is implemented now there is this side-effect when asking for
I have not thought in detail, but it seems possible to make
I agree with this. The easiest solution is to just raise an error and not support reusing register names and only fix the qasm issue in this PR. We could also open an issue in case we wish to implement this feature later. From the user side doing c.add(gates.M(0, register="m0"))
c.add(gates.M(1, register="m0")) is not much different than c.add(gates.M(0, 1, register="m0")) but there may be an application that I am missing that the former could be useful. |
The only case that comes to my mind is whether you would like to measure different qubits at different times but in the same classical register. Thus, for instance something like this: c.add(gates.H(0))
c.add(gates.M(0, register="m0"))
c.add(gates.H(1))
c.add(gates.CX(1,0))
c.add(gates.M(1, register="m0")) but this is very niche, and probably there's no real reason to have both the measurements in the same register anyway. |
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! It works for me.
Small fix to how the classical registers and measurements are converted to qasm.
This should close #1283
Checklist: