Quick Start
Check your installation by running a small offline decoding experiment. You will construct a decoder, calculate syndromes for known bit flips, and verify that applying its corrections recovers the original bits.
Before You Start
Complete the Installation Guide, then use the same Python environment or container shell for the commands below. This example uses the built-in CPU look-up table decoder and NumPy. It needs no GPU, QPU, or optional decoder packages.
Run the Experiment
A three-bit repetition code represents a bit as 000 or 111 and can
correct one bit flip. Its two parity checks compare neighboring bits: a check
returns 1 when those bits disagree. The pair of check results is the
syndrome supplied to the decoder.
Start from 000 and try four cases: no error and a single bit flip at each
position. The decoder receives only the syndrome; it does not receive the
injected error. After decoding, the script applies the suggested correction
and checks that the result is 000.
Save the following as quick_start.py, or
download the script:
import numpy as np
import cudaq_qec as qec
# Each row compares a neighboring pair of bits in a three-bit repetition code.
H = np.array([[1, 1, 0], [0, 1, 1]], dtype=np.uint8)
decoder = qec.get_decoder("single_error_lut", H)
# Start from 000 and inject no error or one bit flip at each position.
errors = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=np.uint8)
for error in errors:
syndrome = (H @ error) % 2
result = decoder.decode(syndrome)
correction = np.array(result.result, dtype=np.uint8)
corrected = (error + correction) % 2
assert result.converged, "The decoder did not find a correction."
assert np.array_equal(corrected,
[0, 0, 0]), "The original bits were not recovered."
print(f"error={error.tolist()} syndrome={syndrome.tolist()} "
f"corrected={corrected.tolist()}")
print("Installation check passed: all 4 cases recovered.")
Run it from the directory where you saved the file:
python3 quick_start.py
Expected Result
The script prints:
error=[0, 0, 0] syndrome=[0, 0] corrected=[0, 0, 0]
error=[1, 0, 0] syndrome=[1, 0] corrected=[0, 0, 0]
error=[0, 1, 0] syndrome=[1, 1] corrected=[0, 0, 0]
error=[0, 0, 1] syndrome=[0, 1] corrected=[0, 0, 0]
Installation check passed: all 4 cases recovered.
Import-time notices from CUDA-Q may appear before these lines.
The final line confirms that Python loaded CUDA-Q QEC, constructed the decoder, and recovered all four cases. This checks the basic CPU decoding path; GPU decoders and realtime integration have their own requirements.
Next Steps
See QEC Decoders to choose a decoder for your workload. For experiments with sampled noise, continue with Experiments and Noise Modeling.