Beam splitter

The simplest non-trivial circuit: a weak laser onto a 50:50 non-polarising beam splitter, with a detector on each output.

                     ┌─QC2──▶ D1
L1 ──QC1──▶ BS1 ────┤
                     └─QC3──▶ D2

The script

This is the complete circuit, which you can run in AnuQarana IDE or import into the Circuit Builder.

Python or JSON

from QNS.components import *
from QNS.channels import *
from QNS.StateEvoluation import *

tl = Timeline()
sm = StateManager("SM")

L1  = Laser("L1", tl.env, sm, freq=1e6, wl=1550e-9,
            lwidth=1, mu_photons=0.1)
BS1 = BeamSplitter("BS1", tl.env, sm, effieciency=1, transmittance=50)

D1 = Detector("D1", tl.env, sm, dead_time=1e-8, jitter=55e-12,
              mean_response_time=1e-9, coupling_eff=1,
              dark_count_rate=0, det_eff=1)
D2 = Detector("D2", tl.env, sm, dead_time=1e-8, jitter=55e-12,
              mean_response_time=1e-9, coupling_eff=1,
              dark_count_rate=0, det_eff=1)

QC1 = QunatumOpticalChannel("QC1", tl.env, length=1, alpha=0.2, n_core=1.5)
QC1.connect_channel([L1, 0], [BS1, 0])
QC2 = QunatumOpticalChannel("QC2", tl.env, length=1, alpha=0.2, n_core=1.5)
QC2.connect_channel([BS1, 0], [D1, 0])
QC3 = QunatumOpticalChannel("QC3", tl.env, length=1, alpha=0.2, n_core=1.5)
QC3.connect_channel([BS1, 1], [D2, 0])

result = tl.run(runtime=1e-3, laser_list=[L1], detector_list=[D1, D2])
print("emitted:", L1.total_photon_emited)
print(result)

Sample Output

emitted: 88
{'total_counts': 88, 'D1': 45, 'D2': 43,
 'coincidences': {('D1', 'D2'): 0}, 'total_coincidences': 0}

Reading it

Every pulse is counted. The splitter is lossless and the detectors are ideal, so total_counts equals emitted. Contrast this with Quickstart, where a linear polarizer absorbs half the amplitude and only half the pulses register.

The split is even. 45 versus 43 on a 50:50 splitter, exactly as expected. Change transmittance to bias it - but read the caveat in BeamSplitter first, because the component passes that value into the operation’s reflectivity parameter.

Zero coincidences. This is the important line. A single photon can only ever click one detector; on a genuinely single-photon pulse the splitter produces a superposition across two modes, and when one detector measures, the state collapses so the other cannot fire. That the count is 0 rather than \(\sim 88/4\) is direct evidence that the simulator is doing real state collapse rather than flipping an independent coin at each output.

With only 88 pulses at \(\mu = 0.1\), the expected number of two-photon pulses is about \(88 \cdot \mu/2 \approx 4\), and only some of those split one photon into each arm - so zero is unremarkable here. Raise the statistics (see below) and a small genuine coincidence rate appears, which is exactly the multi-photon vulnerability that decoy-state QKD exists to address.

Turning the knobs

More statistics. runtime=1e-3 at freq=1e6 is only 1000 cycles. Raise freq to 1e8 for about 95 000 pulses - but drop dead_time to 1e-9 and mean_response_time to 0 first, or the 11 ns detector recovery will start eating counts at a 10 ns period.

Multi-photon pulses. Raise mu_photons towards 1 and coincidences climb sharply. The cost climbs too: the symbolic expansion in the backend is polynomial in photon number, so a run at \(\mu = 1\) is far slower than one at \(\mu = 0.1\).

Channel loss. At length=1 metre the fibre is effectively lossless (transmittance 0.99995). Set length=10000 for the same alpha=0.2 dB/km and about 63 % survives - the counts drop accordingly while the D1/D2 balance stays even.

Source statistics. L1.my_dict is a histogram of photons per cycle over every cycle, empty ones included:

total = sum(L1.my_dict.values())
for n in sorted(L1.my_dict):
    print(n, L1.my_dict[n] / total)     # should track Poisson(0.1)

Feeding both inputs

To see two-photon interference you need photons on both splitter inputs at the same simulated instant. Drive both from one source through equal-length arms:

           ┌── QCa ──┐
L1 ── BS0 ─┤         ├─ BS1 ─┬── D1
           └── QCb ──┘       └── D2

Python or JSON

The arms must have identical total delay, since interference requires the timestamps to match exactly after rounding - there is no coherence-time model. Assert it rather than trusting arithmetic:

assert QCa.delay == QCb.delay

Put a PhaseShifter in one arm and sweep it to move the counts between D1 and D2.