diff --git a/doc/notebooks/gates.ipynb b/doc/notebooks/gates.ipynb index 5b9fff8a..dc3ee542 100644 --- a/doc/notebooks/gates.ipynb +++ b/doc/notebooks/gates.ipynb @@ -141,7 +141,7 @@ "draw_zx_diagram(1, 'rz(0.125*pi) q;') # can also use 'p' or 'u1'\n", "\n", "draw_zx_diagram(1, 'u2(0.125*pi,0.125*pi) q[0];')\n", - "draw_zx_diagram(1, 'u3(0.125*pi,0.125*pi,0.125*pi) q[0];')" + "draw_zx_diagram(1, 'u3(0.125*pi,0.125*pi,0.125*pi) q[0];') # can also use 'u'" ] }, { diff --git a/pyzx/circuit/gates.py b/pyzx/circuit/gates.py index 000c017c..a0be7ebe 100644 --- a/pyzx/circuit/gates.py +++ b/pyzx/circuit/gates.py @@ -1251,6 +1251,7 @@ def to_graph(self, g, q_mapper, c_mapper): "CCZ": CCZ, "U2": U2, "U3": U3, + "U": U3, "CU3": CU3, "CU": CU, "CRX": CRX, @@ -1285,7 +1286,8 @@ def to_graph(self, g, q_mapper, c_mapper): "p": ZPhase, "u1": ZPhase, "u2": U2, - "u3": U3, + "u3": U3, # needed for backwards compatibility with older versions of qiskit + "u": U3, "cu3": CU3, "cu": CU, "cx": CNOT, diff --git a/pyzx/circuit/qasmparser.py b/pyzx/circuit/qasmparser.py index b524c795..81fdaf27 100644 --- a/pyzx/circuit/qasmparser.py +++ b/pyzx/circuit/qasmparser.py @@ -21,7 +21,7 @@ from typing import List, Dict, Tuple, Optional from . import Circuit -from .gates import Gate, qasm_gate_table, XPhase, YPhase, ZPhase, NOT, U2, U3 +from .gates import Gate, qasm_gate_table, U2, U3 from ..utils import settings @@ -193,7 +193,7 @@ def parse_command(self, c: str, registers: Dict[str,Tuple[int,int]]) -> List[Gat elif name == 'u2': if len(phases) != 2: raise TypeError("Invalid specification {}".format(c)) gates.append(U2(argset[0],phases[0],phases[1])) - elif name == 'u3': + elif name in ('u3', 'u'): if len(phases) != 3: raise TypeError("Invalid specification {}".format(c)) gates.append(U3(argset[0],phases[0],phases[1],phases[2])) elif name in ('cx', 'CX', 'cy', 'cz', 'ch', 'csx', 'swap'): diff --git a/tests/test_qasm.py b/tests/test_qasm.py index 0ec91ea2..4540644d 100644 --- a/tests/test_qasm.py +++ b/tests/test_qasm.py @@ -211,6 +211,7 @@ def compare_gate_matrix_with_qiskit(gates, num_qubits: int, num_angles: int, qas # Test standard gates added to OpenQASM 3. compare_gate_matrix_with_qiskit(['cphase'], 2, 1, [3]) + compare_gate_matrix_with_qiskit(['u3', 'u'], 1, 3, [3]) # Test standard gates removed from OpenQASM 3. compare_gate_matrix_with_qiskit(['sxdg'], 1, 0, [2])