SLAPBackend
The SLAPBackend
(for Simulator of LAttice of Polynomials) is a strong simulation backend that,
like the SLOSBackend
, is able to compute efficiently all the output probabilities at once. It achieves its goal
by computing partial derivatives of a polynomial along a graph. The algorithm is introduced in Goubault de Brugière and Heurtel [29].
The main advantage compared to SLOS is that this graph is not represented in memory, so this backend is more memory efficient, with the downside of being slower when memory is not a limitation (for instance with relatively few photons \(n < 10\)). If only a few output states are needed, other backends like NaiveBackend are more suited.
This backend is available in Processor by using the name "SLAP"
.
>>> import perceval as pcvl
>>> c = pcvl.Unitary(pcvl.Matrix.random_unitary(4))
>>> backend = pcvl.SLAPBackend()
>>> backend.set_circuit(c)
>>> backend.set_input_state(pcvl.BasicState([1, 0, 1, 0]))
>>> print(backend.all_prob()) # Results are random due to random unitary
[0.22615963112684112, 0.059932460984674245, 0.11409780074515555, 0.05869159993147518, 0.06610964358209905, 0.1384083292588432, 0.1266841040718083, 0.08819140959446393, 0.05777776134512867, 0.0639472593595116]
- class perceval.backends._slap.SLAPBackend(mask=None)
- all_prob(input_state=None)
Computes the list of probabilities of all states (respecting the mask if any was set). The order of the states can be retrieved using allstate_iterator()
- clear_mask()
Removes any pre-existing mask
- evolve()
Evolves the input BasicState into a StateVector.
- Return type:
- property name: str
Returns the back-end name as a string
- prob_amplitude(output_state)
Computes the probability amplitude for a given output state. The input state and the circuit must already be set
- Return type:
complex
- prob_distribution()
Computes the probability distribution of all states (respecting the mask if any was set) under the form of a BSDistribution.
- Return type:
- probability(output_state)
Computes the probability for a given output state. The input state and the circuit must already be set
- Return type:
float
- set_circuit(circuit)
Sets the circuit to simulate. This circuit must not contain polarized components (use PolarizationSimulator instead, if required).
- set_input_state(input_state)
Sets an input state for the simulation. This state has to be a Fock state without annotations.
- set_mask(masks, n=None)
Sets new masks, replacing the former ones if they exist. Clear possible cached data that depend on the mask. Masks are useful to limit strong simulation to only a part of the Fock space, ultimately saving memory and computation time.
- Parameters:
masks (str | list[str]) – Can be a mask or a list of masks. Each mask is expressed as a string where each character is a condition on one mode. Digits are fixing the number of photons whereas spaces or “*” are accepting any number of detections. e.g. using “****00” as a mask limits the simulation to output states ending in two empty modes.
n – The number of photons to instantiate the mask with. This corresponds to the total number of photons in your non-separated state.