Surface Code¶
quanta.qec.surface_code ¶
quanta.qec.surface_code -- Surface code for logical qubits.
The surface code is the leading candidate for fault-tolerant quantum computing. It arranges physical qubits on a 2D grid with: - Data qubits (carry information) - X-syndrome qubits (detect bit-flip errors) - Z-syndrome qubits (detect phase-flip errors)
A [[d^2, 1, d]] code: d^2 physical qubits encode 1 logical qubit with code distance d (corrects floor((d-1)/2) errors).
Example
from quanta.qec.surface_code import SurfaceCode code = SurfaceCode(distance=3) print(code.summary()) Surface Code [[9, 1, 3]] result = code.simulate_error_correction(error_rate=0.01, rounds=100) print(f"Logical error rate: {result.logical_error_rate:.4f}")
SurfaceCode ¶
Surface code for fault-tolerant quantum computing.
Implements the rotated surface code on a d×d grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
int
|
Code distance d. Physical qubits = d^2. d=3: 9 qubits, corrects 1 error d=5: 25 qubits, corrects 2 errors d=7: 49 qubits, corrects 3 errors |
3
|
Source code in quanta/qec/surface_code.py
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 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
get_syndrome ¶
Extracts syndrome by checking parity of each stabilizer.
Each syndrome bit is the XOR (parity) of the error pattern restricted to that stabilizer's support qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_mask
|
ndarray
|
Boolean array of length n_physical. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Syndrome array (0/1 for each stabilizer). |
Source code in quanta/qec/surface_code.py
simulate_error_correction ¶
simulate_error_correction(
error_rate: float = 0.001,
rounds: int = 1000,
seed: int | None = None,
) -> SurfaceCodeResult
Simulates surface code error correction.
Uses real stabilizer-based syndrome extraction: 1. Injects random errors 2. Extracts syndrome via stabilizer parity checks 3. Decodes using syndrome weight analysis 4. Checks for logical errors via lattice-crossing detection
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_rate
|
float
|
Per-qubit per-round error probability. |
0.001
|
rounds
|
int
|
Number of correction rounds. |
1000
|
seed
|
int | None
|
Random seed. |
None
|
Returns:
| Type | Description |
|---|---|
SurfaceCodeResult
|
SurfaceCodeResult with error rates and statistics. |
Source code in quanta/qec/surface_code.py
summary ¶
Returns a formatted summary of the code parameters.
Source code in quanta/qec/surface_code.py
SurfaceCodeResult
dataclass
¶
Result of surface code error correction simulation.
Attributes:
| Name | Type | Description |
|---|---|---|
logical_error_rate |
float
|
Rate of uncorrectable logical errors. |
physical_error_rate |
float
|
Input physical error rate. |
rounds |
int
|
Number of error correction rounds. |
errors_injected |
int
|
Total errors injected. |
errors_corrected |
int
|
Successfully corrected errors. |
threshold_estimate |
float
|
Estimated threshold error rate. |