Sampler¶
- class lightworks.Sampler(circuit: PhotonicCircuit, input_state: State, n_samples: int, post_selection: PostSelectionType | Callable[[State], bool] | None = None, min_detection: int | None = None, source: Source | None = None, detector: Detector | None = None, random_seed: int | None = None, sampling_mode: str = 'output')¶
Used to randomly sample from the photon number distribution output of a provided circuit. The distribution is calculated when the class is first called and then used to return output states with the sample function. Also supports the inclusion of imperfect source and detection properties.
- Parameters:
circuit (PhotonicCircuit) – The circuit to sample output states from.
input_state (State) – The input state to use with the circuit for sampling.
n_samples (int) – The number of samples that are to be returned.
source (Source, optional) – Provide a source object to simulate an imperfect input. This defaults to None, which will create a perfect source.
detector (Detector, optional) – Provide detector to simulate imperfect detector probabilities. This defaults to None, which will assume a perfect detector.
post_selection (PostSelection | function, optional) – A PostSelection object or function which applies a provided set of post-selection criteria to a state.
min_detection (int | None, optional) – Post-select on a given minimum total number of photons, this should not include any heralded photons. If set to None then this will be the smallest valuable possible on a platform.
random_seed (int|None, optional) – Option to provide a random seed to reproducibly generate samples from the function. This is optional and can remain as None if this is not required.
sampling_mode (str, optional) – Sets the mode of the Sampler. In input mode, N cycles of the system are measured, and only results which meet any assigned criteria are returned. In output mode, N valid samples are produced from the system. Should be either ‘input’ or ‘output’, defaults to ‘output’.
- property circuit: PhotonicCircuit¶
Stores the circuit to be used for simulation, should be a PhotonicCircuit object.
- property detector: Detector | None¶
Details the properties of the Detector used for photon measurement.
- property min_detection: int | None¶
Stores the minimum number of photons to be measured in an experiment, this excludes heralded photons.
- property n_samples: int¶
Stores the number of samples to be collected in an experiment.
- property post_selection: PostSelectionType | None¶
Describes the post-selection criteria to be applied to a state.
- property probability_distribution: ProbabilityDistribution¶
Returns the calculated probability distribution. This can only be called once the Sampler has been run on the backend. Note: If any changes are made to the Sampler configuration, it should be re-evaluated with the backend to update this distribution.
- property random_seed: int | None¶
Stores a random seed which is used for gathering repeatable data from the Sampler
- property sampling_mode: str¶
Stores the input mode of the sampler, which controls whether N valid inputs or outputs are produced from the system.