You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromqiskit.circuit.libraryimportRZGatefromqiskit.quantum_infoimportOperatorfromqiskitimportQuantumCircuitimportscipyimportnumpyasnp# Illustrate the problem with an RZGate, which lowers to a U1Gate plus a global phaseg=RZGate(1.0)
# Manually create an array containing the correct matrixzmat=np.array([[1, 0], [0, -1]])
correct_matrix=scipy.linalg.expm(-0.5j*zmat)
# Operator correctly converts RZGate to a matrixassertnp.allclose(Operator(g).data, correct_matrix)
# g.definition returns a QuantumCircuit with a U1 gate and a global_phase# Converting this gate + phase to a matrix via Operator gives the correct resultassertg.definition.global_phase==-0.5assertnp.allclose(Operator(g.definition).data, correct_matrix)
# Create a circuit with an RZGate (not lowered to U1)qc=QuantumCircuit(1)
qc.append(g, [0])
# qc.decompose() also lowers RZGate to a U1 gate, calling "definition" as above,# but the global_phase is discarded, resulting in a matrix that is incorrect by a phase.assertnp.allclose(np.exp(g.definition.global_phase*1.0j) *Operator(qc.decompose()).data, correct_matrix)
A substitution is made using a gate obtained this way
https://github.com/Qiskit/qiskit-terra/blob/a0ee52400cb21139b509cdba5c14455c27150b01/qiskit/transpiler/passes/basis/decompose.py#L50
But,
node.op.definition.global_phase
is lost.Information
08a1f37
The text was updated successfully, but these errors were encountered: