Magic State Distillation & Lattice Surgery¶
quanta.qec.distillation ¶
quanta.qec.distillation -- Magic state distillation and lattice surgery.
Implements executable 15-to-1 Bravyi-Kitaev distillation factories (purifying |T> states with cubic error suppression eps_out <= 35 p^3), CCZ state factories for non-Clifford gate synthesis, and surface code lattice surgery patch models.
References
Bravyi & Kitaev, "Universal quantum computation with ideal Clifford gates and noisy ancillas", Phys. Rev. A 71, 022316 (2005). Fowler, Whiteside, & Hollenberg, "Towards practical classical processing for the surface code", Phys. Rev. A 86, 042313 (2012). Horsman, Fowler, Devitt, & Van Meter, "Surface code quantum computing by lattice surgery", New J. Phys. 14, 123011 (2012).
BravyiKitaev15to1Factory ¶
15-to-1 Bravyi-Kitaev magic state distillation factory.
Encodes 15 noisy raw |T> states using the [[15, 1, 3]] Reed-Muller CSS code. Transversal T operations project into a purified target |T> state upon verifying all 14 stabilizer syndromes (+1).
Output error rate suppresses as
eps_out <= 35 * p_in^3 + O(p_in^4).
Source code in quanta/qec/distillation.py
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 | |
target_state
property
¶
Target ideal |T> magic state: 1/sqrt(2) (|0> + e^(i pi/4) |1>).
acceptance_probability
staticmethod
¶
Analytical acceptance probability P_accept ~ 1 - 35 p^2.
analytical_output_error
staticmethod
¶
build_circuit ¶
Constructs executable 15-qubit stabilizer verification circuit.
Source code in quanta/qec/distillation.py
distill ¶
distill(
input_error_rate: float = 0.01,
shots: int = 1000,
seed: int | None = None,
) -> DistillationResult
Executes Monte Carlo distillation simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_error_rate
|
float
|
Error rate of raw input magic states. |
0.01
|
shots
|
int
|
Number of distillation attempts. |
1000
|
seed
|
int | None
|
Random seed. |
None
|
Returns:
| Type | Description |
|---|---|
DistillationResult
|
DistillationResult with empirical acceptance and error metrics. |
Source code in quanta/qec/distillation.py
CCZFactory ¶
Tripartite entangled |CCZ> state distillation factory.
Prepares and purifies resource states for fault-tolerant non-Clifford CCZ (Toffoli) gate synthesis: |CCZ> = 1/sqrt(8) sum_{x,y,z in {0,1}} (-1)^{xyz} |x, y, z>.
Source code in quanta/qec/distillation.py
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 | |
build_circuit ¶
Constructs circuit synthesizing |CCZ> from |000> using H and CCX/CCZ.
Source code in quanta/qec/distillation.py
ccz_matrix
staticmethod
¶
Unitary 8x8 matrix representing CCZ gate: diag(1, 1, 1, 1, 1, 1, 1, -1).
distill ¶
distill(
input_error_rate: float = 0.01,
shots: int = 1000,
seed: int | None = None,
) -> DistillationResult
Executes CCZ state purification simulation.
Source code in quanta/qec/distillation.py
DistillationResult
dataclass
¶
Result of magic state distillation.
Attributes:
| Name | Type | Description |
|---|---|---|
success |
bool
|
Whether the distillation was accepted by all stabilizer checks. |
input_error_rate |
float
|
Input physical error probability per raw state. |
output_error_rate |
float
|
Purified state output error probability eps_out. |
acceptance_probability |
float
|
Probability of passing all parity syndrome checks. |
output_state |
ndarray
|
Normalized output statevector. |
fidelity |
float
|
State fidelity with target ideal magic state | |
rounds_simulated |
int
|
Number of Monte Carlo verification shots. |
Source code in quanta/qec/distillation.py
LatticeSurgery ¶
Lattice surgery interaction model for surface code patches.
Implements topological multi-patch operations via genuine joint boundary stabilizer measurements: - z_merge: Joint Z-parity stabilizer checks (M_ZZ) along shared interface. - x_merge: Joint X-parity stabilizer checks (M_XX) along shared interface. - merge: Unified interface calling z_merge or x_merge based on boundary_type. - split: Decouples merged patch back into its constituent patches without string parsing. - transversal_cnot: Fault-tolerant logical CNOT mediated via routing ancilla patch.
Source code in quanta/qec/distillation.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
merge
classmethod
¶
merge(
patch_a: LatticeSurgeryPatch,
patch_b: LatticeSurgeryPatch,
boundary_type: str = "Z",
) -> LatticeSurgeryPatch
Merges two surface code patches along a boundary of given type.
Source code in quanta/qec/distillation.py
split
classmethod
¶
split(
merged_patch: LatticeSurgeryPatch,
boundary_type: str = "Z",
measurement_outcome: int = +1,
) -> tuple[LatticeSurgeryPatch, LatticeSurgeryPatch, int]
Splits a merged patch into two constituent patches.
Restores the individual codespaces by measuring boundary data qubits along the cut without string parsing.
Source code in quanta/qec/distillation.py
transversal_cnot
classmethod
¶
transversal_cnot(
control_patch: LatticeSurgeryPatch,
target_patch: LatticeSurgeryPatch,
) -> dict[str, Any]
Executes a fault-tolerant logical CNOT between two patches via lattice surgery.
Uses an intermediate routing ancilla patch
- Joint Z-parity measurement (M_ZZ) between control and ancilla.
- Joint X-parity measurement (M_XX) between ancilla and target.
Source code in quanta/qec/distillation.py
x_merge
classmethod
¶
x_merge(
patch_a: LatticeSurgeryPatch,
patch_b: LatticeSurgeryPatch,
seed: int | None = None,
) -> tuple[LatticeSurgeryPatch, int, list[dict[str, Any]]]
Executes genuine joint boundary X parity stabilizer measurements.
Along the shared rough boundary of length d = min(d_A, d_B), measures weight-2 X_i ⊗ X_j parity checks. The product of boundary stabilizers yields the joint logical parity outcome M_XX in {+1, -1}.
Source code in quanta/qec/distillation.py
z_merge
classmethod
¶
z_merge(
patch_a: LatticeSurgeryPatch,
patch_b: LatticeSurgeryPatch,
seed: int | None = None,
) -> tuple[LatticeSurgeryPatch, int, list[dict[str, Any]]]
Executes genuine joint boundary Z parity stabilizer measurements.
Along the shared boundary of length d = min(d_A, d_B), measures weight-2 Z_i ⊗ Z_j parity checks. The product of boundary stabilizers yields the joint logical parity outcome M_ZZ in {+1, -1}.
Source code in quanta/qec/distillation.py
LatticeSurgeryPatch
dataclass
¶
Represents a planar surface code logical patch for lattice surgery.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the patch. |
distance |
int
|
Code distance d of the patch. |
basis |
str
|
Logical basis state ('X' or 'Z'). |
num_qubits |
int
|
Total physical data qubits in patch. |
constituent_patches |
tuple[LatticeSurgeryPatch, ...] | None
|
Tuple of constituent patches if this is a merged patch. |
joint_stabilizers |
list[dict[str, Any]]
|
List of joint boundary stabilizer measurements. |
last_outcome |
int
|
Measurement outcome of the last operation (+1 or -1). |