Give IGate a no-op definition#7403
Conversation
This allows it to work with all passes that decompose operations using `Instruction.definition`, even if there is no particular special handling for it.
Pull Request Test Coverage Report for Build 4577211839
💛 - Coveralls |
|
I am marginally concerned that those newly uncovered lines indicate a problem somewhere in our testing logic; they're meant to throw an error, but we didn't have any test failures before, and we don't now. Seems like somewhere might be overzealously catching exceptions. |
kdk
left a comment
There was a problem hiding this comment.
Similar to #7146 , I think the approach here is inconsistent with how Qiskit currently defines IGate.
https://github.com/Qiskit/qiskit-terra/blob/309bfb173e946f441243f292a7655203419efde9/qiskit/circuit/library/standard_gates/i.py#L23
This behavior is deprecated but not yet removed from the IBMQ backends at which point we can IGate to it's canonical definition. Until then, perhaps we can raise a more meaningful error message when someone tries to unroll, decompose, or control an IGate.
kdk
left a comment
There was a problem hiding this comment.
This will be great to be able to finally reconcile. A few documentation comments but otherwise LGTM.
| Identity gate corresponds to a single-qubit gate wait cycle, | ||
| and should not be optimized or unrolled (it is an opaque gate). | ||
| Logically this gate is a quantum no-op and the transpiler will largely treat it as such, but | ||
| some older hardware may choose to interpret it as a short-hand for the shortest-possible delay |
There was a problem hiding this comment.
| some older hardware may choose to interpret it as a short-hand for the shortest-possible delay | |
| some backends may choose to interpret it as a short-hand for the shortest-possible delay |
|
After a discussion with @taalexander and @dtmcclure , I'd like to wait a bit on this. It looks like there's a desire to keep the |
|
I don't believe this will effect IBM backend's custom usage for single qubit delay. As |
|
But the transpiler will also remove |
|
I really don't like the proprietary IBM hardware preventing the backend-agnostic Qiskit from using the natural mathematical name Not having this be a true identity operation keeps causing problems at higher-levels, where algorithms and applications (via |
|
Agree that the result post-optimization of most common uses cases with the proposals on the table will look very similar in practice but I would like, if possible, to find a pathway forward that is consistent with how This might look like defining |
kdk
left a comment
There was a problem hiding this comment.
Proposing some text that might cover both cases. Feedback very welcome.
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
mtreinish
left a comment
There was a problem hiding this comment.
I think now is the time to do this, I can't think of a use case that will be broken by this. For IBM backends with their custom behavior for id that will still work because id is in the basis gates for those backend and they can treat it special (there is also the custom translation plugin the ibm provider has to to translate id to single qubit gate duration delays). For other backends if they support id that will continue to work as is, but for backends that don't support id this fixes transpilation for those backends.
kdk
left a comment
There was a problem hiding this comment.
Coming back to this, starting from the idea that IGate is a single-qubit no-op gate, the core of my hesitation with this PR is that while removing an IGate from a circuit is valid optimization, it is not necessarily a valid translation (roughly, the difference between "IGate is nothing" as opposed to "IGate does nothing logically"). In the same way RXGate(4*pi) and other gates that implement a logical identity operation don't have an empty definition, it doesn't feel correct for IGate.
Where this could turn into a bug for users is that we allow translations at optimization_level=0 but not optimizations, and so users who are intentionally using IGate at optimization_level=0 could have them dropped entirely (as opposed to seeing a compile time error) if their backend doesn't support 'id'.
As an answer for #9485 , I think #7146 is more consistent with IGate being defined as a backend-dependent single-qubit no-op gate (and now that the plan is to maintain 'id' on IBM hardware, my prior concerns there no longer apply).
|
I'm fine with this or #7146, the specific approach doesn't matter to me. What I think is critical to fix is that |
|
Closing in favor of #7146 . |
Summary
This allows it to work with all passes that decompose operations using
Instruction.definition, even if there is no particular specialhandling for it.
Details and comments
Fix #7399.
Fix #4010.
Fix #9485.