-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Combine circuits with clbits onto those with none #7823
Conversation
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.
Sorry this took a while. This generally looks fine to me as a special case utility. Please could you add a "feature" release note as well, and a test of this compose
path with registerless clbits?
@jakelishman I think this is done now. Incorporating registerless bits was a bit tricky because they can be arbitrarily mixed and matched with registers. As there is no (not deprecated or raising) way of querying if a bit has a register, I basically had to resort to looping over bits to see if they are in any registers. |
There is now, though it wasn't added when the original registerless bits implementation was added for some reason. You can do |
|
In [8]: from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
...: qr = QuantumRegister(5)
...: cr = ClassicalRegister(5)
...: qc = QuantumCircuit()
...: qc.add_bits(qr[0:3])
...: qc.add_bits(cr[2:4])
...: qc.qregs, qc.cregs
Out[8]: ([], [])
In [9]: qc.qubits, qc.clbits
Out[9]:
([Qubit(QuantumRegister(5, 'q3'), 0),
Qubit(QuantumRegister(5, 'q3'), 1),
Qubit(QuantumRegister(5, 'q3'), 2)],
[Clbit(ClassicalRegister(5, 'c3'), 2), Clbit(ClassicalRegister(5, 'c3'), 3)])
In [10]: qc.add_register(qr)
...: qc.add_register(cr)
...: # Some of the bits from these registers are already in the circuit,
...: # but neither of these calls raise.
...: qc.qregs, qc.cregs
Out[10]: ([QuantumRegister(5, 'q3')], [ClassicalRegister(5, 'c3')])
In [11]: qc.qubits, qc.clbits
Out[11]:
([Qubit(QuantumRegister(5, 'q3'), 0),
Qubit(QuantumRegister(5, 'q3'), 1),
Qubit(QuantumRegister(5, 'q3'), 2),
Qubit(QuantumRegister(5, 'q3'), 3),
Qubit(QuantumRegister(5, 'q3'), 4)],
[Clbit(ClassicalRegister(5, 'c3'), 2),
Clbit(ClassicalRegister(5, 'c3'), 3),
Clbit(ClassicalRegister(5, 'c3'), 0),
Clbit(ClassicalRegister(5, 'c3'), 1),
Clbit(ClassicalRegister(5, 'c3'), 4)]) If we needed the extra checks, the |
Ok yeah, I was confused I guess. I updated the code. |
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.
No worries - thanks for the tests Paul, it looks good, and it's a nice convenience feature.
fixes #6816
Summary
Allows for the common situation where one combines circuits with measurements (clbits) to those without. Currently you can do this by reversing the order of
combine
but that is not intuitive at all. Given that many (if not the vast majority) workflows involve the situation described in #6816, it makes sense to allow it. It also requires minimal modifications to do so.Details and comments