Add IGate rules to standard equivalence library#7146
Conversation
This commit adds a missing rules to the equivalence library for an identity gate. Without this the basis translator has difficulty finding a match if the basis does not include an id gate (see Qiskit#1346)
There was a problem hiding this comment.
These seem all fine. In normal transpiler runs, will these even activate? It feels like IGate should generally just get removed from the circuit (unless I suppose it has calibrations/noise models attached to it, but then the equivalences shouldn't run either).
(I think black doesn't like your single quotes)
It actually would come up if there is an id gate in the input circuit and not in the basis set at all optimization levels I think. Since we run the basis translator prior to any optimizations that will remove the id gate. I specifically hit this in a pretty synthetic case though, in the benchmarks I'm adding in: #1346 which just uses |
|
Yeah, I'd seen the synthetic benchmark. I suppose it makes sense that the basis-gate translator would be run first; if we ran the hypothetical "check for no-ops" too early, we'd probably have to run it again later to make sure we hadn't introduced any more by cancellations or parameter combinations or something. |
There was a problem hiding this comment.
Comments in Qiskit/qiskit-metapackage#1346 (comment) .
This shouldn't hold true anymore as new backends will no longer support the |
Pull Request Test Coverage Report for Build 3658676946
💛 - Coveralls |
|
Additionally I just pushed: Qiskit/qiskit-ibm-provider#468 to have IBM backend's preserve their custom definition of id == delay(sx.duration) through transpile via custom backend plugin defaults. This means that combined with this PR IBM backends get their custom behavior and for all other backends id == identity (especially when combined with #7403 ) |
I'm a bit confused as to why Qiskit/qiskit-ibm-provider#468 is needed in addition to the this PR and #7403. Wouldn't that override this PR and #7403 to reinstate the deprecated behavior (and maybe silence the deprecation warning)? |
|
Yeah, that's the idea: the old backends that do maintain that definition translate This and #7403 are about not enforcing that custom behaviour on every other hardware backend, and letting various other parts of Qiskit now reason about the identity operation at a high-level in the expected way. |
I think I'm a bit lost on the motivation. It might be a good time to write down all the cases we're thinking of, and the various timelines and expected behaviors. Why would the backends that still maintain |
|
This is superseded by #7403 as I don't think we need explicit equivalence lib entries for |
Adding the id equivalence rules to the equivalence library is changing the output translation for one of the tests and this causes the test which is using an exact circuit comparison to fail. This commit updates the test to use the new output but then also does an operator comparison to ensure that the output circuit is equivalent too.
jakelishman
left a comment
There was a problem hiding this comment.
A minor question, but I'm in general happy to merge.
Pull Request Test Coverage Report for Build 6424802268
💛 - Coveralls |
| expected = QuantumCircuit(2) | ||
| expected.u(pi / 2, 0, pi, qr[0]) | ||
| expected.u(0, 0, -pi / 2, qr[0]) | ||
| expected.u(-pi / 2, -pi / 2, pi / 2, qr[1]) | ||
| expected.u(pi, 0, 0, qr[0]) | ||
| expected.u(pi / 2, -pi / 2, pi / 2, qr[1]) | ||
| expected.ecr(0, 1) | ||
| expected.u(pi, 0, pi, qr[0]) | ||
| expected_dag = circuit_to_dag(expected) |
There was a problem hiding this comment.
My question from the prior review! It got lost before - I must have forgotten to save the comment.
Do we know why this changes? We haven't added any rules that go to IGate, so I'd not have expected the basis-translation path to change.
There was a problem hiding this comment.
TBH, I'm not sure. I didn't really think to check. I just saw the output circuit was equivalent and updated the test. I'll do some debugging locally because the qpy tests are failing in a weird way now too so this is blocked on that anyway.
kdk
left a comment
There was a problem hiding this comment.
Following some updates since this was last discussed (id will stick around on IBM backends, and is being defined in Qiskit as a single-qubit no-op of backend-defined duration), I think this is good to go (pending #7146 (comment) ).
It would also be good to call out (in the IGate docstring and maybe as a release note) that IGate is no longer strictly opaque, and should be expected to be optimized away by the transpiler except at optimization_level=0.
Summary
This commit adds a missing rules to the equivalence library for an
identity gate. Without this the basis translator has difficulty finding
a match if the basis does not include an id gate (see
Qiskit/qiskit-metapackage#1346)
Details and comments
Fix #9485.