Gates¶
quanta.core.gates ¶
- A name (name)
- Unitary matrix representation (matrix)
Example
from quanta.core.gates import H, CX H.matrix.shape (2, 2) CX.num_qubits 2
Gate ¶
Base class for a quantum gate.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Gate name (e.g. "H", "CX"). |
num_qubits |
int
|
Number of qubits this gate acts on. |
Source code in quanta/core/gates.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
inverse
property
¶
Returns the inverse (adjoint) gate: U†.
For self-inverse gates (H, X, Y, Z, CX, CZ, SWAP) returns self. For known pairs (S↔SDG, T↔TDG, SX↔SXdg) returns the partner. Otherwise computes U† from the matrix.
Example
S.inverse.name 'SDG' H.inverse is H True
__call__ ¶
Records gate to active circuit. Supports broadcast.
H(q[0]) → single qubit H(q) → broadcast to all qubits
Source code in quanta/core/gates.py
controlled ¶
Returns a controlled version of this gate.
Builds a (num_ctrl + num_qubits)-qubit controlled-U gate. The first num_ctrl qubits are controls, the rest are targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_ctrl
|
int
|
Number of control qubits (default: 1). |
1
|
Returns:
| Type | Description |
|---|---|
Gate
|
A new Gate with the controlled-U matrix. |
Example
X.controlled().name 'CX' H.controlled().num_qubits 2
Source code in quanta/core/gates.py
MultiParametricGate ¶
Multi-parameter gate factory. Like U(θ, φ, λ).
Source code in quanta/core/gates.py
ParametricGate ¶
Parametric gate factory. Like RX(θ), RY(θ), RZ(θ).
Example
RY(np.pi/4)(q[0]) # θ=π/4 ile RY uygula