Fix global phase tracking around DAGCircuit.substitute_node.#5618
Conversation
e310c4f to
19f9d5f
Compare
19f9d5f to
8cbee03
Compare
8cbee03 to
b70256d
Compare
mtreinish
left a comment
There was a problem hiding this comment.
LGTM, just a couple of inline comments. Nothing worth blocking over. But it might be worth having someone else check the global phase adjustments in the tests. I always seem to get them wrong. :)
| circuit = QuantumCircuit(2) | ||
| circuit.append(random_unitary(4, seed=1234), [0, 1]) | ||
| circuit = circuit.decompose() | ||
| circuit.cz(0, 1) |
There was a problem hiding this comment.
Was this change made because the random unitary decomposition to qasm and back would lose the global phase and the equality would differ now? FWIW I agree using a random unitary here seems unnecessary since it's testing the pi serialization for qasm, I'm just curious.
There was a problem hiding this comment.
That's right, the unitary ends up generating a non-zero global phase that's lost in the back and forth to QASM.
…-usage-ee05476a7d0b24c6.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
…-usage-ee05476a7d0b24c6.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
|
I checked all the global_phase values in the tests and looks correct to me. (I updated this comment, in my original comment, I missed your update on |
* DAGCircuit.__eq__ to check .global_phase and .calibrations. * Fix BasisTranslator and Unroller global phase for substitute_node. * Update releasenotes/notes/dagcircuit-fix-substitute-node-global-phase-usage-ee05476a7d0b24c6.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Update releasenotes/notes/dagcircuit-fix-substitute-node-global-phase-usage-ee05476a7d0b24c6.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 89cd41e)
In Qiskit#5618 the dagcircuit __eq__ method was updated to also compare the global_phase and calibrations property. This was done to ensure we preserve both through a transpilation and other transforms since when we assert a circuit is equal to the expect result it will also check phase. However, this has backwards compatibility implications since comparing 2 QuantumCircuits would previously ignore global phase. This commit removes this piece from the backport and just leave the phase corrections as the backport.
… (#5673) * Fix global phase tracking around DAGCircuit.substitute_node. (#5618) * DAGCircuit.__eq__ to check .global_phase and .calibrations. * Fix BasisTranslator and Unroller global phase for substitute_node. * Update releasenotes/notes/dagcircuit-fix-substitute-node-global-phase-usage-ee05476a7d0b24c6.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Update releasenotes/notes/dagcircuit-fix-substitute-node-global-phase-usage-ee05476a7d0b24c6.yaml Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 89cd41e) * Backport global phase from #5517 on grover operator This commit adds a missing phase of pi to the grover operator circuit library entry. It is a backport from #5517. * Remove backport of phase and calibrartions check to dagcircuit eq In #5618 the dagcircuit __eq__ method was updated to also compare the global_phase and calibrations property. This was done to ensure we preserve both through a transpilation and other transforms since when we assert a circuit is equal to the expect result it will also check phase. However, this has backwards compatibility implications since comparing 2 QuantumCircuits would previously ignore global phase. This commit removes this piece from the backport and just leave the phase corrections as the backport. Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com> Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Summary
Updates the
UnrollerandBasisTranslatorpasses to only manually update the global phase of the target dag when usingDAGCircuit.substitute_node, asDAGCircuit.substitute_node_with_dagalready handles updating global phase of the target dag.Details and comments
Also updates
DAGCircuit.__eq__to check equality of theglobal_phaseandcalibrationsattributes and updates tests. Also fixes a case where aQuantumCirucit.global_phasewhich had been set from as aParameterExpressioncould avoid the [0, 2pi) bounds check.