### Install LDPC Package via Pip Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/installation.md Instructions for installing the LDPC package directly from PyPI using the pip package manager. This is the simplest method for quick setup. ```Bash pip install -U ldpc ``` -------------------------------- ### Install LDPC Python Bindings from Source Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/installation.md Steps to clone the LDPC repository and install the Python bindings from source. This method requires a C compiler (e.g., gcc or clang) and Python 3.8 or higher. ```Bash git clone git@github.com:quantumgizmos/ldpc_v2.git cd ldpc pip install -Ue . ``` -------------------------------- ### Install LDPC Python Package from Source Source: https://github.com/quantumgizmos/ldpc/blob/main/README.md These commands clone the LDPCv2 repository from GitHub, navigate into the directory, and then install the Python package in editable mode from the local source. A C compiler is required for this installation method. ```bash git clone git@github.com:quantumgizmos/ldpc_v2.git cd ldpc pip install -Ue . ``` -------------------------------- ### Install LDPC Python Package via Pip Source: https://github.com/quantumgizmos/ldpc/blob/main/README.md This command installs the latest version of the LDPC Python package using pip. It's the easiest way to get started with LDPCv2, requiring Python versions 3.9 or higher. ```bash pip install -U ldpc ``` -------------------------------- ### Install Specific Version of LDPCv1 Python Package Source: https://github.com/quantumgizmos/ldpc/blob/main/README.md This command installs a specific older version (0.1.60) of the LDPC package. This is useful for projects that require backward compatibility with LDPCv1. ```bash pip install -U ldpc==0.1.60 ``` -------------------------------- ### Example Usage of BP+LSD Decoder in Python Source: https://github.com/quantumgizmos/ldpc/blob/main/README.md This Python snippet demonstrates how to initialize and use the BP+LSD decoder with a Hamming code. It shows how to create a BpLsdDecoder instance with various parameters, generate a random syndrome, and then decode it, printing the original and decoded syndromes. ```python import numpy as np import ldpc.codes from ldpc.bplsd_decoder import BpLsdDecoder H = ldpc.codes.hamming_code(5) ## The bp_osd = BpLsdDecoder( H, error_rate = 0.1, bp_method = 'product_sum', max_iter = 2, schedule = 'serial', lsd_method = 'lsd_cs', lsd_order = 0 ) syndrome = np.random.randint(size=H.shape[0], low=0, high=2).astype(np.uint8) print(f"Syndrome: {syndrome}") decoding = bp_osd.decode(syndrome) print(f"Decoding: {decoding}") decoding_syndrome = H@decoding % 2 print(f"Decoding syndrome: {decoding_syndrome}") ``` -------------------------------- ### Example: Error Correction over Binary Symmetric Channel Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/bp_decoding_example.ipynb Presents a comprehensive example of error correction using `BpDecoder` over a binary symmetric channel. It includes setting up the decoder, simulating random errors, calculating syndromes, and performing decoding in a loop to demonstrate the process over multiple runs. ```python import numpy as np from ldpc.codes import rep_code from ldpc import BpDecoder n = 13 error_rate = 0.3 runs = 5 H = rep_code(n) # BP decoder class. Make sure this is defined outside the loop bpd = BpDecoder(H, error_rate=error_rate, max_iter=n, bp_method="product_sum") error = np.zeros(n).astype(int) # error vector for _ in range(runs): for i in range(n): if np.random.random() < error_rate: error[i] = 1 else: error[i] = 0 syndrome = H @ error % 2 # calculates the error syndrome print(f"Error: {error}") print(f"Syndrome: {syndrome}") decoding = bpd.decode(syndrome) print(f"Decoding: {decoding}\n") ``` -------------------------------- ### Initialize and use Belief Propagation + Ordered Statistics Decoder (BP+OSD) in Python Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/quantum_decoder.ipynb This snippet demonstrates the initialization and usage of the `BpOsdDecoder` from the `ldpc` package. It inherits from `ldpc.BpDecoder` and requires specifying `osd_method` and `osd_order`. The example shows how to create a Hamming code, initialize the decoder with parameters like error rate, BP method, max iterations, and schedule, then decode a random syndrome and verify the result. ```python import numpy as np import ldpc.codes from ldpc import BpOsdDecoder H = ldpc.codes.hamming_code(5) ## The bp_osd = BpOsdDecoder( H, error_rate=0.1, bp_method="product_sum", max_iter=7, schedule="serial", osd_method="osd_cs", # set to OSD_0 for fast solve osd_order=2, ) syndrome = np.random.randint(size=H.shape[0], low=0, high=2).astype(np.uint8) print(f"Syndrome: {syndrome}") decoding = bp_osd.decode(syndrome) print(f"Decoding: {decoding}") decoding_syndrome = H @ decoding % 2 print(f"Decoding syndrome: {decoding_syndrome}") ``` -------------------------------- ### Compute Code Parameters for a Custom LDPC Parity Check Matrix Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Provides an example of calculating the `n`, `k`, and `d` parameters for a user-defined LDPC parity check matrix `H` using `ldpc.code_util.compute_code_parameters`. ```python import ldpc.code_util H = np.array( [ [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1], [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0] ] ) n, k, d_estimate = ldpc.code_util.compute_code_parameters(H) print(f"Code parameters: [n = {n}, k = {k}, d <= {d_estimate}]") ``` -------------------------------- ### Initialize and use Belief Propagation + Localized Statistics Decoder (BP+LSD) in Python Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/quantum_decoder.ipynb This snippet illustrates the setup and application of the `BpLsdDecoder` from the `ldpc.bplsd_decoder` module. Similar to OSD, LSD solves decoding via matrix inversion but on local error clusters, significantly speeding up decoding for large parity check matrices. It inherits from `ldpc.BpDecoder` and uses `lsd_method` and `lsd_order` parameters. The example demonstrates creating a Hamming code, configuring the decoder, and processing a random syndrome. ```python import numpy as np import ldpc.codes from ldpc.bplsd_decoder import BpLsdDecoder H = ldpc.codes.hamming_code(5) ## The bp_osd = BpLsdDecoder( H, error_rate=0.1, bp_method="product_sum", max_iter=2, schedule="serial", osd_method="lsd_cs", osd_order=2, ) syndrome = np.random.randint(size=H.shape[0], low=0, high=2).astype(np.uint8) print(f"Syndrome: {syndrome}") decoding = bp_osd.decode(syndrome) print(f"Decoding: {decoding}") decoding_syndrome = H @ decoding % 2 print(f"Decoding syndrome: {decoding_syndrome}") ``` -------------------------------- ### LDPC API Module Reference Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/index.rst Lists the core modules available in the LDPC Python library, providing an overview of its API structure and the main components for coding and decoding operations. ```APIDOC ldpc API Modules: - ldpc/codes - ldpc/mod2 - ldpc/code_util - ldpc/bp_decoder - ldpc/belief_find_decoder - ldpc/bposd_decoder - ldpc/bplsd_decoder - ldpc/union_find_decoder - ldpc/monte_carlo_simulation - ldpc/sinter_decoders - ldpc/soft_info_belief_propagation ``` -------------------------------- ### Configure GoogleTest Library with CMake FetchContent Source: https://github.com/quantumgizmos/ldpc/blob/main/cpp_test/CMakeLists.txt This CMake snippet demonstrates how to download and make the GoogleTest library available within a project using `FetchContent`. It also includes a specific setting for Windows to prevent conflicts with the parent project's runtime library settings by forcing shared CRT. ```CMake include(FetchContent) FetchContent_Declare( GoogleTest URL ${CMAKE_CURRENT_SOURCE_DIR}/google_test.zip ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Make the GoogleTest library available to the project FetchContent_MakeAvailable(GoogleTest) ``` -------------------------------- ### Conditionally Add Subdirectories and Enable Testing Source: https://github.com/quantumgizmos/ldpc/blob/main/CMakeLists.txt This section conditionally adds the 'cpp_example' subdirectory if it's the master project. It also enables testing using Google Test and adds the 'cpp_test' subdirectory if the 'BUILD_LDPC_TESTS' option is enabled. ```CMake if (LDPC_MASTER_PROJECT) add_subdirectory(cpp_example) endif() if(BUILD_LDPC_TESTS) enable_testing() include(GoogleTest) add_subdirectory(cpp_test) endif() ``` -------------------------------- ### Initialize BeliefFindDecoder with Inversion UF Method and Decode Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/quantum_decoder.ipynb This snippet demonstrates initializing the `BeliefFindDecoder` with `uf_method="inversion"` and then decoding a randomly generated syndrome. It shows the input syndrome, the decoded output, and the syndrome of the decoded result. ```python bf = BeliefFindDecoder( H, error_rate=0.1, bp_method="product_sum", max_iter=7, schedule="serial", uf_method="inversion", # Union-find clusters are solved by matrix inversion bits_per_step=1 ## this is the number of bits by which clusters are expanded in each growth step ) syndrome = np.random.randint(size=H.shape[0], low=0, high=2).astype(np.uint8) print(f"Syndrome: {syndrome}") decoding = bf.decode(syndrome) print(f"Decoding: {decoding}") decoding_syndrome = H @ decoding % 2 print(f"Decoding syndrome: {decoding_syndrome}") ``` -------------------------------- ### BibTeX Citation for LDPC Python Software Source: https://github.com/quantumgizmos/ldpc/blob/main/README.md This BibTeX entry provides the recommended citation for the LDPC Python tools software. It includes author, title, URL, and year for proper academic attribution. ```BibTeX @software{Roffe_LDPC_Python_tools_2022, author = {Roffe, Joschka}, title = {{LDPC: Python tools for low density parity check codes}}, url = {https://pypi.org/project/ldpc/}, year = {2022} } ``` -------------------------------- ### Initialize BpDecoder for Belief Propagation Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/bp_decoding_example.ipynb Demonstrates how to load an instance of the `ldpc.BpDecoder` class, specifying the parity check matrix, error rate, maximum iterations, and BP method. This sets up the decoder for subsequent operations. ```python import numpy as np import ldpc.codes from ldpc import BpDecoder H = ldpc.codes.rep_code(3) # parity check matrix for the length-3 repetition code n = H.shape[1] # the codeword length bpd = BpDecoder( H, # the parity check matrix error_rate=0.1, # the error rate on each bit max_iter=n, # the maximum iteration depth for BP bp_method="product_sum" # BP method. The other option is `minimum_sum' ) ``` -------------------------------- ### Print Simulation Results to Console Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/stim_integration.ipynb This line of code calls the `print_results` function, passing the `samples` data, to output the simulation statistics in a structured CSV format directly to the console. ```Python print_results(samples) ``` -------------------------------- ### ldpc.codes Module API Documentation Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/codes.rst API documentation for the `ldpc.codes` Python module, detailing its key code generation functions. This module provides implementations for various Low-Density Parity-Check (LDPC) codes. ```APIDOC Module: ldpc.codes Description: Provides functions for generating various types of LDPC codes. Members: - hamming_code - rep_code - ring_code - random_binary_code ``` -------------------------------- ### Initialize BeliefFindDecoder with Peeling UF Method for Repetition Code Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/quantum_decoder.ipynb This snippet shows how to import necessary libraries and initialize the `BeliefFindDecoder` for a repetition code. It sets `uf_method="peeling"`, which is suitable for parity check matrices yielding point-like syndromes. ```python import numpy as np import ldpc.codes from ldpc import BeliefFindDecoder H = ldpc.codes.ring_code(15) ## The bf = BeliefFindDecoder( H, error_rate=0.1, bp_method="product_sum", max_iter=7, schedule="serial", uf_method="peeling", # If uf_method is set to False, union-find clusters are solved using a peeling decoder bits_per_step=1 ## this is the number of bits by which clusters are expanded in each growth step ) ``` -------------------------------- ### Execute Quantum Error Correction Simulation Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/stim_integration.ipynb This line of code initiates the quantum error correction simulation by calling the `run_simulation` function and stores the returned simulation results (samples) for further analysis. ```Python samples = run_simulation() ``` -------------------------------- ### Configure LDPC Main Executable with CMake Source: https://github.com/quantumgizmos/ldpc/blob/main/cpp_example/CMakeLists.txt This CMake snippet defines an executable target named 'ldpc-main' from 'main.cpp' and links it privately to the 'ldpc' library. This ensures that the executable can use functions and definitions provided by the 'ldpc' library during compilation and linking. ```CMake # Add an executable target named 'ldpc-main', which is built from the 'main.cpp' source file add_executable(ldpc-main main.cpp) # Link the 'ldpc' library to the 'ldpc-main' executable target target_link_libraries(ldpc-main PRIVATE ldpc) ``` -------------------------------- ### API Reference for ldpc.sinter_decoders.sinter_bposd_decoder Module Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/sinter_decoders.rst This snippet provides an API reference for the `ldpc.sinter_decoders.sinter_bposd_decoder` module, listing its primary classes `SinterBpOsdDecoder` and `SinterBeliefFindDecoder` as documented by Sphinx `automodule` directives. ```APIDOC Module: ldpc.sinter_decoders.sinter_bposd_decoder Classes: SinterBpOsdDecoder SinterBeliefFindDecoder ``` -------------------------------- ### ldpc.code_util Module API Reference Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/code_util.rst API documentation for the `ldpc.code_util` module, detailing its functions for constructing generator matrices, estimating and computing code distances, computing code dimensions and parameters, and searching for cycles within LDPC codes. ```APIDOC ldpc.code_util module: construct_generator_matrix() estimate_code_distance() compute_code_dimension() compute_code_parameters() search_cycles() compute_exact_code_distance() ``` -------------------------------- ### Decode Syndrome Using Peeling BeliefFindDecoder Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/quantum_decoder.ipynb Following the initialization of a `BeliefFindDecoder` (e.g., with `uf_method="peeling"`), this snippet demonstrates generating a random error, computing its syndrome, and then using the decoder to find the corresponding decoding. It prints the decoded result and its syndrome. ```python error = np.random.randint(size=H.shape[0], low=0, high=2).astype(np.uint8) syndrome = H @ error % 2 decoding = bf.decode(syndrome) print(f"Decoding: {decoding}") decoding_syndrome = H @ decoding % 2 print(f"Decoding syndrome: {decoding_syndrome}") ``` -------------------------------- ### API Reference: ldpc.bp_decoder.SoftInfoBpDecoder Class Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/soft_info_belief_propagation.rst This entry provides the API documentation for the `SoftInfoBpDecoder` class, a key component for soft information belief propagation decoding. It outlines how its documentation is generated to include all its own members, inherited members, and its full inheritance hierarchy. ```APIDOC Class: ldpc.bp_decoder.SoftInfoBpDecoder Purpose: Implements a Soft Information Belief Propagation (BP) Decoder. Documentation Directives: - :members: SoftInfoBpDecoder (Documents the class itself and its direct members) - :inherited-members: (Includes members inherited from base classes) - :undoc-members: (Includes members even if they lack docstrings) - :show-inheritance: (Displays the class inheritance hierarchy) ``` -------------------------------- ### Run Quantum Error Correction Simulations with Sinter Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/stim_integration.ipynb The `run_simulation` function orchestrates Monte Carlo simulations using `sinter.collect`. It configures the simulation environment, including the number of workers, shot limits, and integrates custom BPOSD and BeliefFind decoders with specific parameters for quantum error correction. Simulation results are saved to a CSV file. ```Python def run_simulation(): samples = sinter.collect( num_workers=10, max_shots=20_000, max_errors=100, tasks=generate_example_tasks(), decoders=["bposd", "belief_find"], custom_decoders={ "bposd": SinterBpOsdDecoder( max_iter=5, bp_method="ms", ms_scaling_factor=0.625, schedule="parallel", osd_method="osd0", ), "belief_find": SinterBeliefFindDecoder( max_iter=5, bp_method="ms", ms_scaling_factor=0.625, schedule="parallel" ), }, print_progress=True, save_resume_filepath="bposd_surface_code.csv", ) return samples ``` -------------------------------- ### Define CMake Project and Minimum Requirements Source: https://github.com/quantumgizmos/ldpc/blob/main/CMakeLists.txt This snippet sets the minimum required CMake version and defines the main project 'ldpc', specifying its description and the C++ language. It also ensures C++11 features are available for dependencies like RapidCSV. ```CMake cmake_minimum_required(VERSION 3.12...3.30) project(ldpc DESCRIPTION "ldpc - Software for classical and quantum low density parity check codes" LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) ``` -------------------------------- ### Generate Quantum Error Correction Simulation Tasks Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/stim_integration.ipynb This Python function `generate_example_tasks` creates a generator for `sinter.Task` objects. Each task configures a `stim.Circuit` representing a rotated surface code with varying distances and physical error probabilities, suitable for quantum error correction simulations. ```Python import sinter import stim import numpy as np from ldpc.sinter_decoders import SinterBeliefFindDecoder, SinterBpOsdDecoder from matplotlib import pyplot as plt def generate_example_tasks(): for p in np.arange(0.001, 0.01, 0.002): for d in [5, 7, 9]: sc_circuit = stim.Circuit.generated( rounds=d, distance=d, after_clifford_depolarization=p, after_reset_flip_probability=p, before_measure_flip_probability=p, before_round_data_depolarization=p, code_task="surface_code:rotated_memory_z", ) yield sinter.Task( circuit=sc_circuit, json_metadata={ "p": p, "d": d, "rounds": d, }, ) ``` -------------------------------- ### BibTeX Citation for Quantum Error Correction Paper Source: https://github.com/quantumgizmos/ldpc/blob/main/README.md This BibTeX entry provides the recommended citation for the paper on decoding across the quantum low-density parity-check code landscape. It should be cited if the BP+OSD class for quantum error correction is used. ```BibTeX @article{roffe_decoding_2020, title={Decoding across the quantum low-density parity-check code landscape}, volume={2}, ISSN={2643-1564}, url={http://dx.doi.org/10.1103/PhysRevResearch.2.043423}, DOI={10.1103/physrevresearch.2.043423}, number={4}, journal={Physical Review Research}, publisher={American Physical Society (APS)}, author={Roffe, Joschka and White, David R. and Burton, Simon and Campbell, Earl}, year={2020}, month={Dec} } ``` -------------------------------- ### Add and Register Test Executables with CTest Source: https://github.com/quantumgizmos/ldpc/blob/main/cpp_test/CMakeLists.txt This CMake snippet iterates through a predefined list of test executable names. For each name, it creates an executable target, links it against `gtest_main` (GoogleTest's main library) and the `ldpc` library, and then uses `gtest_discover_tests` to register the tests with CTest for discovery and execution. ```CMake foreach(TEST ${TEST_EXECUTABLES}) add_executable(${TEST} ${TEST}.cpp) # Add the test executable target_link_libraries(${TEST} PRIVATE gtest_main ldpc) # Link the libraries gtest_discover_tests(${TEST}) # Discover and register the tests endforeach() ``` -------------------------------- ### Configure LDPC Interface Library Source: https://github.com/quantumgizmos/ldpc/blob/main/CMakeLists.txt This snippet defines an interface library named 'ldpc' for header-only inclusion. It specifies the include directories for source files and external dependencies like robin_map and rapidcsv, and sets the required C++ standard to C++20 for the library. ```CMake add_library(ldpc INTERFACE) target_include_directories(ldpc INTERFACE src_cpp include/robin_map include/rapidcsv) target_compile_features(ldpc INTERFACE cxx_std_20) ``` -------------------------------- ### Configure BpDecoder for Serial Decoding Schedule Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/bp_decoding_example.ipynb Demonstrates how to switch the `BpDecoder` to a 'serial' decoding schedule by setting the `schedule` parameter during initialization. Serial scheduling can improve convergence in certain scenarios compared to the default 'parallel' schedule. ```python H = ldpc.codes.rep_code(3) # parity check matrix for the length-3 repetition code n = H.shape[1] # the codeword length bpd = BpDecoder( H, # the parity check matrix error_rate=0.1, # the error rate on each bit max_iter=n, # the maximum iteration depth for BP bp_method="product_sum", # BP method. The other option is `minimum_sum', schedule="serial" # the BP schedule ) error = np.array([0, 1, 0]) syndrome = H @ error % 2 # the syndrome of the error decoding = bpd.decode(syndrome) print(f"Error: {error}") print(f"Syndrome: {syndrome}") print(f"Decoding: {decoding}") ``` -------------------------------- ### Initialize Cluster-inversion Belief-Find Decoder in Python Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/quantum_decoder.ipynb This snippet shows the initialization of the `BeliefFindDecoder` from the `ldpc` package, specifically demonstrating the cluster-inversion variant. Belief-find combines belief propagation with a union-find post-processor. It inherits from `ldpc.BpDecoder` and can be applied to any quantum LDPC code. The provided code initializes a Hamming code and the decoder. ```python import numpy as np import ldpc.codes from ldpc import BeliefFindDecoder H = ldpc.codes.hamming_code(5) ``` -------------------------------- ### Simulating Binary Linear Codes with Monte Carlo BSC Simulation in Python Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/bp_decoding_example.ipynb This Python snippet demonstrates how to set up and run a Monte Carlo simulation for binary linear codes over a Binary Symmetric Channel (BSC) using the `ldpc` library. It initializes a parity-check matrix `H`, computes code parameters (n, k, d), configures a Belief Propagation (BP) decoder, and then runs the simulation to test code performance. ```Python import numpy as np import ldpc.codes from ldpc import BpDecoder from ldpc.monte_carlo_simulation import MonteCarloBscSimulation import ldpc.code_util H = np.array( [ [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1], [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0], [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0] ] ) n, k, d = ldpc.code_util.compute_code_parameters(H) print(f"[n={n}, k={k}, d={d}]") error_rate = 0.01 dec = BpDecoder(H, error_rate=error_rate, max_iter=0, bp_method="minimum_sum") mc_sim = MonteCarloBscSimulation( H, error_rate=error_rate, target_run_count=10000, Decoder=dec, tqdm_disable=True ) mc_sim.run() ``` -------------------------------- ### API Documentation for ldpc.bp_decoder.BpDecoder Class Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/bp_decoder.rst Documents the `BpDecoder` class, a belief propagation decoder for LDPC codes, including all its public, inherited, and undocumented members as specified by the Sphinx `autoclass` directive. ```APIDOC class ldpc.bp_decoder.BpDecoder Description: A class for decoding Low-Density Parity-Check (LDPC) codes using the belief propagation algorithm. Members: - All public members - All inherited members - All undocumented members Inheritance: Displayed ``` -------------------------------- ### API Reference for BpLsdDecoder Class Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/bplsd_decoder.rst Documents the `BpLsdDecoder` class, including its specified members and inherited members. This class is a core component for decoding functionalities within the `ldpc` library. ```APIDOC Class: ldpc.bplsd_decoder.BpLsdDecoder Members: - BpOsdDecoder Inherited Members: Included Undocumented Members: Included Show Inheritance: Yes No Index: Yes ``` -------------------------------- ### API Reference: BeliefFindDecoder Class Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/belief_find_decoder.rst Detailed API documentation for the `BeliefFindDecoder` class, including its public, inherited, and undocumented members. This class is part of the `ldpc.belief_find_decoder` module and is used for decoding operations, likely related to LDPC codes. ```APIDOC class ldpc.belief_find_decoder.BeliefFindDecoder: # This class is automatically documented. # All public members, inherited members, and undocumented members are included. # Inheritance hierarchy is shown. ``` -------------------------------- ### Decode Received Vector with BpDecoder Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/bp_decoding_example.ipynb Illustrates the process of decoding a corrupted codeword using `bp_decoder.decode`. It shows how to define an original codeword, simulate an error to create a received vector, and then apply the decoder to estimate the unerrored form. ```python codeword = np.array([1, 1, 1]) received_vector = np.array([0, 1, 1]) decoded_codeword = bpd.decode(received_vector) print(decoded_codeword) ``` -------------------------------- ### Define Test Executables for CTest Source: https://github.com/quantumgizmos/ldpc/blob/main/cpp_test/CMakeLists.txt This CMake snippet defines a list of test executable names. These names are later used in a loop to create executable targets, link necessary libraries, and register them with CTest for automated testing. ```CMake set(TEST_EXECUTABLES TestBPDecoder TestOsdDecoder TestSoftInfo TestFlipDecoder TestGf2Codes TestLsd TestSparseMatrix TestSparseMatrixUtil TestGF2Sparse TestGF2RowReduce TestGf2Linalg TestGf2Dense TestGf2DenseApplications TestUtil TestRng TestUnionFind ) ``` -------------------------------- ### ldpc.mod2 Module API Reference Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/mod2.rst This section documents the public members of the `ldpc.mod2` module, which provides functionalities for linear algebra operations in GF(2). It includes functions for computing matrix properties, bases, and decompositions. ```APIDOC Module: ldpc.mod2 Description: Implements linear algebra operations over GF(2). Members: - rank(matrix): Computes the rank of a matrix over GF(2). - kernel(matrix): Computes the null space (kernel) of a matrix over GF(2). - pivot_rows(matrix): Identifies pivot rows in the row echelon form of a matrix. - row_complement_basis(matrix): Computes a basis for the row space complement. - row_basis(matrix): Computes a basis for the row space of a matrix. - estimate_code_distance(matrix): Estimates the minimum distance of a code defined by the matrix. - row_span(matrix): Computes the row span of a matrix. - compute_exact_code_distance(matrix): Computes the exact minimum distance of a code. - row_echelon(matrix): Transforms a matrix into row echelon form. - reduced_row_echelon(matrix): Transforms a matrix into reduced row echelon form. - inverse(matrix): Computes the inverse of a square matrix over GF(2). - PluDecomposition(matrix): Performs PLU decomposition of a matrix over GF(2). ``` -------------------------------- ### Display and Plot Quantum Error Correction Results Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/stim_integration.ipynb This Python code block defines two utility functions: `print_results` and `plot_results`. `print_results` formats and prints simulation samples as CSV data. `plot_results` uses Matplotlib to visualize the logical error rates for different decoders, saving the plot and displaying it. ```Python def print_results(samples): # Print samples as CSV data. print(sinter.CSV_HEADER) for sample in samples: print(sample.to_csv_line()) def plot_results(samples): # Render a matplotlib plot of the data. fig, axis = plt.subplots(1, 2, sharey=True, figsize=(10, 5)) sinter.plot_error_rate( ax=axis[0], stats=samples, group_func=lambda stat: f"Rotated Surface Code d={stat.json_metadata['d']}", filter_func=lambda stat: stat.decoder == "bposd", x_func=lambda stat: stat.json_metadata['p'], ) sinter.plot_error_rate( ax=axis[1], stats=samples, group_func=lambda stat: f"Rotated Surface Code d={stat.json_metadata['d']}", filter_func=lambda stat: stat.decoder == "belief_find", x_func=lambda stat: stat.json_metadata['p'], ) axis[0].set_ylabel("Logical Error Rate") axis[0].set_title("BPOSD") axis[1].set_title("Belief Find") for ax in axis: ax.loglog() ax.grid() ax.set_xlabel("Physical Error Rate") ax.legend() # Save to file and also open in a window. fig.savefig("plot.png") plt.show() ``` -------------------------------- ### Compute All Code Parameters [n,k,d] for Hamming Code Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Illustrates the direct computation of all code parameters `n`, `k`, and an estimate for `d` for a given parity check matrix `H` (e.g., a rank 5 Hamming code) using `ldpc.code_util.compute_code_parameters`. ```python H = ldpc.codes.hamming_code(5) # Rank 5 Hamming Code n, k, d_estimate = ldpc.code_util.compute_code_parameters(H) print(f"Code parameters: [n = {n}, k = {k}, d <= {d_estimate}]") ``` -------------------------------- ### Load Repetition Code Parity Check Matrix using ldpc.codes Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Demonstrates how to load a repetition code's parity check matrix (H) of a specified length (n) using `ldpc.codes.rep_code`. The output shows the coordinates of non-zero elements. ```python import numpy as np import ldpc.codes import ldpc.code_util n = 5 # specifies the lenght of the repetition code H = ldpc.codes.rep_code(n) # returns the repetition code parity check matrix print(H) ``` -------------------------------- ### Configure BpDecoder for Asymmetric Error Channels Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/bp_decoding_example.ipynb Shows how to configure the `BpDecoder` to handle asymmetric error channels by providing an `error_channel` vector. This vector specifies individual error probabilities for each code bit, overriding a global error rate, and demonstrates decoding with such a channel. ```python bpd = BpDecoder( H, max_iter=n, bp_method="product_sum", error_channel=[ 0.1, 0, 0.1, ] # channel probability probabilities. Will overide error rate. ) error = np.array([1, 0, 1]) syndrome = H @ error % 2 decoding = bpd.decode(syndrome) print(f"Error: {error}") print(f"Syndrome: {syndrome}") print(f"Decoding: {decoding}") ``` -------------------------------- ### API Documentation for BpOsdDecoder Class Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/bposd_decoder.rst Documents the BpOsdDecoder class from the ldpc.bposd_decoder module. This class likely implements a decoder combining Belief Propagation (BP) and Ordered Statistics Decoding (OSD) for LDPC codes. The documentation includes its own members, inherited members, and undocumented members, and shows its inheritance hierarchy. ```APIDOC Class: ldpc.bposd_decoder.BpOsdDecoder Purpose: Implements a decoder, likely combining Belief Propagation (BP) and Ordered Statistics Decoding (OSD) techniques for LDPC codes. Module: ldpc.bposd_decoder Documentation Directives: - members: BpOsdDecoder (Indicates the class and its directly defined members are documented) - inherited-members: Includes members inherited from base classes. - undoc-members: Includes members that do not have explicit docstrings. - show-inheritance: Displays the class's inheritance hierarchy. - noindex: Prevents the class from being added to the general index. ``` -------------------------------- ### Perform Syndrome Decoding with BpDecoder Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/bp_decoding_example.ipynb Demonstrates syndrome decoding, where the error syndrome is input to the `bp_decoder.decode` function. This method is crucial when the codeword cannot be directly measured, such as in quantum error correction, and the output provides an estimate of the error. ```python H = ldpc.codes.rep_code(3) # parity check matrix for the length-3 repetition code n = H.shape[1] # the codeword length bpd = BpDecoder( H, # the parity check matrix error_rate=0.1, # the error rate on each bit max_iter=n, # the maximum iteration depth for BP bp_method="product_sum" # BP method. The other option is `minimum_sum' ) error = np.array([0, 1, 0]) syndrome = H @ error % 2 # the syndrome of the error decoding = bpd.decode(syndrome) print(f"Error: {error}") print(f"Syndrome: {syndrome}") print(f"Decoding: {decoding}") ``` -------------------------------- ### Configure OpenMP and Detect Master Project Status Source: https://github.com/quantumgizmos/ldpc/blob/main/CMakeLists.txt This section enables OpenMP support for parallel programming (though commented out in the snippet) and determines if the current build is the master project or a sub-directory integration. It also defines an option to build tests based on the master project status. ```CMake # SET(CMAKE_CXX_FLAGS "-fopenmp") # check if this is the master project or used via add_subdirectory if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(LDPC_MASTER_PROJECT ON) else() set(LDPC_MASTER_PROJECT OFF) endif() option(BUILD_LDPC_TESTS "Also build tests for the LDPC project" ${LDPC_MASTER_PROJECT}) ``` -------------------------------- ### Construct Generator Matrix (G) from Parity Check Matrix (H) Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Demonstrates how to obtain the generator matrix `G` from a parity check matrix `H` (e.g., for a Hamming code) using the `ldpc.code_util.construct_generator_matrix` function, and then displays it as an array. ```python import numpy as np import ldpc.codes import ldpc.code_util H = ldpc.codes.hamming_code(3) G = ldpc.code_util.construct_generator_matrix(H) G.toarray() ``` -------------------------------- ### Load and Display Hamming Code Parity Check Matrix Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Illustrates loading a Hamming code's parity check matrix (H) of a specified rank (e.g., 3) using `ldpc.codes.hamming_code` and then displaying it as a dense array. ```python H = ldpc.codes.hamming_code(3) print(H.toarray()) ``` -------------------------------- ### Generate and Display Error Rate Plot Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/stim_integration.ipynb This line of code invokes the `plot_results` function with the `samples` data, which generates a visual representation of the logical error rates using Matplotlib, saves it as an image, and displays the plot window. ```Python plot_results(samples) ``` -------------------------------- ### Python UnionFindDecoder Class API Documentation Directive Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/ldpc/union_find_decoder.rst This snippet illustrates the Sphinx reStructuredText directive used to automatically generate comprehensive API documentation for the 'UnionFindDecoder' class. It instructs Sphinx to include all members, inherited members, and even undocumented members, along with displaying the class's inheritance hierarchy. ```APIDOC .. autoclass:: ldpc.union_find_decoder.UnionFindDecoder :members: UnionFindDecoder :inherited-members: :undoc-members: :show-inheritance: :noindex: ``` -------------------------------- ### Display Parity Check Matrix as NumPy Array Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Shows how to convert the sparse parity check matrix `H` into a dense NumPy array for a more readable representation using the `toarray()` method. ```python print(H.toarray()) ``` -------------------------------- ### Estimate Code Distance (d) using ldpc.code_util Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Shows how to estimate the code distance `d` using `ldpc.code_util.estimate_code_distance`. This function samples codewords to find low weights and allows setting a `timeout_seconds` parameter for the estimation process. ```python d, number_code_words_sampled, lowest_weight_codewords = ( ldpc.code_util.estimate_code_distance(H, timeout_seconds=0.1) ) print( f"Code distance estimate, d <= {d} (no. codewords sampled: {number_code_words_sampled})" ) ``` -------------------------------- ### Encode Binary Message using Generator Matrix Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Shows how to encode a `k`-bit binary message `b` into an `n`-bit codeword `c` by multiplying it with the transpose of the generator matrix `G` (modulo 2). ```python b = np.array([1, 0, 1, 1]) c = G.T @ b % 2 c ``` -------------------------------- ### Calculate Code Dimension (k) using ldpc.code_util Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Demonstrates how to compute the code dimension (number of logical bits) `k` from the parity check matrix `H` using the `ldpc.code_util.compute_code_dimension` function. ```python k = ldpc.code_util.compute_code_dimension(H) print(f"Number of logical bits, k = {k}") ``` -------------------------------- ### Verify H * G^T = 0 Condition for Generator Matrix Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Verifies the fundamental condition `H * G^T = 0` for the constructed generator matrix `G` and parity check matrix `H`. The result is modulo 2 to confirm the binary linear code property. ```python temp = H @ G.T temp.data = temp.data % 2 temp.toarray() ``` -------------------------------- ### Verify Encoded Codeword with Parity Check Matrix Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Confirms that an encoded codeword `c` is valid by multiplying it with the parity check matrix `H`. A valid codeword should result in a zero vector (modulo 2). ```python H @ c % 2 ``` -------------------------------- ### Calculate Number of Physical Bits (n) from Parity Check Matrix Source: https://github.com/quantumgizmos/ldpc/blob/main/docs/source/classical_coding.ipynb Explains how to determine the number of physical bits `n` for a code by accessing the number of columns in its parity check matrix `H` using `H.shape[1]`. ```python n = H.shape[1] print(f"Number of physical bits, n = {n}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.