hchevva commited on
Commit
86bf17d
·
verified ·
1 Parent(s): 23409c2

Update quread/gates.py

Browse files
Files changed (1) hide show
  1. quread/gates.py +46 -1
quread/gates.py CHANGED
@@ -69,4 +69,49 @@ SINGLE_QUBIT_GATES = {
69
  "Tdg": Tdg,
70
  "SQRTX": SQRTX,
71
  "SQRTZ": SQRTZ,
72
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  "Tdg": Tdg,
70
  "SQRTX": SQRTX,
71
  "SQRTZ": SQRTZ,
72
+ }
73
+
74
+
75
+ def single_qubit_gate_matrix(gate: str) -> np.ndarray:
76
+ """
77
+ Returns a 2x2 unitary matrix for supported single-qubit gate labels.
78
+
79
+ Supports UI labels too:
80
+ - "S†" / "Sdg"
81
+ - "T†" / "Tdg"
82
+ - "√X" / "SQRTX"
83
+ - "√Z" / "SQRTZ"
84
+ - "RX(π)", "RX(π/2)" (and similarly RY/RZ)
85
+ """
86
+ g = gate.strip()
87
+
88
+ # Normalize common UI labels
89
+ if g in ("S†", "Sdg"):
90
+ g = "Sdg"
91
+ if g in ("T†", "Tdg"):
92
+ g = "Tdg"
93
+ if g in ("√X", "SX"):
94
+ g = "SQRTX"
95
+ if g in ("√Z", "SZ"):
96
+ g = "SQRTZ"
97
+ if g in ("I†", "Idg"):
98
+ g = "I"
99
+
100
+ # Fixed-angle rotation labels (from your palette)
101
+ if g == "RX(π)":
102
+ return rx(np.pi)
103
+ if g == "RX(π/2)":
104
+ return rx(np.pi / 2)
105
+ if g == "RY(π)":
106
+ return ry(np.pi)
107
+ if g == "RY(π/2)":
108
+ return ry(np.pi / 2)
109
+ if g == "RZ(π)":
110
+ return rz(np.pi)
111
+ if g == "RZ(π/2)":
112
+ return rz(np.pi / 2)
113
+
114
+ if g in SINGLE_QUBIT_GATES:
115
+ return SINGLE_QUBIT_GATES[g]
116
+
117
+ raise ValueError(f"Unsupported gate: {gate}")