Statevector Simulator¶
quanta.simulator.statevector ¶
quanta.simulator.statevector -- NumPy-based statevector simulator.
v0.2: Rewritten with tensor contraction method.
OLD (v0.1): Kronecker expansion O(4^n) -- max 12 qubits, 1.8s NEW (v0.2): Tensor contraction O(2^n) -- max 26 qubits, <20s
Method
Keep statevector as [2,2,...,2] tensor. Apply gate only to relevant axes (np.tensordot).
Example
sim = StateVectorSimulator(num_qubits=20) sim.apply("H", (0,)) sim.apply("CX", (0, 1)) sim.probabilities()[:4] array([0.5, 0. , 0. , 0.5])
SimulatorError ¶
Bases: QuantaError
Simulator runtime error.
StateVectorSimulator ¶
Bases: SimulatorBackend
Tensor-based statevector simulator.
Simulates quantum circuits on a 2^n dimensional complex vector. v0.2: O(2^n) performance with np.tensordot -- supports 26 qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_qubits
|
int
|
Number of qubits to simulate. |
required |
seed
|
int | None
|
Random seed for reproducibility. |
None
|
Source code in quanta/simulator/statevector.py
37 38 39 40 41 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 72 73 74 75 76 77 78 79 80 81 82 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
apply ¶
Applies a gate to the statevector via tensor contraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gate_name
|
str
|
Gate name (e.g., "H", "CX"). |
required |
qubits
|
tuple[int, ...]
|
Target qubit indices. |
required |
params
|
tuple[float, ...]
|
Angles for parametric gates. |
()
|
Source code in quanta/simulator/statevector.py
apply_noise ¶
Applies a noise model to the statevector after a gate.
Public interface for noise integration — avoids external access to _state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
noise_model
|
object
|
NoiseModel with apply_noise(state, qubits, n, rng). |
required |
qubits
|
tuple[int, ...]
|
Qubits the gate acted on. |
required |
rng
|
Generator
|
Random number generator for stochastic noise. |
required |
Source code in quanta/simulator/statevector.py
apply_phase ¶
Applies a phase factor to a specific basis state.
Used by Grover oracle and other state-manipulation algorithms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Basis state index (0 to 2^n - 1). |
required |
phase
|
complex
|
Phase factor to multiply (e.g., -1 for phase flip). |
required |
Source code in quanta/simulator/statevector.py
probabilities ¶
sample ¶
Performs measurement sampling based on probabilities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shots
|
int
|
Number of samples. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, int]
|
Result -> count. E.g. {'00': 512, '11': 512} |