SimulatorFactory
This class exposes a single build
static method that can be used to create a simulator suited to your circuit.
In particular, it allows you to simulate circuits with non-unitary components or polarized components.
>>> import perceval as pcvl
>>> p = pcvl.Processor("SLOS", 2)
>>> p.add(0, pcvl.BS())
>>> p.add(0, pcvl.TD(1)) # Add a non-unitary component
>>> p.add(0, pcvl.BS())
>>> sim = pcvl.SimulatorFactory.build(p) # SLOS is transmitted from p to sim
>>> sim.probs(pcvl.BasicState([1, 1]))
{
|1,0>: 0.25
|0,0>: 0.24999999999999994
|0,1>: 0.25
|0,2>: 0.12500000000000006
|2,0>: 0.12500000000000006
}
The type of the simulator will depend on your components. However, it is guaranteed that the resulting simulator will have at least these methods:
set_selection
for heralds, postselect, and min_detected_photons_filter (already done if the circuit is aProcessor
).probs
to compute the output probabilities for one input state.probs_svd
to compute the output probabilities for aSVDistribution
, with possible support for detectors
The simulator factory aims at creating simulators for strong simulation, so it requires the backend to be capable of computing probability amplitudes.
- class perceval.simulators.simulator_factory.SimulatorFactory
Using the SimulatorFactory is an easy and integrated way of instantiating the correct layers of simulation for a given circuit. The factory will adapt to the component needs, in terms of simulation, and chain the correct simulator calls.
- static build(circuit, backend=None, **kwargs)
- Parameters:
circuit (ACircuit | Processor | list) – The optical circuit to build the simulation layers around. The circuit can be a unitary circuit (Circuit object), a list containing positioned unitary components + LC + TD, or a Processor object.
backend (ABackend | str) – (Optional) Any probampli capable backend instance or name. If no backend is passed, then the processor backend name is used if the first parameter’s type is Processor. Ultimately, the fallback is a SLOS backend instantiated without any configuration (i.e. no mask)
kwargs – If backend is a string, the kwargs are transmitted to the instantiation of the backend.
- Return type:
ISimulator
- Returns:
A simulator object with the input circuit set
Simulator specificities
Depending on the components you have, there may be some specificities to the resulting simulator:
Polarization
If you have polarization components, then you will still be able to use evolve
.
The input state will also be expected to be a polarized BasicState
,
or, in the case of probs_svd
, a SVDistribution
with a single polarized non-superposed StateVector
.
If the input is not polarized, the simulator will assume all photons have horizontal polarization.
However, in any method, detectors won’t be simulated if given.
Time Delay and Loss
If you have TD
components or LC
components, the number of photons will not be conserved.
You can still use evolve
, but you could expect strange results (do it at your own risks).
Feed-forward
If you have FFConfigurator
or FFCircuitProvider
in your circuit, you won’t be able to call evolve
.
Also, the dictionary returned by the call to probs_svd
will only have one performance field, named global_perf
.