-
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
Allow decomposing composite gates by name #9170
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this: |
…erra into fix_decompose_labels
Pull Request Test Coverage Report for Build 3942368030
💛 - Coveralls |
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.
I left some preliminary comments, but I'm not sure this behavior is what we want. The idea of decomposing by name was to decompose according to what was drawn in the circuit drawer, but with this PR that's not true anymore. For example, with the circuit of the test:
┌────────┐ ┌───┐┌─────────────┐
q0_0: ┤0 ├────────────■──┤ H ├┤0 ├
│ │ │ └───┘│ circuit-93 │
q0_1: ┤1 gate1 ├────────────■───────┤1 ├
│ │┌────────┐ │ └─────────────┘
q0_2: ┤2 ├┤0 ├──■──────────────────────
└────────┘│ │ │
q0_3: ──────────┤1 gate2 ├──■──────────────────────
│ │┌─┴─┐
q0_4: ──────────┤2 ├┤ X ├────────────────────
└────────┘└───┘
specifying "circuit-*"
should only decompose the top-right box, but now it also decomposes gate1
and gate2
, to
┌───┐ ┌───┐┌───┐
q0_0: ┤ H ├────────────■──┤ H ├┤ X ├
├───┤ │ └───┘└───┘
q0_1: ┤ T ├────────────■────────────
├───┤┌───┐ │
q0_2: ┤ X ├┤ H ├──■────■────────────
└───┘└───┘┌─┴─┐ │
q0_3: ──────────┤ X ├──■────────────
┌───┐ └───┘┌─┴─┐
q0_4: ┤ X ├──────────┤ X ├──────────
└───┘ └───┘
but this is not how it was originally designed. If we do want that we can change it, but I just want to make sure that this right now is a breaking change.
In the original design it was intended that XXPlusYYGate
was indeed only decomposed by
circuit.decompose("{XX+YY}")
and not by tagging "xx_plus_yy"
.
Julien: I wasn't aware that was the intention from the PR that added it, but even learning it now, it feels a bit odd to me. There's no inherent link between The only documentation that exists on using strings as the decomposition is in the |
@Cryoris, @jakelishman. I see both sides of this, so just let me know which way to go. I also noticed that |
Yeah I agree that the mix right now is confusing, it seems we were trying to solve a different problem before. But just decomposing if either of the label or name fits still seems imprecise. Would it be a cleaner solution to separately have either (1) gate type and name (both sort of are the type) and (2) labels? That could be done by eg adding "labels_to_decompose" or something similar. We could also come up with a different solution for checking what gates are made up of in the drawer, but that would probably be very helpful to have (which is why we made decompose do it before 🙂) |
@Cryoris Adding the 'labels_to_decompose' could be a good solution for the current situation. It eliminates having to decide if 'name' or 'label' has some kind of priority. Only issue is in the short-term if someone is currently using labels in 'gates_to_decompose', how do we handle that. Do a deprecation for it? @jakelishman Let me know if this seems reasonable to you and I can add it in. In regard to showing gates composed of circuits in the drawers, I'm currently working on showing the control flow circuit clauses in the 'mpl' drawer. It's not a simple problem, but if I get that working, the same structure could be used to show any composite gate as a circuit, perhaps with an option for the user. |
Technically we should have a deprecation, but this decomposition by string is sufficiently new (and the behaviour sufficiently unexpected, as evidenced by the ticket) that we can say the previous behaviour of Those changes to the drawer sound great, Edwin, thanks! |
In thinking (overthinking) this further, I don't believe the
Bottom line is the user can only specify a single or subset of all composite gates by using labels. This can be explained in detail in the docs. So leave the behavior as it is in this PR, with some update to the docs. |
Edwin: this seems to miss the issue that actually caused this PR to be opened, which was that we were surprised that you can't use the
|
Ok. Understood that decompose is not drawer-only. The current PR code solves the original problem as well. If a gate name is entered, all gates with that name will be decomposed whether there are labels on them or not. If labels are given, only gates with those labels will be decomposed. |
…erra into fix_decompose_labels
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 Edwin - I think this now agrees with what we'd decided. I'll merge this now.
* Fix decompose with a lable or name * Finish tests and reno * Lint * Remove gate arg and fix parens * Update QuantumCircuit.decompose doc string * Unused imports
Summary
Fixes #9136
Details and comments
This fixes a situation where passing the name of a composite gate to
QuantumCircuit.decompose
would result in the gate not decomposing if there was a label on the gate.