data: add SC-LDPC results and comprehensive comparison plots

SC-LDPC threshold saturation results:
- SC original staircase: 2.28 photons/slot (vs 4.76 uncoupled)
- SC DE-optimized: 1.03 photons/slot (vs 3.21 uncoupled)
- Shannon limit: 0.47 photons/slot (remaining gap: 3.4 dB)

Add CLI to sc_ldpc.py (threshold, fer-compare, full subcommands).
Add threshold progression, SC threshold bars, and SC FER plots.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
cah
2026-02-24 18:35:50 -07:00
parent 41e2ef72ec
commit b4d5856bf9
6 changed files with 437 additions and 0 deletions

View File

@@ -10,6 +10,8 @@ with coupling width w, creating a convolutional-like structure.
"""
import numpy as np
import argparse
import json
import sys
import os
@@ -615,3 +617,194 @@ def compute_sc_threshold(B, L=50, w=2, lam_b=0.1, z_pop=10000, tol=0.25,
lo = mid
return hi
# =============================================================================
# CLI
# =============================================================================
def run_threshold_comparison(seed=42, z_pop=5000, tol=0.5, L=20):
"""Compare SC-LDPC and uncoupled DE thresholds."""
from ldpc_sim import H_BASE
from density_evolution import (
compute_threshold, build_de_profile, make_profile
)
np.random.seed(seed)
print("=" * 60)
print("SC-LDPC vs Uncoupled Threshold Comparison")
print("=" * 60)
# Uncoupled thresholds
degrees_opt = [7, 4, 4, 4, 4, 3, 3, 3]
profile_opt = build_de_profile(degrees_opt, m_base=7)
profile_orig = make_profile(H_BASE)
print("\nUncoupled thresholds:")
thresh_opt_offset = compute_threshold(
profile_opt, lam_b=0.1, z_pop=z_pop, tol=tol, cn_mode='offset')
thresh_opt_norm = compute_threshold(
profile_opt, lam_b=0.1, z_pop=z_pop, tol=tol,
cn_mode='normalized', alpha=0.875)
thresh_orig = compute_threshold(
profile_orig, lam_b=0.1, z_pop=z_pop, tol=tol, cn_mode='offset')
print(f" Original staircase (offset): {thresh_orig:.2f} photons/slot")
print(f" DE-optimized (offset): {thresh_opt_offset:.2f} photons/slot")
print(f" DE-optimized (normalized 0.875): {thresh_opt_norm:.2f} photons/slot")
# SC-LDPC thresholds
print(f"\nSC-LDPC thresholds (L={L}, w=2, normalized 0.875):")
sc_thresh_orig = compute_sc_threshold(
H_BASE, L=L, w=2, lam_b=0.1, z_pop=z_pop, tol=tol,
cn_mode='normalized', alpha=0.875)
print(f" SC original staircase: {sc_thresh_orig:.2f} photons/slot")
from density_evolution import construct_base_matrix
H_opt, girth = construct_base_matrix(degrees_opt, z=32, n_trials=500)
sc_thresh_opt = compute_sc_threshold(
H_opt, L=L, w=2, lam_b=0.1, z_pop=z_pop, tol=tol,
cn_mode='normalized', alpha=0.875)
print(f" SC DE-optimized: {sc_thresh_opt:.2f} photons/slot")
shannon_limit = 0.47
print(f"\n Shannon limit (rate 1/8): {shannon_limit} photons/slot")
return {
'uncoupled_thresholds': {
'original_offset': float(thresh_orig),
'optimized_offset': float(thresh_opt_offset),
'optimized_normalized': float(thresh_opt_norm),
},
'sc_thresholds': {
'sc_original': float(sc_thresh_orig),
'sc_optimized': float(sc_thresh_opt),
},
'shannon_limit': shannon_limit,
'params': {'L': L, 'w': 2, 'z_pop': z_pop, 'tol': tol},
}
def run_fer_comparison(seed=42, n_frames=50, L=10, z=32):
"""FER comparison: SC-LDPC vs uncoupled at Z=32."""
from ldpc_sim import H_BASE, poisson_channel, quantize_llr
np.random.seed(seed)
print("=" * 60)
print(f"SC-LDPC vs Uncoupled FER Comparison (Z={z}, L={L})")
print("=" * 60)
m_base, n_base = H_BASE.shape
# Build SC chain
H_sc, components, meta = build_sc_chain(
H_BASE, L=L, w=2, z=z, seed=seed)
n_total = H_sc.shape[1]
lam_s_points = [2.0, 3.0, 4.0, 5.0, 7.0, 10.0]
sc_results = {}
print(f"\nSC-LDPC (L={L}, w=2, windowed W=5, normalized alpha=0.875):")
print(f"{'lam_s':>8s} {'FER':>10s} {'BER':>10s}")
print("-" * 30)
for lam_s in lam_s_points:
frame_errors = 0
bit_errors = 0
total_bits = 0
for _ in range(n_frames):
codeword = np.zeros(n_total, dtype=np.int8)
llr_float, _ = poisson_channel(codeword, lam_s, 0.1)
llr_q = quantize_llr(llr_float)
decoded, converged, iters = windowed_decode(
llr_q, H_sc, L=L, w=2, z=z, n_base=n_base, m_base=m_base,
W=5, max_iter=20, cn_mode='normalized', alpha=0.875)
errs = np.sum(decoded != 0)
bit_errors += errs
total_bits += n_total
if errs > 0:
frame_errors += 1
fer = frame_errors / n_frames
ber = bit_errors / total_bits if total_bits > 0 else 0
sc_results[lam_s] = {'fer': float(fer), 'ber': float(ber)}
print(f"{lam_s:8.1f} {fer:10.3f} {ber:10.6f}")
return {
'lam_s_points': lam_s_points,
'sc_fer': {str(k): v for k, v in sc_results.items()},
'params': {'L': L, 'w': 2, 'z': z, 'n_frames': n_frames},
}
def run_full_pipeline(seed=42):
"""Full SC-LDPC pipeline: threshold comparison + FER."""
print("=" * 70)
print("SC-LDPC FULL PIPELINE")
print("=" * 70)
# Step 1: Threshold comparison
print("\n--- Step 1: Threshold Comparison ---")
threshold_results = run_threshold_comparison(
seed=seed, z_pop=5000, tol=0.5, L=20)
# Step 2: FER comparison
print("\n--- Step 2: FER Comparison ---")
fer_results = run_fer_comparison(
seed=seed, n_frames=50, L=10, z=32)
# Combine and save results
output = {
**threshold_results,
'fer_comparison': fer_results,
}
out_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data')
os.makedirs(out_dir, exist_ok=True)
out_path = os.path.join(out_dir, 'sc_ldpc_results.json')
with open(out_path, 'w') as f:
json.dump(output, f, indent=2, default=str)
print(f"\nResults saved to {out_path}")
return output
def main():
parser = argparse.ArgumentParser(
description='SC-LDPC Code Construction and Analysis',
)
subparsers = parser.add_subparsers(dest='command')
p_thresh = subparsers.add_parser('threshold',
help='SC-DE threshold comparison')
p_thresh.add_argument('--seed', type=int, default=42)
p_thresh.add_argument('--z-pop', type=int, default=5000)
p_thresh.add_argument('--tol', type=float, default=0.5)
p_thresh.add_argument('--L', type=int, default=20)
p_fer = subparsers.add_parser('fer-compare',
help='FER: SC vs uncoupled')
p_fer.add_argument('--seed', type=int, default=42)
p_fer.add_argument('--n-frames', type=int, default=50)
p_fer.add_argument('--L', type=int, default=10)
p_full = subparsers.add_parser('full', help='Full pipeline')
p_full.add_argument('--seed', type=int, default=42)
args = parser.parse_args()
if args.command == 'threshold':
run_threshold_comparison(seed=args.seed, z_pop=args.z_pop,
tol=args.tol, L=args.L)
elif args.command == 'fer-compare':
run_fer_comparison(seed=args.seed, n_frames=args.n_frames, L=args.L)
elif args.command == 'full':
run_full_pipeline(seed=args.seed)
else:
parser.print_help()
if __name__ == '__main__':
main()