-
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
QuantumCircuit.reverse_bits does not work with some circuits with registerless bits #7415
Comments
@jakelishman Can you assign this to me? Thanks. |
@kdk, @jakelishman Consider these circuits, all run with main. In the first case, when
This results in 2 identical circuits, which can't be distinguished from one another by the drawers. In this second case, the registers (with their one bits each) are reversed and the qarg stays the same. This results in 2 different circuits, which are displayed differently.
Now suppose we have
What do we do here? Reverse the bits or the qarg? It seems to me, reverse_bits should always reverse the bits, whether within a register or not, and the qargs and cargs should remain the same. |
@enavarro51 apologies: I assigned this off my phone without checking the issue properly - looks like there's already a pending PR that needs review. I'll unassign for now, and I need to start working through the post-release backlog when I'm back at work. |
Sorry that I created a PR for this issue without asking for an assignment. At first, I thought it was an easy problem, so I submitted the PR directly when no one was assigned. But the test failure made me realize that there could be different explanations regarding the semantics, and I changed the PR state to draft. After I fixed my code, I found that the issue has been assigned to @enavarro51. It is not the fault of @jakelishman. Maybe my code can be used as a reference and save all of us some time. I support the current semantics of
which is the Qiskit convention.
which is the textbook convention. If the bits are reversed within registers, the control bit would both be 0, before and after applying As to registerless bits, I think they should be regarded as unnamed 1-bit registers. So, they should be reversed. I am not sure about the semantics of |
Oh, @yjt98765 I apologize as well. I'd missed the PR. Also, thanks for your comments. For me, it just seems a bit odd when doing |
Sorry, I've been busy for the last while, and I read your PR before I actually read this comment! There's a bit more complexity here than just considering single bits as 1-bit registers; multiple registers can contain the same bits now, so there can be a lot of overlap, and the ordering described in the docstring doesn't necessarily make sense for that now. Also, in converting from little-endian to big-endian, I think we should also take into account the fact that in modern Terra, you can pass a global index into Don't worry about working on the issue without asking for assignment - it's not required, and it was just an oversight on our parts here that we didn't spot you'd already made a PR! You'd already made the PR before Edwin asked, and I just missed the notification. |
Environment
What is happening?
The method
QuantumCircuit.reverse_bits
fails when using a circuit with registerless bits. Relates to discussion in #7303.How can we reproduce the issue?
produces
Also for a simple circuit, the circuit drawers do not reverse the bit labels after a successful
QuantumCircuit.reverse_bits
.produces
What should happen?
QuantumCircuit.reverse_bits
shouldn't fail and the method andreverse_bits=True
in the drawers should produce the same result.Any suggestions?
No response
The text was updated successfully, but these errors were encountered: