Skip to content
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

Decompose.run discards global_phase #5004

Closed
jlapeyre opened this issue Aug 31, 2020 · 1 comment · Fixed by #4915
Closed

Decompose.run discards global_phase #5004

jlapeyre opened this issue Aug 31, 2020 · 1 comment · Fixed by #4915
Labels
bug Something isn't working

Comments

@jlapeyre
Copy link
Contributor

from qiskit.circuit.library import RZGate
from qiskit.quantum_info import Operator
from qiskit import QuantumCircuit

import scipy
import numpy as np

# Illustrate the problem with an RZGate, which lowers to a U1Gate plus a global phase
g = RZGate(1.0)

# Manually create an array containing the correct matrix
zmat = np.array([[1, 0], [0, -1]])
correct_matrix = scipy.linalg.expm(- 0.5j * zmat)

# Operator correctly converts RZGate to a matrix
assert np.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 result
assert g.definition.global_phase == -0.5
assert np.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.
assert np.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

@jlapeyre jlapeyre added the bug Something isn't working label Aug 31, 2020
@ewinston
Copy link
Contributor

I believe this should be resolved by pr #4915

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants