7.2. Repetition Code

7.2.1. Repetition Code Block

The RepetitionCode is a simple \([n, 1, n]\) error-correcting code that encodes a single logical qubit with \(n\) physical qubits. By specifying the code distance \(d\), stabilizer type (X or Z), the physical lattice, and lattice position, this code factory allows the user to build Block that describe one logical qubit with the specified parameters.

The example below shows how to create a repetition code with 5 data qubits, which encodes a single logical qubit with X stabilizers.

from loom_repetition_code.code_factory import RepetitionCode
from loom.eka import Lattice

lattice = Lattice.linear((10,))

# Create a block for a repetition code with 5 data qubits
myLogicalqubit = RepetitionCode.create(
    d = 5,
    check_type = "X",   # Specify the type of stabilizers (X or Z), this code will only detects Z errors
    lattice=lattice,
    unique_label = "repetition_code_5",
    position =  (0,),
)

7.2.2. Operations on Repetition Code

The operations module provides high-level definition of operations that can be applied on Block objects. The lower-level implementations specific to RepetitionCode class, are defined in the applicator module.

On top of the common operations (resets, logical measurements, etc…), the repetition code applicators include implementations for the following operations:

  • grow: Expand the size of a repetition code Block by adding qubits and stabilizers around its perimeter, increasing its logical qubit capacity or error-correcting capabilities.

  • merge: Combine two adjacent repetition code Block into a single larger block by joining their boundaries, enabling operations across the combined logical qubits.

  • shrink: Reduce the size of a repetition code Block by removing qubits and stabilizers from its edges, typically to free resources or prepare for operations like splitting.

  • split: Divide a repetition code Block into two smaller Block by creating boundaries within the original block, allowing independent manipulation of the resulting logical qubits.

Growing, merging, shrinking, and splitting are operations that modify the structure of the repetition code, allowing for dynamic changes to the logical qubit configuration.

Example of application :

from loom_repetition_code.code_factory import RepetitionCode
from loom.eka import Eka, Lattice
from loom.eka.operations import ResetAllDataQubits, MeasureBlockSyndromes, Shrink, Merge, MeasureLogicalZ
from loom.interpreter import interpret_eka

lattice = Lattice.linear(...)
# Assuming you have RepetitionCode blocks created
rep_block_1 = RepetitionCode.create(unique_label="rep_block_1", ...)
rep_block_2 = RepetitionCode.create(unique_label="rep_block_2", ...)

ops = [
    ResetAllDataQubits(rep_block_1.unique_label),
    MeasureBlockSyndromes(rep_block_1.unique_label, n_cycles=1),
    Shrink(rep_block_1.unique_label, direction="right", length=2),
    Merge([rep_block_1.unique_label, rep_block_2.unique_label], "rep_block_3", orientation="horizontal"),
    MeasureBlockSyndromes("rep_block_3", n_cycles=1),
    MeasureLogicalZ("rep_block_3"),
]

# Interpret the operations on the repetition code blocks
eka = Eka(lattice, blocks=[rep_block_1, rep_block_2], operations=ops)
# This will contain the circuit, syndromes and detectors of the system resulting from the operations.
final_state = interpret_eka(eka)