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

Change 1q UnitaryGate definition to use U instead of U3 #10597

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions qiskit/extensions/unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
from qiskit.circuit import QuantumRegister, Qubit
from qiskit.circuit.exceptions import CircuitError
from qiskit.circuit._utils import _compute_control_matrix
from qiskit.circuit.library.standard_gates import U3Gate
from qiskit.circuit.library.standard_gates import UGate
from qiskit.extensions.quantum_initializer import isometry
from qiskit.quantum_info.operators.predicates import matrix_equal
from qiskit.quantum_info.operators.predicates import is_unitary_matrix
from qiskit.quantum_info.synthesis.one_qubit_decompose import OneQubitEulerDecomposer
from qiskit.quantum_info.synthesis.two_qubit_decompose import two_qubit_cnot_decompose
from qiskit.extensions.exceptions import ExtensionError

_DECOMPOSER1Q = OneQubitEulerDecomposer("U3")
_DECOMPOSER1Q = OneQubitEulerDecomposer("U")


class UnitaryGate(Gate):
Expand Down Expand Up @@ -125,7 +125,7 @@ def _define(self):
q = QuantumRegister(1, "q")
qc = QuantumCircuit(q, name=self.name)
theta, phi, lam, global_phase = _DECOMPOSER1Q.angles_and_phase(self.to_matrix())
qc._append(U3Gate(theta, phi, lam), [q[0]], [])
qc._append(UGate(theta, phi, lam), [q[0]], [])
qc.global_phase = global_phase
self.definition = qc
elif self.num_qubits == 2:
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/unitary-u-not-u3-0a32c2d968f7890e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
upgrade:
- |
the definition of UnitaryGate for single qubit unitaries is now in terms of UGate instead of the legacy U3Gate class
8 changes: 4 additions & 4 deletions test/python/circuit/test_circuit_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_unitary_qasm(self):
qasm = qc.qasm()
expected = """OPENQASM 2.0;
include "qelib1.inc";
gate unitary q0 { u3(0,0,0) q0; }
gate unitary q0 { u(0,0,0) q0; }
qreg q[1];
unitary q[0];
"""
Expand All @@ -367,9 +367,9 @@ def test_multiple_unitary_qasm(self):
expected = re.compile(
r"""OPENQASM 2.0;
include "qelib1.inc";
gate unitary q0 { u3\(0,0,0\) q0; }
gate (?P<u1>unitary_[0-9]*) q0 { u3\(pi,-pi/2,pi/2\) q0; }
gate (?P<u2>unitary_[0-9]*) q0 { u3\(0,pi/2,pi/2\) q0; }
gate unitary q0 { u\(0,0,0\) q0; }
gate (?P<u1>unitary_[0-9]*) q0 { u\(pi,-pi/2,pi/2\) q0; }
gate (?P<u2>unitary_[0-9]*) q0 { u\(0,pi/2,pi/2\) q0; }
gate custom q0 { (?P=u2) q0; }
qreg q\[2\];
unitary q\[0\];
Expand Down
4 changes: 2 additions & 2 deletions test/python/circuit/test_unitary.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_qasm_unitary_only_one_def(self):
expected_qasm = (
"OPENQASM 2.0;\n"
'include "qelib1.inc";\n'
"gate unitary q0 { u3(0,0,0) q0; }\n"
"gate unitary q0 { u(0,0,0) q0; }\n"
"qreg q0[2];\ncreg c0[1];\n"
"x q0[0];\n"
"unitary q0[0];\n"
Expand All @@ -241,7 +241,7 @@ def test_qasm_unitary_twice(self):
expected_qasm = (
"OPENQASM 2.0;\n"
'include "qelib1.inc";\n'
"gate unitary q0 { u3(0,0,0) q0; }\n"
"gate unitary q0 { u(0,0,0) q0; }\n"
"qreg q0[2];\ncreg c0[1];\n"
"x q0[0];\n"
"unitary q0[0];\n"
Expand Down