Skip to content

Commit

Permalink
Add 'u' as alias for 'u3' gate. Required for compatibility with Qiski…
Browse files Browse the repository at this point in the history
…t 1.0+.

See: https://docs.quantum.ibm.com/api/qiskit/qiskit.circuit.library.U3Gate

In particular, note the line: "This gate is deprecated. Instead, the following replacements should be used: U3(theta, phi, lambda) = U(theta, phi, lambda)"
  • Loading branch information
dlyongemallo committed May 4, 2024
1 parent 107c24e commit bde49b1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/notebooks/gates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion pyzx/circuit/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pyzx/circuit/qasmparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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'):
Expand Down
1 change: 1 addition & 0 deletions tests/test_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit bde49b1

Please sign in to comment.