Skip to content

Commit

Permalink
dynamic scaling factors
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumgizmos committed Nov 26, 2024
1 parent 968fc4d commit 9bdb670
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies = [
"stim",
"sinter"
]
version = "2.1.5"
version = "2.1.6"

[project.urls]
Documentation = "https://software.roffe.eu/ldpc"
Expand Down
20 changes: 15 additions & 5 deletions python_test/test_qcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_400_16_6_hgp():

error_rate = 0.01
run_count = 10000
seed = 42
seed = 100
max_iter = 5
osd_order = 3
print()
Expand Down Expand Up @@ -106,10 +106,20 @@ def test_400_16_6_hgp():

decoder = BpLsdDecoder(hx, error_rate=error_rate, max_iter=max_iter, bp_method="ms", ms_scaling_factor=0.625,
schedule="parallel", lsd_order=osd_order, lsd_method="lsd_cs")
# decoder.set_do_stats(True)
ler, min_logical, speed, _ = quantum_mc_sim(hx, lx, error_rate, run_count, seed, decoder,
f"Min-sum LSD-{osd_order} parallel schedule")
# print(json.dumps(decoder.statistics))

decoder = BpLsdDecoder(hx, error_rate=error_rate, max_iter=max_iter, bp_method="ms", ms_scaling_factor=0,
schedule="parallel", bits_per_step=1, lsd_order=0, lsd_method="osd_e")
ler, min_logical, speed, _ = quantum_mc_sim(hx, lx, error_rate, run_count, seed, decoder,
f"Min-sum LSD-0 parallel schedule, dynamic scaling factor")


decoder = BpLsdDecoder(hx, error_rate=error_rate, max_iter=max_iter, bp_method="ms", ms_scaling_factor=0,
schedule="serial", bits_per_step=1, lsd_order=0, lsd_method="osd_e")
ler, min_logical, speed, _ = quantum_mc_sim(hx, lx, error_rate, run_count, seed, decoder,
f"Min-sum LSD-0 serial schedule, dynamic scaling factor")


def test_toric_20():
hx = scipy.sparse.load_npz("python_test/pcms/hx_toric_20.npz")
Expand Down Expand Up @@ -181,5 +191,5 @@ def test_surface_20():
if __name__ == "__main__":

test_400_16_6_hgp()
test_toric_20()
test_surface_20()
# test_toric_20()
# test_surface_20()
24 changes: 22 additions & 2 deletions src_cpp/bp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ namespace ldpc {
}
}
} else if (this->bp_method == MINIMUM_SUM) {

double alpha;
if(this->ms_scaling_factor == 0.0) {
alpha = 1.0 - std::pow(2.0, -1.0*it);
}
else {
alpha = this->ms_scaling_factor;
}

//check to bit updates
for (int i = 0; i < check_count; i++) {

Expand Down Expand Up @@ -236,8 +245,10 @@ namespace ldpc {
}

int message_sign = (sgn % 2 == 0) ? 1.0 : -1.0;
e.check_to_bit_msg *= message_sign * ms_scaling_factor;

e.check_to_bit_msg *= message_sign * alpha;


double abs_bit_to_check_msg = std::abs(e.bit_to_check_msg);
if (abs_bit_to_check_msg < temp) {
temp = abs_bit_to_check_msg;
Expand Down Expand Up @@ -431,6 +442,15 @@ namespace ldpc {
this->initialise_log_domain_bp();

for (int it = 1; it <= maximum_iterations; it++) {

double alpha;
if(this->ms_scaling_factor == 0.0) {
alpha = 1.0 - std::pow(2.0, -1.0*it);
}
else {
alpha = this->ms_scaling_factor;
}

if (this->random_schedule_seed > -1) {
this->rng_list_shuffle.shuffle(this->serial_schedule_order);
} else if (this->schedule == BpSchedule::SERIAL_RELATIVE) {
Expand Down Expand Up @@ -483,7 +503,7 @@ namespace ldpc {
}
}
double message_sign = (sgn % 2 == 0) ? 1.0 : -1.0;
e.check_to_bit_msg = ms_scaling_factor * message_sign * temp;
e.check_to_bit_msg = alpha * message_sign * temp;
e.bit_to_check_msg = log_prob_ratios[bit_index];
this->log_prob_ratios[bit_index] += e.check_to_bit_msg;
}
Expand Down

0 comments on commit 9bdb670

Please sign in to comment.