NoisySamplingSimulator

The NoisySamplingSimulator is a special simulator dedicated to sample states from a noisy input state.

It is completely separated from the other simulators, and, as such, it is not available through the SimulatorFactory. As its name suggests, it requires a sampling able backend such as CliffordClifford2017.

The NoisySamplingSimulator exposes two simulation methods:

  • samples that returns a python dictionary with a BSSamples in the “results” field

  • sample_count that returns a python dictionary with a BSCount in the “results” field

Note that these two methods require a SVDistribution without superposed states (but can be annotated), since we can’t retrieve the probability amplitudes from the backend.

Also, this simulator can only simulate non-polarized unitary circuits.

Using a NoisySamplingSimulator

import perceval as pcvl

sim = pcvl.NoisySamplingSimulator(pcvl.Clifford2017Backend())
sim.set_circuit(pcvl.BS())  # Now, sim holds a 2 modes circuit

# Physical and logical selection
sim.set_selection(min_detected_photons_filter = 2)  # Other fields: heralds (accounting only the output), postselect
sim.set_detectors([pcvl.Detector.threshold(), pcvl.Detector.pnr()])

svd = pcvl.SVDistribution({pcvl.BasicState("|{_:0}, {_:1}>"): 1})
# Sample stream
print(sim.samples(svd, 5)["results"])  # Random sampling; results may change at each run
# [ |1,1>, |0,2>, |0,2>, |1,1>, |1,1> ]

# Sample count
print(sim.sample_count(svd, max_samples = 10, max_shots = 10)["results"])
# {
#   |1,1>: 7
#   |0,2>: 2
# }
class perceval.simulators.NoisySamplingSimulator(sampling_backend)

Simulates a sampling, using a perfect sampling algorithm. It is used to take advantage of a parallel sampling algorithm, by computing multiple output states at once, while taking noise and post-processing (heralds, post-selection, detector characteristics) into account

Parameters:

sampling_backend (ASamplingBackend) – Instance of a sampling-capable back-end

compute_physical_logical_perf(value)

Tells the simulator to compute or not the physical and logical performances when possible

Parameters:

value (bool) – True to compute the physical and logical performances, False otherwise.

format_results(results, physical_perf, logical_perf)

Format the simulation results by computing the global performance, and returning the physical and logical performances only if needed.

Parameters:
  • results – the simulation results

  • physical_perf – the physical performance

  • logical_perf – the logical performance

keep_heralds(value)

Tells the simulator to keep or discard ancillary modes in output states

Parameters:

value (bool) – True to keep ancillaries/heralded modes, False to discard them (default is keep).

log_resources(method, extra_parameters)

Log resources of the noisy sampling simulator

Parameters:
  • method (str) – name of the method used

  • extra_parameters (dict) –

    extra parameters to log

    Extra parameter can be:

    • max_samples

    • max_shots

sample_count(svd, max_samples, max_shots=None, progress_callback=None)

Run a noisy sampling simulation and retrieve the results

Parameters:
  • svd (SVDistribution | tuple[Source, BasicState]) – The noisy input, expressed as a mixed state, or a tuple containing the source and the perfect input state

  • max_samples (int) – Max expected samples of interest in the results

  • max_shots (int) – Shots limit before the sampling ends (you might get fewer samples than expected)

  • progress_callback (callable) – A progress callback

Return type:

dict

Returns:

A dictionary of the form { “results”: BSCount, “physical_perf”: float, “logical_perf”: float }

  • results is the post-selected output state sample count

  • physical_perf is the performance computed from the detected photon filter

  • logical_perf is the performance computed from the post-selection

samples(svd, max_samples, max_shots=None, progress_callback=None)

Run a noisy sampling simulation and retrieve the results

Parameters:
  • svd (SVDistribution | tuple[Source, FockState]) – The noisy input, expressed as a mixed state, or a tuple containing the source and the perfect input state

  • max_samples (int) – Max expected samples of interest in the results

  • max_shots (int) – Shots limit before the sampling ends (you might get fewer samples than expected)

  • progress_callback (callable) – A progress callback

Return type:

dict

Returns:

A dictionary of the form { “results”: BSSamples, “physical_perf”: float, “logical_perf”: float }

  • results is the post-selected output state sample stream

  • physical_perf is the performance computed from the detected photon filter

  • logical_perf is the performance computed from the post-selection

set_circuit(circuit)

Set the circuit to simulate the sampling on

Parameters:

circuit (ACircuit) – A unitary circuit

set_detectors(detector_list)
Parameters:

detector_list (list[IDetector]) – A list of detectors to simulate

set_min_detected_photons_filter(value)

Set the physical detection filter. Any output state with less than this threshold gets discarded.

Parameters:

value (int) – Minimal photon count in output states of interest.

set_selection(min_detected_photons_filter=None, postselect=None, heralds=None)

Set multiple selection filters at once to remove unwanted states from computed output distribution

Parameters:
  • min_detected_photons_filter (Optional[int]) – minimum number of detected photons in the output distribution

  • postselect (Optional[PostSelect]) – a post-selection function

  • heralds (Optional[dict]) – expected detections (heralds). Only corresponding states will be selected, others are filtered out. Mapping of heralds. For instance {5: 0, 6: 1} means 0 photon is expected on mode 5 and 1 on mode 6.