-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: In-repository performance benchmarks (#6)
* Uses our custom LDPC file library. Updates Julia code and dependencies * Adds rate adapted performance simulation to benchmarks * BUGFIX missing reference in saturate. This lead to worse FER due to saturation not doing anything * Assume stored zero-based indices for rate adaption * Enables reading row indices from files for rate adaption * Adds rate adapted FER simulation and dichotomic average rate search. * bugfix: no longer skip first line of rate adaptive data csv file * bugfix console output in main fer simulation * bugfix miscounting frame errors on convergence * Implements a check for variable node elimination on code construction. * sorts variable node arrays after rate adaption * uses stop at n errors parameter in rate adapted fer simulation * Update runtime benchmarks, add rate adaption benchmark * Allows VN clashes during rate adaption. Duplicates removed manually Note: benchmarks show that rate adaption takes less than 1/10 of decoding time. While this change introduces some overhead, it should not be critical and can be adressed later. Relevant places in the code are marked with TODO * Adds csv files specifying rate adaption for each given LDPC matrix * Adds Julia function to convert all QC-cscmat files to cscmat files. Not part of command line interface yet * Updates documentation * Allows disabling console output by setting update console every N frames to zero * main_rate_adapted_simulation uses bisection to find critical rate
- Loading branch information
XQP-Munich
committed
Sep 22, 2021
1 parent
d719cc9
commit eb4fc12
Showing
25 changed files
with
535,353 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Created by alice on 08.09.21. | ||
// | ||
|
||
#ifndef LDPC4QKD_CODE_SIMULATION_HELPERS_HPP | ||
#define LDPC4QKD_CODE_SIMULATION_HELPERS_HPP | ||
|
||
#include "read_scsmat_format.hpp" | ||
|
||
namespace LDPC4QKD::CodeSimulationHelpers { | ||
template<typename T> | ||
void noise_bitstring_inplace(std::mt19937_64 &rng, std::vector<T> &src, double err_prob) { | ||
std::bernoulli_distribution distribution(err_prob); | ||
|
||
for (std::size_t i = 0; i < src.size(); i++) { | ||
if (distribution(rng)) { | ||
src[i] = !src[i]; | ||
} else { | ||
src[i] = src[i]; | ||
} | ||
} | ||
} | ||
|
||
|
||
// Shannon binary entropy | ||
template<typename T> | ||
double h2(T p) { | ||
return -p * ::log2(p) - (1 - p) * ::log2(1 - p); | ||
} | ||
|
||
template<typename T> | ||
double avg(const std::vector<T> &in) { | ||
double tmp{}; | ||
for (auto i : in) { | ||
tmp += static_cast<double>(i); | ||
} | ||
return tmp / in.size(); | ||
} | ||
|
||
|
||
/// WARNING: if the templated types are too small, the numbers in the files are static_cast down! | ||
template<typename Bit=bool, // type of matrix entires (only values zero and one are used, default to bool) | ||
typename colptr_t=std::uint32_t, // integer type that fits ("number of non-zero matrix entries" + 1) | ||
typename idx_t=std::uint32_t> | ||
LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t> get_ldpc_code_nora(const std::string &cscmat_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; | ||
|
||
return LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t>(colptr, row_idx); | ||
} | ||
|
||
/// WARNING: if the templated types are too small, the numbers in the files are static_cast down! | ||
template<typename Bit=bool, // type of matrix entires (only values zero and one are used, default to bool) | ||
typename colptr_t=std::uint32_t, // integer type that fits ("number of non-zero matrix entries" + 1) | ||
typename idx_t=std::uint32_t> | ||
LDPC4QKD::RateAdaptiveCode<Bit, colptr_t, idx_t> get_code_big_wra( | ||
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; | ||
|
||
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); | ||
} | ||
} | ||
|
||
#endif //LDPC4QKD_CODE_SIMULATION_HELPERS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Created by alice on 20.09.21. | ||
// | ||
|
||
// Standard library | ||
#include <iostream> | ||
#include <random> | ||
|
||
// Google Benchmark library | ||
#include <benchmark/benchmark.h> | ||
|
||
// Project scope | ||
#include "rate_adaptive_code.hpp" | ||
// Test cases test against constants known to be correct for the LDPC-matrix defined here: | ||
#include "autogen_ldpc_matrix_csc.hpp" | ||
#include "autogen_rate_adaption.hpp" | ||
|
||
|
||
LDPC4QKD::RateAdaptiveCode<bool> 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); | ||
} | ||
|
||
|
||
static void BM_decode_benchmark_set_rate(benchmark::State& state) { | ||
for (auto _ : state) { | ||
state.PauseTiming(); | ||
auto H = get_code_big_wra(); | ||
state.ResumeTiming(); | ||
|
||
benchmark::DoNotOptimize(H.getPosVarn()); | ||
H.set_rate(state.range(0)); | ||
benchmark::ClobberMemory(); | ||
} | ||
} | ||
BENCHMARK(BM_decode_benchmark_set_rate)->Unit(benchmark::kMicrosecond)->Range(0, 1024); | ||
|
||
|
||
// Run the benchmark | ||
BENCHMARK_MAIN(); |
Oops, something went wrong.