Timeline

Timeline is the simulation clock. It starts the source and detector processes, advances time, and gathers the results.

from QNS.components import Timeline

tl = Timeline()
env = tl.env            # pass this to every component and channel

Constructor

Timeline(*args, **kwargs)

All arguments are forwarded straight to simpy.Environment, so Timeline(initial_time=0) works exactly as SimPy documents it.

Attributes:

env

The simpy.Environment. Every component and channel constructor takes this.

result

The dictionary returned by the most recent run(). Empty before the first run.

coincidences

The pairwise coincidence dictionary from the most recent run.

Running a simulation

result = tl.run(runtime, laser_list, detector_list, coincidence_window=None)
runtime (float)

Simulated duration in seconds. The simulation stops here regardless of what is still in flight.

laser_list (list of Laser)

Sources to start. run calls env.process(laser.emit()) on each. A laser not in this list never fires.

detector_list (list of Detector)

Detectors to start and to read counts from. run calls env.process(detector.start()) on each, which arms the dark-count process. A detector left out of this list still registers photon clicks (the channel calls receive regardless) but generates no dark counts and contributes nothing to the result dictionary.

coincidence_window (float or None)

See Coincidence counting below.

Returns a dictionary:

{
    '<detector uID>':     int,    # one entry per detector
    'total_counts':       int,    # sum over detectors
    'coincidences':       {(uID_a, uID_b): int, ...},
    'total_coincidences': int,
}

Warning

run may be called more than once on a Timeline, but the detectors do not reset their counters and the lasers resume from where they stopped. For a fresh experiment, build a fresh Timeline and StateManager.

Coincidence counting

After the run, Timeline correlates the click logs of every pair of detectors (itertools.combinations, so each unordered pair appears once). There are two modes.

Pulse mode - coincidence_window=None (default). Two detectors are coincident if they both fired on the same emitted pulse. This is ground truth: the click log stores the photon_id, so pairing is exact.

pulses_a = {pid for pid, _ in det_a.get_clicks() if pid is not None}
pulses_b = {pid for pid, _ in det_b.get_clicks() if pid is not None}
count = len(pulses_a & pulses_b)

Dark counts carry no photon_id and are skipped, so pulse mode never reports an accidental.

Window mode - coincidence_window=<seconds>. Clicks are paired off if they fall within the window of each other, which is what a real coincidence unit does. Dark counts are included, so accidentals show up here.

result = tl.run(runtime=1e-4, laser_list=[L1],
                detector_list=[D1, D2],
                coincidence_window=1e-9)

The pairing is a greedy two-pointer merge over the sorted click times: each click is consumed at most once, so \(N\) clicks on one detector can never yield more than \(N\) coincidences.

Note

A single photon can only ever click one detector. A coincidence therefore means either that the pulse carried more than one photon - with a Poissonian laser this happens at rate \(\sim \mu^2/2\) - or, in window mode, that a dark count landed nearby. A non-zero coincidence rate on genuinely single-photon pulses indicates a bug in the circuit, not physics.

You can also reach the raw logs yourself:

for photon_id, t in D1.get_clicks():
    ...   # photon_id is None for dark counts