Update quread/gates.py
Browse files- quread/gates.py +31 -49
quread/gates.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
# quread/gates.py
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
H = (1 / np.sqrt(2)) * np.array([[1, 1], [1, -1]], dtype=complex)
|
| 7 |
X = np.array([[0, 1], [1, 0]], dtype=complex)
|
|
@@ -18,7 +20,7 @@ Tdg = np.array([[1, 0], [0, np.exp(-1j * np.pi / 4)]], dtype=complex)
|
|
| 18 |
SQRTX = 0.5 * np.array([[1 + 1j, 1 - 1j],
|
| 19 |
[1 - 1j, 1 + 1j]], dtype=complex)
|
| 20 |
|
| 21 |
-
# √Z (principal square root): diag(1,
|
| 22 |
SQRTZ = S
|
| 23 |
|
| 24 |
|
|
@@ -41,50 +43,30 @@ def RZ(theta: float) -> np.ndarray:
|
|
| 41 |
[0, np.exp(1j * theta / 2)]], dtype=complex)
|
| 42 |
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
if g in ("√X", "SQRTX"):
|
| 72 |
-
return SQRTX
|
| 73 |
-
if g in ("√Z", "SQRTZ"):
|
| 74 |
-
return SQRTZ
|
| 75 |
-
|
| 76 |
-
# rotations (fixed angles from your palette)
|
| 77 |
-
if g == "RX(π)":
|
| 78 |
-
return RX(np.pi)
|
| 79 |
-
if g == "RX(π/2)":
|
| 80 |
-
return RX(np.pi / 2)
|
| 81 |
-
if g == "RY(π)":
|
| 82 |
-
return RY(np.pi)
|
| 83 |
-
if g == "RY(π/2)":
|
| 84 |
-
return RY(np.pi / 2)
|
| 85 |
-
if g == "RZ(π)":
|
| 86 |
-
return RZ(np.pi)
|
| 87 |
-
if g == "RZ(π/2)":
|
| 88 |
-
return RZ(np.pi / 2)
|
| 89 |
-
|
| 90 |
-
raise ValueError(f"Unsupported gate: {gate}")
|
|
|
|
| 1 |
# quread/gates.py
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
+
# Identity
|
| 5 |
+
I = np.array([[1, 0],
|
| 6 |
+
[0, 1]], dtype=complex)
|
| 7 |
|
| 8 |
H = (1 / np.sqrt(2)) * np.array([[1, 1], [1, -1]], dtype=complex)
|
| 9 |
X = np.array([[0, 1], [1, 0]], dtype=complex)
|
|
|
|
| 20 |
SQRTX = 0.5 * np.array([[1 + 1j, 1 - 1j],
|
| 21 |
[1 - 1j, 1 + 1j]], dtype=complex)
|
| 22 |
|
| 23 |
+
# √Z (principal square root): diag(1, i) == S
|
| 24 |
SQRTZ = S
|
| 25 |
|
| 26 |
|
|
|
|
| 43 |
[0, np.exp(1j * theta / 2)]], dtype=complex)
|
| 44 |
|
| 45 |
|
| 46 |
+
# --- aliases expected by engine.py ---
|
| 47 |
+
def rx(theta: float) -> np.ndarray:
|
| 48 |
+
return RX(theta)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def ry(theta: float) -> np.ndarray:
|
| 52 |
+
return RY(theta)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def rz(theta: float) -> np.ndarray:
|
| 56 |
+
return RZ(theta)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# --- map expected by engine.py ---
|
| 60 |
+
SINGLE_QUBIT_GATES = {
|
| 61 |
+
"I": I,
|
| 62 |
+
"H": H,
|
| 63 |
+
"X": X,
|
| 64 |
+
"Y": Y,
|
| 65 |
+
"Z": Z,
|
| 66 |
+
"S": S,
|
| 67 |
+
"Sdg": Sdg,
|
| 68 |
+
"T": T,
|
| 69 |
+
"Tdg": Tdg,
|
| 70 |
+
"SQRTX": SQRTX,
|
| 71 |
+
"SQRTZ": SQRTZ,
|
| 72 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|