Tutorial 6 — QKD Key Exchange (BB84)
Objective: Run the run_qkd() protocol between two nodes and inspect the BB84 security metrics: QBER, secret key length, and efficiency rate.
Quantum Key Distribution (QKD) uses entanglement distribution as its physical layer to establish a shared secret key. The BB84 protocol is the most widely deployed QKD scheme. qnet-core simulates this protocol end-to-end using the underlying entanglement engine.
Define the Network
from qnet_core import QNetEngine, NodeDefinition, LinkDefinition, QKDParameters
engine = QNetEngine()
nodes = [
NodeDefinition(id="Alice", memory_lifetime_t2=1.0),
NodeDefinition(id="Bob", memory_lifetime_t2=1.0),
]
links = [
LinkDefinition("Alice", "Bob", distance_km=10.0, base_fidelity=0.95,
generation_rate_hz=1_000.0),
]
engine.define_network(nodes, links)
Configure QKD Protocol Parameters
qkd_params = QKDParameters(
from_node="Alice",
to_node="Bob",
fidelity_target=0.90, # minimum entanglement fidelity
max_latency_ms=10_000.0, # protocol timeout
rounds=200, # number of BB84 signal rounds
error_rate_tolerance=0.11, # BB84 threshold — abort if QBER > this
sifting_overhead_ratio=0.5, # fraction lost during basis reconciliation
privacy_amplification_factor=0.8, # compression for security proof
)
Execute the Protocol
result = engine.run_qkd(qkd_params)
print("=== BB84 QKD Key Exchange ===")
print(f"Success: {result.success}")
print(f"Secret key length: {result.secret_key_length_bits} bits")
print(f"Efficiency rate: {result.efficiency_rate:.4f}")
print(f"QBER: {result.qber:.4f}")
print(f"Latency: {result.latency_ms:.1f} ms")
print(f"Path: {' → '.join(result.execution_path)}")
print(f"Rounds completed: {result.rounds_completed} / {qkd_params.rounds}")
print(f"Rounds failed: {result.rounds_failed}")
Result Fields
| Field | Type | Description |
|---|---|---|
success | bool | Whether a secure key was established |
secret_key_length_bits | int | Length of the final secret key in bits |
efficiency_rate | float | Key generation efficiency [0, 1] — ratio of output bits to input rounds |
qber | float | Quantum Bit Error Rate — if QBER > error_rate_tolerance, the protocol aborts |
latency_ms | float | Total protocol latency (entanglement + classical post-processing) |
execution_path | List[str] | Node IDs traversed during entanglement distribution |
rounds_completed | int | Number of successful round-end measurements |
rounds_failed | int | Number of rounds that failed (link generation failure or decoherence) |
QKD Protocol Flow
- Entanglement distribution — engine establishes entangled pairs between Alice and Bob
- Basis sifting — each party randomly measures in one of two bases;
sifting_overhead_ratiocontrols wasted rounds - QBER estimation — compare a subset of results; if error rate exceeds tolerance, abort
- Privacy amplification — compress the sifted key to eliminate eavesdropper information
QKDStats (Planned)
The QKDStats Monte Carlo ensemble type is planned but not yet implemented. run_qkd() currently returns a single QKDResult. To estimate statistics, call simulate() on the engine and check each result's success field.
What's next
- State Teleportation — another higher-level protocol
- Monte Carlo Ensemble — statistical analysis techniques