Quickstart
Welcome to the quickstart guide. This example shows how to build a simple quantum optical circuit, run it, and read the results. It uses a laser, a half-wave plate, a linear polarizer, a polarising beam splitter and two detectors.
Note
The example is a complete circuit, but it is not a protocol. It does not implement any particular quantum information task, and it does not have a classical post-processing stage. It is meant to show how to use the library to build and run a circuit, and how to read the results.
In order to run the example, you need to have an account on AnuQarana. You can run the example in AnuQarana IDE or import the JSON into the Circuit Builder.
Download the script and
the JSON that describes the circuit.
1. Imports
from QNS.components import *
from QNS.channels import *
from QNS.StateEvoluation import *
Each subpackage re-exports its public names. If you prefer explicit imports:
from QNS.components import (Timeline, Laser, HalfWavePlate,
LinearPolarizer, PolarisingBeamSplitter,
Detector)
from QNS.channels import QunatumOpticalChannel
from QNS.StateEvoluation import StateManager
2. The clock and the state table
tl = Timeline()
sm = StateManager('StateManager')
Timeline is a discrete-event simulation clock,
exposed as tl.env. StateManager
holds every live quantum state. Both are passed to the components below; use
one of each per experiment.
3. Components
L1 = Laser("L1", tl.env, sm, freq=125e6, wl=1.55e-6,
lwidth=1, mu_photons=0.1)
HWP1 = HalfWavePlate("HWP1", tl.env, sm, angle=45)
LP = LinearPolarizer("LP", tl.env, sm, angle=45)
PBS1 = PolarisingBeamSplitter("PBS1", tl.env, sm)
D1 = Detector("D1", tl.env, sm, dead_time=1e-8, jitter=5.5e-11,
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=5.5e-11,
mean_response_time=1e-9, coupling_eff=1,
dark_count_rate=0, det_eff=1)
Every component takes the same first three arguments: a unique ID string,
tl.env, and sm. After that come the device parameters.
The laser fires every 1/freq seconds and draws the photon number of each
pulse from \(\mathrm{Poisson}(\mu)\) with mu_photons=0.1, so roughly
one pulse in ten carries light and a small fraction of those carry two photons.
Angles are given in degrees and converted to radians internally.
4. Wiring
Components are joined only through channels. Each channel takes
[component, port] for its source and destination:
QF1 = QunatumOpticalChannel('QC1', tl.env, length=1, alpha=0.2, n_core=1.5)
QF1.connect_channel([L1, 0], [HWP1, 0]) # ([Source_object, Source_output_port], [Destination_object, Destination_input_port])
QF2 = QunatumOpticalChannel('QC2', tl.env, length=1, alpha=0.2, n_core=1.5)
QF2.connect_channel([HWP1, 0], [LP, 0]) # ([Source_object, Source_output_port], [Destination_object, Destination_input_port])
QF3 = QunatumOpticalChannel('QC3', tl.env, length=1, alpha=0.2, n_core=1.5)
QF3.connect_channel([LP, 0], [PBS1, 0]) # ([Source_object, Source_output_port], [Destination_object, Destination_input_port])
QF4 = QunatumOpticalChannel('QC4', tl.env, length=1, alpha=0.2, n_core=1.5)
QF4.connect_channel([PBS1, 0], [D1, 0]) # ([Source_object, Source_output_port], [Destination_object, Destination_input_port])
QF5 = QunatumOpticalChannel('QC5', tl.env, length=1, alpha=0.2, n_core=1.5)
QF5.connect_channel([PBS1, 1], [D2, 0]) # ([Source_object, Source_output_port], [Destination_object, Destination_input_port])
length is in metres and alpha in dB/km, so each hop here is a 1 m fibre
with negligible loss and a 5 ns delay (length / (c / n_core)). The PBS has
two output ports, 0 and 1; only one input port is fed, which is the
normal single-input configuration.
Warning
Passing a port number a component does not have raises TypeError
at wiring time - for example [D1, 1] fails, because a detector object has
exactly one input port.
5. Running
all_lasers = [L1]
all_detectors = [D1, D2]
result = tl.run(runtime=0.0001,
laser_list=all_lasers,
detector_list=all_detectors
coincidence_window=None)
print("Total Emited Photons : ", L1.total_photon_emited)
print(result)
Argument |
Meaning |
|---|---|
|
How long to run the clock, in seconds. |
|
A list of all lasers to be used in the simulation. Each laser starts a background process that emits pulses at its own frequency. |
|
A list of all detectors to be used in the simulation. Each detector starts a background process that generates dark counts at its own rate. |
|
If not |
run() starts an emission process for
every laser and a dark-count process for every detector, advances the clock to
runtime seconds, then collects the counts.
Sample Output (numbers vary between runs):
Total Emited Photons : 1179
{'total_counts': 591, 'D1': 291, 'D2': 300,
'coincidences': {('D1', 'D2'): 6}, 'total_coincidences': 6}
6. Reading the result
Key |
Meaning |
|---|---|
|
Counts registered by that detector, one entry per detector passed in. |
|
Sum over all detectors. |
|
|
|
Sum of the pairwise coincidence counts. |
L1.total_photon_emited counts pulses that contained at least one photon
and were handed to the channel - not the total number of photons, and not the
number of laser cycles. With freq=125e6 over 1e-4 s the laser cycles
12 500 times; with mu_photons=0.1 about 1 190 of those cycles are non-empty.
Roughly half the emitted pulses are counted here rather than all of them: the half-wave plate at 45° and the linear polarizer at 45° together discard half the amplitude, and the detector treats that missing norm as “no photon arrived” rather than normalising it away.
The six (D1, D2) coincidences are the multi-photon tail. A single photon
can only ever click one detector, so a coincidence means the pulse carried two
or more photons - exactly what a Poissonian source with \(\mu = 0.1\)
produces at the percent level. See Timeline for the two
coincidence-counting modes.
To try out the circuit, Download the script and run it in AnuQarana IDE or download the JSON and import it into the Circuit Builder. Change the device parameters and re-run to see how the counts change. For example, set the linear polarizer to 0° and the half-wave plate to 22.5° to see the counts on D1 and D2 swap.
Download the script and
the JSON that describes the circuit.
Next steps
Components - every component and its parameters
Channels overview - loss, delay and the channel API
Protocols - the built-in protocols and how to run them
Examples - more complete circuits