Index
Notebook-focused Gemini decoding helpers.
ConfidenceDecoder
Bases: ABC
flowchart TD
bloqade.gemini.decoding.ConfidenceDecoder[ConfidenceDecoder]
click bloqade.gemini.decoding.ConfidenceDecoder href "" "bloqade.gemini.decoding.ConfidenceDecoder"
Decoder interface for a correction plus a scalar confidence score.
decode_with_confidence
abstractmethod
decode_with_confidence(
detector_bits: NDArray[bool_],
) -> tuple[npt.NDArray[np.bool_], np.float64]
Decode one detector syndrome and return a confidence score.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/confidence.py
84 85 86 87 88 89 | |
GurobiDecoderWithConfidence
GurobiDecoderWithConfidence(*args: Any, **kwargs: Any)
Bases: GurobiDecoder, ConfidenceDecoder
flowchart TD
bloqade.gemini.decoding.GurobiDecoderWithConfidence[GurobiDecoderWithConfidence]
bloqade.gemini.decoding.confidence.GurobiDecoder[GurobiDecoder]
bloqade.gemini.decoding.confidence.ConfidenceDecoder[ConfidenceDecoder]
bloqade.gemini.decoding.confidence.GurobiDecoder --> bloqade.gemini.decoding.GurobiDecoderWithConfidence
bloqade.gemini.decoding.confidence.ConfidenceDecoder --> bloqade.gemini.decoding.GurobiDecoderWithConfidence
click bloqade.gemini.decoding.GurobiDecoderWithConfidence href "" "bloqade.gemini.decoding.GurobiDecoderWithConfidence"
click bloqade.gemini.decoding.confidence.GurobiDecoder href "" "bloqade.gemini.decoding.confidence.GurobiDecoder"
click bloqade.gemini.decoding.confidence.ConfidenceDecoder href "" "bloqade.gemini.decoding.confidence.ConfidenceDecoder"
Gurobi MLE decoder with logical-gap confidence.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/confidence.py
32 33 | |
decode
decode(
detector_bits: NDArray[bool_],
verbose: bool = False,
return_weights: bool = False,
) -> (
npt.NDArray[np.bool_]
| tuple[npt.NDArray[np.bool_], np.ndarray]
)
Decode detector bits after validating the detector-shot width.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/confidence.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
decode_with_confidence
decode_with_confidence(
detector_bits: NDArray[bool_],
) -> tuple[npt.NDArray[np.bool_], np.float64]
Decode a single shot and return the logical-gap confidence.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/confidence.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
PostSelectionExperiment
PostSelectionExperiment(
nonclifford_prefix: Method[..., None],
clifford_circuit: Method[..., None],
tomography_circuits: Mapping[str, Method[..., None]],
decoder: type[ConfidenceDecoder],
decoder_init_args: Mapping[str, object] | None = None,
)
A "wizard" class that orchestrates the steps of running a experiment to do tomography which obtains samples from the hardware and runs decoding with postselection on your ancilla qubits.
It defines methods for creating noisy tomography circuits, creating decoders from the detector error models from those tomography circuits, sampling from the hardware, and doing some analysis based on the confidence associated with each shot.
Attributes:
| Name | Type | Description |
|---|---|---|
nonclifford_prefix |
Method[..., None]
|
A SQuIN kernel consisting of a single layer of single-qubit gates applied to the physical qubits before the state-preparation circuit is applied. |
clifford_circuit |
Method[..., None]
|
A SQuIN kernel consisting of a Clifford circuit applied to the logical qubits (after logical encoding). |
tomography_circuits |
Method[..., None]
|
A mapping of basis strings to SQuIN kernels consisting of a clifford circuit applied to your logical qubits. |
These |
kernels will be appended to your circuits in the following fashion, for each `basis_label in tomography_circuits`
|
|
decoder |
type[ConfidenceDecoder]
|
A type of ConfidenceDecoder used to initialize decoders. |
decoder_init_args |
Mapping[str, object] | None
|
Optional arguments that can be passed in to initialize the decoder. Defaults to None. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
analysis_f_vs_fraction
analysis_f_vs_fraction(
*,
target_bloch: ndarray = _DEFAULT_TARGET_BLOCH,
threshold_points: int = 64,
min_accepted_per_basis: int = 50
) -> PostselectionCurveData
Analyzes the shot data to produce arrays for the fidelity to some target state as a function of the fraction of total accepted shots. Produces various thresholds of accepted shots by thresholding on the confidence score associated with each shot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_bloch
|
ndarray
|
The bloch vector to which fidelity is computed. Defaults to np.array([1.0, 1.0, 1.0]) / np.sqrt(3). |
_DEFAULT_TARGET_BLOCH
|
threshold_points
|
int
|
The number of thresholds that we would like to compute. We get thresholds at evenly spaced quantiles on the array of |
64
|
min_accepted_per_basis
|
int
|
The minimum number of shots that we require per basis in order to do tomography. This is to prevent very |
50
|
Returns:
| Name | Type | Description |
|---|---|---|
PostselectionCurveData |
PostselectionCurveData
|
The accepted fractions and point fidelities |
PostselectionCurveData
|
for the thresholded curve. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
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 | |
analysis_visualization
analysis_visualization(
min_accepted_fraction: float = 0.04,
title: str | None = None,
)
Plots the curve of the fidelity vs. accepted fraction, with a cutoff of min_accepted_fraction as well as a supplied title.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
493 494 495 496 497 498 499 500 501 502 503 504 505 | |
decode_and_postselect
decode_and_postselect(
postselection_condition: ndarray,
progress_label: str | bool = False,
) -> dict[str, _DecodedPostselectionResult]
With the resulting shot data from the hardware samples, runs the following steps: 1. Decoding and correction on the ancilla qubits 2. Filtering shots whose corrected ancilla observable is a valid pattern in postselection_condition 3. Out of these filtered shots, decode and correct the output qubit 4. Returns the corrected observables as well as the confidence score associated with each observable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postselection_condition
|
ndarray
|
A 2D numpy array of shape (num_conditions, num_ancillae) representing the valid ancilla patterns to postselect on. Example: If postselection_condition = np.array([[1, 0, 1, 1]]), then we will only accept shots where the first ancilla is 1, the second ancilla is 0, the third ancilla is 1, and the fourth ancilla is 1 after those ancilla have been corrected by the decoder. |
required |
progress_label
|
str | bool
|
If False, no progress bar is displayed. If True, the decoder class name is used as the progress-bar label. If a string, that string is used as the progress-bar label. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, _DecodedPostselectionResult]
|
dict[str, _DecodedPostselectionResult]: A dictionary that maps each basis to postselected observables and confidence scores per shot. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
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 | |
dem_circuits
dem_circuits() -> dict[str, tsim_backend.Circuit]
Constructs TSIM circuits annotated with error channels for each basis from the tomography kernels, which will later be used to construct detector error models.
Note: this function depends on .kernels() being invoked. Note: in the implementation of this function, to obtain a noiseless reference observable to later construct a DEM, we take our whole circuit, strip away the noise, and prepend it to our circuit so that the noiseless behavior is U^dagU = I.
Returns:
| Type | Description |
|---|---|
dict[str, Circuit]
|
dict[str, tsim_backend.Circuit]: A dictionary mapping each basis label to a compiled TSIM circuit with noise channels, where the observables |
dict[str, Circuit]
|
in noiseless simulation are all 0. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
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 | |
dems
dems() -> dict[str, stim.DetectorErrorModel]
Constructs detector error models from the noisy circuits in each basis. Defaults to approximating disjoint errors.
Note: this function depends on dem_circuits() being called.
Returns:
| Type | Description |
|---|---|
dict[str, DetectorErrorModel]
|
dict[str, stim.DetectorErrorModel]: A dictionary mapping each basis label to the detector error model for the tomography |
dict[str, DetectorErrorModel]
|
circuit in that basis. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
get_samples
get_samples(num_shots: int) -> dict[str, _BasisDataset]
For each basis, samples num_shots from the hardware. Returns the detector and observable information for each task.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
initialize_decoders
initialize_decoders() -> (
dict[str, tuple[ConfidenceDecoder, BaseDecoder]]
)
Initializes the decoders for the tomography circuits in each basis from the detector error models. This function utilizes correlated decoding (https://arxiv.org/abs/2403.03272). Because of this, this function initializes two decoders: one for the decoding the ancilla qubits, and one for decoding the output qubit. The decoder that decodes the ancilla qubits decodes them jointly, taking in (num_ancillas * 3) detectors and outputting corrections for (num_ancillas) observables. This decoder does not additionally take in the output qubit's detectors for the case that the output qubit might be used later in the computation. The decoder that decodes the output qubit decodes it jointly with the ancilla qubits, taking in ((num_ancillas + 1) * 3) detectors and outputting corrections for 1 observable (on the output qubit). This function assumes that the first qubit is the output qubit, and also assumes that we are using the [[7, 1, 3]] Steane code, which has three detectors per logical qubit.
Note: this function depends on dems() being called.
Returns:
| Type | Description |
|---|---|
dict[str, tuple[ConfidenceDecoder, BaseDecoder]]
|
dict[str, tuple[ConfidenceDecoder, BaseDecoder]]: A dictionary mapping each basis label to (factory_decoder, full_decoder), where factory_decoder |
dict[str, tuple[ConfidenceDecoder, BaseDecoder]]
|
decodes the ancilla qubits jointly and full_decoder decodes the output qubit jointly with the information on all logical qubits. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
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 | |
kernels
kernels(
num_logical_qubits: int = 5,
) -> dict[str, ir.Method[..., _LogicalTomographyReturn]]
Composes the nonclifford, clifford, and tomography kernels into a dictionary mapping each basis label to the respective nonclifford + clifford + tomography kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_logical_qubits
|
int
|
An integer corresponding to the number of logical qubits allocated in the kernels. |
5
|
Returns:
| Type | Description |
|---|---|
dict[str, Method[..., _LogicalTomographyReturn]]
|
dict[str, ir.Method[..., _LogicalTomographyReturn]]: A dictionary mapping the tomography basis labels to the respective kernel used for tomography. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
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 | |
make_tasks
make_tasks(
device: GeminiLogicalSimulator,
) -> dict[
str,
GeminiLogicalSimulatorTask[_LogicalTomographyReturn],
]
Prepares tasks for submission to the hardware device.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
tomography_result
tomography_result(
accepted_fraction: float,
) -> TomographyResult
Returns a TomographyResult after decoding and postselection with the option to manually specify the fraction of shots accepted.
The implementation will find the minimum number of shots to accept where the fraction of accepted shots is >= accepted_fraction, sorted by highest to lowest confidence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accepted_fraction
|
float
|
The fraction of shots to accept out of shots that passed postselection. Note that if accepted_fraction == 1.0, this means |
required |
Returns:
| Name | Type | Description |
|---|---|---|
TomographyResult |
TomographyResult
|
The resulting shots in each basis based on the accepted_fraction provided. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
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 488 489 490 491 | |
PostselectionCurveData
dataclass
PostselectionCurveData(
accepted_fraction: ndarray,
fidelity: ndarray,
point_fidelity: ndarray,
)
Point-estimate fidelity curve from thresholded postselection.
TableDecoderWithConfidence
TableDecoderWithConfidence(
dem: DetectorErrorModel,
*,
num_shots: int = 10**7,
seed: int | None = None,
step_size: int | None = None
)
Bases: TableDecoder, ConfidenceDecoder
flowchart TD
bloqade.gemini.decoding.TableDecoderWithConfidence[TableDecoderWithConfidence]
bloqade.gemini.decoding.table_decoders.TableDecoder[TableDecoder]
bloqade.gemini.decoding.confidence.ConfidenceDecoder[ConfidenceDecoder]
bloqade.gemini.decoding.table_decoders.TableDecoder --> bloqade.gemini.decoding.TableDecoderWithConfidence
bloqade.gemini.decoding.confidence.ConfidenceDecoder --> bloqade.gemini.decoding.TableDecoderWithConfidence
click bloqade.gemini.decoding.TableDecoderWithConfidence href "" "bloqade.gemini.decoding.TableDecoderWithConfidence"
click bloqade.gemini.decoding.table_decoders.TableDecoder href "" "bloqade.gemini.decoding.table_decoders.TableDecoder"
click bloqade.gemini.decoding.confidence.ConfidenceDecoder href "" "bloqade.gemini.decoding.confidence.ConfidenceDecoder"
Dense table decoder with empirical per-syndrome confidence.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/table_decoders.py
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 | |
decode
decode(detector_bits: ndarray) -> np.ndarray
Decode detector bits after validating the detector-shot width.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/table_decoders.py
154 155 156 157 158 159 160 161 162 163 | |
decode_with_confidence
decode_with_confidence(
detector_bits: ndarray,
) -> tuple[np.ndarray, np.float64]
Decode one detector syndrome and return its empirical confidence.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/table_decoders.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
TomographyResult
dataclass
TomographyResult(shots_by_basis: Mapping[str, ndarray])
Point-estimate single-qubit tomography result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shots_by_basis
|
Mapping[str, ndarray]
|
A mapping of each basis to an array of shots (0/1's) in each basis. |
required |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/tomography.py
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 | |
fidelity_bloch
fidelity_bloch(
target_bloch: ndarray | Sequence[float],
tol: float = 1e-10,
) -> float
Return the fidelity to a target state from its Bloch vector.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/tomography.py
108 109 110 111 112 113 114 115 116 117 118 | |
empty_logical_circuit
empty_logical_circuit() -> ir.Method[..., None]
Return a no-op logical Squin kernel for injected-state tomography.
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
88 89 90 91 92 93 94 95 96 97 | |
magic_state_dist_steane
magic_state_dist_steane(
*,
theta_offset: float = 0.0,
phi_offset: float = 0.0,
lam_offset: float = 0.0
) -> tuple[ir.Method[..., None], ir.Method[..., None]]
Returns the nonclifford prefix circuit and clifford logical circuit used for magic state distillation. Note that the kernels take in the qubit register 'reg' as input. This means that the kernels are technically agnostic to the number of input qubits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theta_offset
|
float
|
An optional offset to theta to manually introduce rotation error in the nonclifford prefix. Defaults to 0.0. |
0.0
|
phi_offset
|
float
|
An optional offset to phi to manually introduce rotation error in the nonclifford prefix. Defaults to 0.0. |
0.0
|
lan_offset
|
float
|
An optional offset to lam to manually introduce rotation error in the nonclifford prefix. Defaults to 0.0. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Method[..., None], Method[..., None]]
|
tuple[ir.Method[..., None], ir.Method[..., None]]: The (nonclifford_prefix, logical_circuit) pair. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
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 | |
single_qubit_state_tomography
single_qubit_state_tomography() -> (
dict[str, ir.Method[..., None]]
)
Returns X, Y, and Z basis kernels used to perform single-qubit tomography. Note that the kernels take in the register as the input.
Returns:
| Type | Description |
|---|---|
dict[str, Method[..., None]]
|
dict[str, ir.Method[..., None]]: A dictionary mapping "X", "Y", and "Z" to the respective tomography kernels. |
Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/decoding/experiments.py
76 77 78 79 80 81 82 83 84 85 | |