qldpc.circuits.common

Miscellaneous circuit utilities.

Attributes

CircuitOrTableau

Params

StimCircuitLike

Classes

StimCircuitProtocol

Structural type for circuit objects that behave like a stim.Circuit.

Functions

get_pauli_product_measurements(→ stim.Circuit)

Construct a circuit of MPP instructions that measure the given Pauli strings.

get_unaddressed_measurements(→ list[int])

Identify measurements, by index, that are not addressed by detectors or observables.

remap_qubit_target(→ stim.GateTarget)

Remap the qubit addressed by a stim.GateTarget, if any.

restrict_to_qubits(→ collections.abc.Callable[Params, ...)

Restrict a circuit or tableau constructor to qubit-based codes.

with_remapped_qubits(→ StimCircuitLike)

The same circuit, but with relabeled qubits.

Module Contents

class qldpc.circuits.common.StimCircuitProtocol[source]

Bases: Protocol

Structural type for circuit objects that behave like a stim.Circuit.

A stim.Circuit satisfies this protocol, as do stim-wrapping circuit classes such as tsim.Circuit. qLDPC’s circuit-polymorphic functions (e.g. noisy_circuit, with_remapped_qubits) are generic over the StimCircuitLike type variable (bound to this protocol) so that they preserve the concrete circuit type of their input. Those functions read a circuit as a sequence of stim operations (via range(len(circuit)) and indexing), do their work on a stim.Circuit, and rebuild a circuit of the original type by constructing an empty instance (type(circuit)()) and populating it via append / in-place concatenation. A conforming circuit must therefore be default-constructible in addition to supporting the methods declared here. This lets qLDPC support such circuits structurally, without depending on the packages that define them.

append(name: str | stim.CircuitInstruction | stim.CircuitRepeatBlock | stim.Circuit, targets: int | stim.GateTarget | stim.PauliString | collections.abc.Iterable[int | stim.GateTarget | stim.PauliString] = (), arg: float | collections.abc.Iterable[float] | None = None, *, tag: str = '') → None[source]

Append an operation to this circuit in place.

qldpc.circuits.common.get_pauli_product_measurements(pauli_strings: collections.abc.Sequence[stim.PauliString] | collections.abc.Sequence[collections.abc.Sequence[int]] | numpy.typing.NDArray[numpy.int_], qubits: collections.abc.Sequence[int] | None = None) → stim.Circuit[source]

Construct a circuit of MPP instructions that measure the given Pauli strings.

In addition to a list of Pauli strings, this method accepts a symplectic matrix (or a sequence of symplectic rows) in which each row indicates the [X|Z] support of a Pauli string. If “code” is a QuditCode, for example, then passing “pauli_strings=code.get_stabilizer_ops()” will measure the stabilizers of “code”.

Parameters:
  • pauli_strings – Pauli strings or symplectic rows to measure.

  • qubits – Optional physical-qubit labels corresponding to the columns of each Pauli string.

qldpc.circuits.common.get_unaddressed_measurements(circuit: stim.Circuit) → list[int][source]

Identify measurements, by index, that are not addressed by detectors or observables.

qldpc.circuits.common.remap_qubit_target(target: stim.GateTarget, qubit_map: collections.abc.Mapping[int, int]) → stim.GateTarget[source]

Remap the qubit addressed by a stim.GateTarget, if any.

MPAD padding-bit targets are not qubits and are intentionally preserved by with_remapped_qubits() before this helper is called.

qldpc.circuits.common.restrict_to_qubits(func: collections.abc.Callable[Params, CircuitOrTableau]) → collections.abc.Callable[Params, CircuitOrTableau][source]

Restrict a circuit or tableau constructor to qubit-based codes.

qldpc.circuits.common.with_remapped_qubits(circuit: StimCircuitLike, qubit_map: collections.abc.Mapping[int, int] | collections.abc.Sequence[int], *, inverse: bool = False) → StimCircuitLike[source]

The same circuit, but with relabeled qubits.

Qubits not in qubit_map get mapped to themselves.

Parameters:
  • circuit – The circuit to remap.

  • qubit_map – Either a mapping (e.g., dictionary) from old to new qubit indices, or a sequence for which the qubit at index old_index gets mapped to new_index = qubit_map[old_index].

  • inverse – If True, invert the provided qubit_map. Default: False.

Returns:

The input circuit with remapped qubits.

qldpc.circuits.common.CircuitOrTableau
qldpc.circuits.common.Params
qldpc.circuits.common.StimCircuitLike