Skip to content

Commit

Permalink
Encoding and Codec creation directly from qc-exponents (#19)
Browse files Browse the repository at this point in the history
Breaking changes:

- removes RateAdaptiveCode template parameter Bit. This is now a template parameter of underlying functions, which is more flexible (and hopefully not too much more complicated/prone to errors...)
- (ABI-breaking) reworks underlying data representation for RateAdaptiveCode.

Non-breaking changes:
- New header encoder_advanced.hpp. Enables constexpr storage of QC-exponents for a code in a grouped manner. For how to use, see unit test in test_encoder_advanced.cpp. Requires C++20!
- Enable construction of RateAdaptiveCode from a vector<vector<idx_t>> mother_pos_varn
- Together, these also enable creating RateAdaptiveCode from QC-exponents stored statically in C++.
  • Loading branch information
adomasbaliuka authored May 2, 2024
1 parent 30f63df commit 8677201
Show file tree
Hide file tree
Showing 16 changed files with 1,019 additions and 214 deletions.
17 changes: 9 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ if (LDPC4QKD_HEADER_ONLY)

add_library(LDPC4QKD INTERFACE
src/rate_adaptive_code.hpp # contains decoder and encoder. Does not need any other files to work.

# TODO add `encoder_advanced` and require C++20
# encoder_advanced.hpp # REQUIRES C++20!!! advanced encoder (QC-enabled and constexpr objects). Handles storage.
src/encoder.hpp # contains only minimal encoder that needs static storage of the LDPC matrix
src/read_ldpc_file_formats.hpp # helper methods to generate static storage (not needed to use encoder/decoder class).
src/read_ldpc_file_formats.hpp # helper methods (not needed to use `rate_adaptive_code.hpp`).
)

target_compile_features(LDPC4QKD INTERFACE cxx_std_17)
Expand Down Expand Up @@ -95,9 +96,9 @@ else (LDPC4QKD_HEADER_ONLY)
include(CompilerWarnings)
set_project_warnings(compiler_warnings)

# ----------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------- MISCELLANEOUS ---------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------- MISCELLANEOUS -----------------------------------------------
# ------------------------------------------------------------------------------------------------------------------

# This will allow us to print a feature summary.
# https://cmake.org/cmake/help/v3.11/module/FeatureSummary.html
Expand Down Expand Up @@ -130,9 +131,9 @@ else (LDPC4QKD_HEADER_ONLY)
message(WARNING "Using ccache to speed up the build is not possible.")
endif (CCACHE_FOUND)

# ----------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------- INCLUDE SUBDIRECTORIES -----------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------- INCLUDE SUBDIRECTORIES -------------------------------------------
# ------------------------------------------------------------------------------------------------------------------

add_subdirectory(src)

Expand Down
14 changes: 7 additions & 7 deletions benchmarks_error_rate/code_simulation_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ namespace LDPC4QKD::CodeSimulationHelpers {
template<typename Bit=bool,
typename colptr_t=std::uint32_t,
typename idx_t=std::uint32_t>
LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t> load_ldpc_from_cscmat(
LDPC4QKD::RateAdaptiveCode<colptr_t, idx_t> load_ldpc_from_cscmat(
const std::string &cscmat_file_path, const std::string &rate_adaption_file_path=""
) {
auto pair = LDPC4QKD::read_matrix_from_cscmat<colptr_t, idx_t>(cscmat_file_path);
auto colptr = pair.first;
auto row_idx = pair.second;

if(rate_adaption_file_path.empty()) {
return LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t>(colptr, row_idx);
return LDPC4QKD::RateAdaptiveCode<colptr_t, idx_t>(colptr, row_idx);
} else {
std::vector<idx_t> rows_to_combine = read_rate_adaption_from_csv<idx_t>(rate_adaption_file_path);
return LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t>(colptr, row_idx, rows_to_combine);
return LDPC4QKD::RateAdaptiveCode<colptr_t, idx_t>(colptr, row_idx, rows_to_combine);
}
}

Expand All @@ -94,7 +94,7 @@ namespace LDPC4QKD::CodeSimulationHelpers {
template<typename Bit=bool,
typename colptr_t=std::uint32_t,
typename idx_t=std::uint32_t>
LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t> load_ldpc_from_json(
LDPC4QKD::RateAdaptiveCode<colptr_t, idx_t> load_ldpc_from_json(
const std::string &json_file_path, const std::string &rate_adaption_file_path = ""
) {
try {
Expand All @@ -113,10 +113,10 @@ namespace LDPC4QKD::CodeSimulationHelpers {
std::vector<idx_t> rowval = data["rowval"];

if (rate_adaption_file_path.empty()) {
return LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t>(colptr, rowval);
return LDPC4QKD::RateAdaptiveCode<colptr_t, idx_t>(colptr, rowval);
} else {
std::vector<idx_t> rows_to_combine = read_rate_adaption_from_csv<idx_t>(rate_adaption_file_path);
return LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t>(colptr, rowval, rows_to_combine);
return LDPC4QKD::RateAdaptiveCode<colptr_t, idx_t>(colptr, rowval, rows_to_combine);
}
} else if (data["format"] == "COMPRESSED_SPARSE_COLUMN") { // quasi-cyclic exponents stored
// std::vector<std::uint64_t> colptr = data["colptr"];
Expand Down Expand Up @@ -155,7 +155,7 @@ namespace LDPC4QKD::CodeSimulationHelpers {
template<typename Bit=bool,
typename colptr_t=std::uint32_t,
typename idx_t=std::uint32_t>
LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t> load_ldpc(
LDPC4QKD::RateAdaptiveCode<colptr_t, idx_t> load_ldpc(
const std::string &file_path, const std::string &rate_adaption_file_path=""
) {
std::filesystem::path filePath = file_path;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks_error_rate/main_rate_adapted_fer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace LDPC4QKD::CodeSimulationHelpers;
template<typename colptr_t=std::uint32_t, // integer type that fits ("number of non-zero matrix entries" + 1)
typename idx_t=std::uint16_t>
std::pair<size_t, size_t> run_simulation(
const LDPC4QKD::RateAdaptiveCode<bool, colptr_t, idx_t> &H,
const LDPC4QKD::RateAdaptiveCode<colptr_t, idx_t> &H,
double p,
std::size_t num_frames_to_test,
std::mt19937_64 &rng,
Expand Down
4 changes: 2 additions & 2 deletions benchmarks_runtime/main_benchmark_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ void noise_bitstring_inplace(std::vector<T> &src, double err_prob, unsigned int
}


LDPC4QKD::RateAdaptiveCode<bool> get_code_big_nora() {
LDPC4QKD::RateAdaptiveCode get_code_big_nora() {
std::vector<std::uint32_t> colptr(AutogenLDPC::colptr.begin(), AutogenLDPC::colptr.end());
std::vector<std::uint16_t> row_idx(AutogenLDPC::row_idx.begin(), AutogenLDPC::row_idx.end());
return LDPC4QKD::RateAdaptiveCode<bool>(colptr, row_idx);
return LDPC4QKD::RateAdaptiveCode(colptr, row_idx);
}


Expand Down
4 changes: 2 additions & 2 deletions benchmarks_runtime/main_benchmark_ra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
#include "autogen_rate_adaption.hpp"


LDPC4QKD::RateAdaptiveCode<bool> get_code_big_wra() {
LDPC4QKD::RateAdaptiveCode get_code_big_wra() {
std::vector<std::uint32_t> colptr(AutogenLDPC::colptr.begin(), AutogenLDPC::colptr.end());
std::vector<std::uint16_t> row_idx(AutogenLDPC::row_idx.begin(), AutogenLDPC::row_idx.end());
std::vector<std::uint16_t> rows_to_combine(AutogenRateAdapt::rows.begin(), AutogenRateAdapt::rows.end());
return LDPC4QKD::RateAdaptiveCode<bool>(colptr, row_idx, rows_to_combine);
return LDPC4QKD::RateAdaptiveCode(colptr, row_idx, rows_to_combine);
}


Expand Down
6 changes: 3 additions & 3 deletions examples/main_demo_error_correction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


/// Get a LDPC matrix
LDPC4QKD::RateAdaptiveCode<bool> get_code_small() {
auto get_code_small() {
/// We use this matrix as an example:
/// H = [1 0 1 0 1 0 1
/// 0 1 1 0 0 1 1
Expand All @@ -19,7 +19,7 @@ LDPC4QKD::RateAdaptiveCode<bool> get_code_small() {
/// To use it, we must convert H to compressed sparse column (CSC) storage:
std::vector<std::uint32_t> colptr{0, 1, 2, 4, 5, 7, 9, 12};
std::vector<std::uint16_t> row_idx{0, 1, 0, 1, 2, 0, 2, 1, 2, 0, 1, 2};
return LDPC4QKD::RateAdaptiveCode<bool>(colptr, row_idx);
return LDPC4QKD::RateAdaptiveCode(colptr, row_idx);
}


Expand All @@ -44,7 +44,7 @@ int main() {
llrs[i] = vlog * (1 - 2 * x_noised[i]); // log likelihood ratios
}
// alternatively, use the built-in convenience method that does the same:
// std::vector<double> llrs = LDPC4QKD::RateAdaptiveCode<bool>::llrs_bsc(x, p);
// std::vector<double> llrs = LDPC4QKD::RateAdaptiveCode::llrs_bsc(x, p);

std::vector<bool> solution;
bool decoder_converged = H.decode_at_current_rate(llrs, syndrome, solution);
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ add_library(LDPC4QKD INTERFACE
rate_adaptive_code.hpp # contains decoder and encoder. Does not need any other files to work.

encoder.hpp # contains only minimal encoder that needs static storage of the LDPC matrix
encoder_advanced.hpp # REQUIRES C++20!!! advanced encoder (QC-enabled and constexpr objects). Handles storage.
autogen_ldpc_matrix_csc.hpp # static storage of the LDPC matrix. Automatically generated by Julia script.
autogen_rate_adaption.hpp # static storage of the rate adaption specification. Automatically generated by Julia script.
read_ldpc_file_formats.hpp # helper methods to generate static storage (not needed to use encoder/decoder class).
)

target_compile_features(LDPC4QKD INTERFACE cxx_std_17)
target_compile_features(LDPC4QKD INTERFACE cxx_std_20)

target_include_directories(LDPC4QKD
INTERFACE
Expand Down
Loading

0 comments on commit 8677201

Please sign in to comment.