qldpc.circuits.bookkeeping
Helper objects to keep track of qubits, measurements, and detectors.
Classes
An organized record of detectors in a Stim circuit. |
|
An organized record of measurements in a Stim circuit. |
|
Container to keep track of the indices and roles of qubits in a circuit. |
|
An organized record of events in a Stim circuit. |
Module Contents
- class qldpc.circuits.bookkeeping.DetectorRecord(initial_record: collections.abc.Mapping[collections.abc.Hashable, collections.abc.Iterable[int] | int] | None = None)[source]
Bases:
RecordAn organized record of detectors in a Stim circuit.
- after_post_selection(key: collections.abc.Hashable) DetectorRecord[source]
A record of the detectors remaining after post-selecting on the detectors of a key.
If “detector_record” is the record of the detectors in circuit whose detector error model is represented by the qldpc.decoders.DetectorErrorModelArrays object “dem_arrays”, the record:
new_detector_record = detector_record.after_post_selection(key)
is the record of the detectors in:
new_dem_arrays = dem_arrays.post_selected_on(detector_record.get_events(key))
See help(qldpc.decoders.DetectorErrorModelArrays).
- get_detector(key: collections.abc.Hashable, detection_index: int = -1) int[source]
Retrieve a Stim detector (by index) associated with the given key.
- Parameters:
key – The name associated with a sequence of detectors in the record.
detection_index – An index specifying which detector in the specified sequence we want. A detection_index of 0 would be the first detector in the sequence, while a detection_index of -1 would be the last detector. Default value: -1.
- Returns:
The index of a detector.
- Return type:
int
- class qldpc.circuits.bookkeeping.MeasurementRecord(initial_record: collections.abc.Mapping[collections.abc.Hashable, collections.abc.Iterable[int] | int] | None = None)[source]
Bases:
RecordAn organized record of measurements in a Stim circuit.
- get_target_rec(qubit: collections.abc.Hashable, measurement_index: int = -1) stim.GateTarget[source]
Retrieve a Stim measurement record target for the given qubit.
- Parameters:
qubit – The qubit whose measurement record we want.
measurement_index – An index specifying which measurement of the specified qubit we want. A measurement_index of 0 would be the first measurement of the qubit, while a measurement_index of -1 would be the most recent measurement. Default value: -1.
- Returns:
A Stim measurement record target.
- Return type:
stim.target_rec
- validate_num_measurements(num_measurements: int) None[source]
Validate synchronization with a circuit’s measurement count.
- Parameters:
num_measurements – The number of measurements in the circuit at the point where this record will be consumed.
- Raises:
ValueError – If the circuit and record contain different numbers of measurements.
- class qldpc.circuits.bookkeeping.QubitIDs(data: int | collections.abc.Sequence[int], check: int | collections.abc.Sequence[int] = (), ancilla: int | collections.abc.Sequence[int] = (), *, reference: int | collections.abc.Sequence[int] = ())[source]
Container to keep track of the indices and roles of qubits in a circuit.
- static from_code(code: qldpc.codes.QuditCode, *, num_ancillas: int = 0, num_references: int = 0, shift: int = 0) QubitIDs[source]
Initialize from an error-correcting code with specific parity checks.
- static validated(qubit_ids: QubitIDs, code: qldpc.codes.QuditCode) QubitIDs[source]
Validate qubit IDs for the given code and return a copy.
- property all_qubits: tuple[int, ...]
Serialized tuple of all qubits tracked by this QubitIDs object.
- ancilla: tuple[int, ...]
- check: tuple[int, ...]
- checks_x: tuple[int, ...] = ()
- checks_z: tuple[int, ...] = ()
- data: tuple[int, ...]
- reference: tuple[int, ...]
- class qldpc.circuits.bookkeeping.Record(initial_record: collections.abc.Mapping[collections.abc.Hashable, collections.abc.Iterable[int] | int] | None = None)[source]
Bases:
collections.abc.Mapping[collections.abc.Hashable,list[int]]An organized record of events in a Stim circuit.
A record is essentially a dictionary that maps some key (such as a qubit index) to an ordered list of the events (such as measurements or detectors) associated with that key. The events that a Record keeps track of are assumed to be indexed from zero.
Record is subclassed by MeasurementRecord to keep track of measurements in a circuit, and by DetectorRecord to keep track of the detectors in a circuit.
- append(record: collections.abc.Mapping[collections.abc.Hashable, collections.abc.Iterable[int] | int], repeat: int = 1) None[source]
Append the given record to this one.
All event numbers in the appended record are increased by the number of events in the current record. That is, if the current record holds n events numbered from 0 to
n - 1, then events (0, 1, …) in the appended record are added to the current record as(n, n+1, ...).
- get_events(*keys: collections.abc.Hashable) list[int][source]
All events associated with the given keys.
- items() collections.abc.ItemsView[collections.abc.Hashable, list[int]][source]
Iterator over keys and their associated events.
- key_to_events: dict[collections.abc.Hashable, list[int]]
- num_events: int