qldpc.circuits.encoding

Encoding circuits, logical tableaus, and analysis of logical states.

Functions

get_encoder_and_decoder(→ tuple[stim.Tableau, ...)

Encoder for a code, and decoder either the same code or a deformed code.

get_encoding_circuit(→ stim.Circuit)

Circuit to encode physical states at its input into logical states of the given code.

get_encoding_tableau(→ stim.Tableau)

Tableau to encode physical states at its input into logical states of the given code.

get_logical_state_stabilizers(→ list[stim.PauliString])

Identify pure logical operators that stabilize the state prepared by the provided circuit.

get_logical_tableau(→ stim.Tableau)

Identify the logical tableau implemented by the physical circuit or tableau.

get_state_stabilizers(→ list[stim.PauliString])

Identify stabilizers of the prepared state that are supported on specified qubits.

restrict_tableau(→ stim.Tableau)

Restrict the given stabilizer tableau to the sub-tableau at the specified qubits.

Module Contents

qldpc.circuits.encoding.get_encoder_and_decoder(code: qldpc.codes.QuditCode, deformation: stim.Circuit | stim.Tableau | None = None) → tuple[stim.Tableau, stim.Tableau][source]

Encoder for a code, and decoder either the same code or a deformed code.

qldpc.circuits.encoding.get_encoding_circuit(code: qldpc.codes.QuditCode, *, only_zero: bool = False) → stim.Circuit[source]

Circuit to encode physical states at its input into logical states of the given code.

If only_zero is True, this circuit maps an all-0 physical state at its input to an all-0 logical state at its output. Otherwise, for all j in {0, 1, ..., code.dimension - 1}, this circuit maps weight-one X_j and Z_j operators at its input to the logical X and Z operators of the j-th logical qubit of the code. Weight-one Z_j operators for j >= code.dimension get mapped to “Z-type” gauge operators and stabilizers, and their conjugate X_j get mapped to “X-type” gauge operators and destabilizers.

Warning: The resulting encoding circuit is not fault-tolerant.

qldpc.circuits.encoding.get_encoding_tableau(code: qldpc.codes.QuditCode, *, only_zero: bool = False) → stim.Tableau[source]

Tableau to encode physical states at its input into logical states of the given code.

If only_zero is True, this tableau maps an all-0 physical state at its input to an all-0 logical state at its output. Otherwise, for all j in {0, 1, ..., code.dimension - 1}, this tableau maps weight-one X_j and Z_j operators at its input to the logical X and Z operators of the j-th logical qubit of the code. Weight-one Z_j operators for j >= code.dimension get mapped to “Z-type” gauge operators and stabilizers, and their conjugate X_j get mapped to “X-type” gauge operators and destabilizers.

qldpc.circuits.encoding.get_logical_state_stabilizers(state_prep_circuit: stim.Circuit, code: qldpc.codes.QuditCode, qubit_ids: qldpc.circuits.bookkeeping.QubitIDs | None = None) → list[stim.PauliString][source]

Identify pure logical operators that stabilize the state prepared by the provided circuit.

The first len(code) qubits addressed by the circuit must be the data qubits of the code.

Parameters:
  • state_prep_circuit – A circuit that prepares a logical state of the provided code.

  • code – The code whose logical state is prepared by the provided state_prep_circuit.

  • qubit_ids – A QubitIDs object specifying the indices of the data qubits of the code. If None, the data qubits of the code are assumed to be range(len(code)).

Returns:

A list of Pauli strings supported on the data qubits of the provided code.

qldpc.circuits.encoding.get_logical_tableau(code: qldpc.codes.QuditCode, physical_circuit_or_tableau: stim.Circuit | stim.Tableau, *, deform_code: bool = False) → stim.Tableau[source]

Identify the logical tableau implemented by the physical circuit or tableau.

If deform_code is True, then the physical circuit is required to have two effects, namely (a) transforming a logical state of the QuditCode by a corresponding logical Clifford gate, and (b) changing the code that encodes the logical state to:

code.deformed(physical_circuit, preserve_logicals=True)
qldpc.circuits.encoding.get_state_stabilizers(state_prep_circuit: stim.Circuit, qubits: collections.abc.Sequence[int] | int) → list[stim.PauliString][source]

Identify stabilizers of the prepared state that are supported on specified qubits.

The strategy in this method is as follows. If we prepend reset operations to make an initial |0...0⟩ initial state explicit, then all stabilizer flows of the circuit should have the form

1 -> output_generator,

where each output_generator is an XOR of

  1. a Pauli string,

  2. measurements, and

  3. observables.

That is, the circuit prepares a state for which, after identifying {+1,-1} <-> {0,1} as necessary, the XOR of (a), (b), and (c) for each output_generator is 0.

To identify a basis of output generators (in this case, Pauli strings) that are supported only on the specified qubits, we collect all output generators into a binary matrix and row-reduce this matrix.

Parameters:
  • state_prep_circuit – A circuit that prepares a logical state of the provided code.

  • qubits – The qubits on which we are looking for stabilizers. If provided an integer, target the qubits indexed by range(qubits).

Returns:

A list of Pauli strings supported on the specified qubits. The strings are compacted into the requested-qubit frame: position i refers to qubits[i] in the input circuit.

qldpc.circuits.encoding.restrict_tableau(tableau: stim.Tableau, qubits: collections.abc.Sequence[int]) → stim.Tableau[source]

Restrict the given stabilizer tableau to the sub-tableau at the specified qubits.

The selected qubits must be a closed subsystem: the tableau must not map a selected Pauli to support outside qubits. This function does not check that precondition; if it is violated, the result is simply the submatrices restricted to qubits, silently discarding any support that spilled outside the selection.