Tasks¶
- class lightworks.Analyzer(circuit: PhotonicCircuit, inputs: State | list[State], expected: dict[State, State | list[State]] | None = None, post_selection: PostSelectionType | Callable[[State], bool] | None = None)¶
Bases:
Task
The analyzer class is built as an alternative to simulation, intended for cases where we want to look at the transformations between a specific subset of states. It is useful for the simulation of probabilities in cases where loss and circuit errors are likely to be a factor. As part of the process a performance and error rate metric are calculated.
- Parameters:
circuit (PhotonicCircuit) – The circuit to simulate.
inputs (list) – A list of the input states to simulate. For multiple inputs this should be a list of States.
expected (dict) – A dictionary containing a mapping between the input state and expected output state(s). If there is multiple possible outputs, this can be specified as a list.
Attribute:
- performanceThe total probabilities of mapping between the states
provided compared with all possible states.
- error_rateGiven an expected mapping, the analyzer will determine the
extent to which this is achieved.
- property circuit: PhotonicCircuit¶
Stores the circuit to be used for simulation, should be a PhotonicCircuit object.
- property expected: dict[State, State | list[State]] | None¶
A dictionary of the expected mapping between inputs and outputs of the system.
- property post_selection: PostSelectionType | None¶
Stores post-selection criteria for analysis.
- class lightworks.Batch(task: type[Task] | None = None, task_args: list[list[Any]] | None = None, task_kwargs: dict[str, list[Any]] | None = None, parameters: dict[Parameter[Any], list[Any]] | None = None)¶
Bases:
object
Allows for batch submission of jobs with varied parameters on each run.
- add(task: Task) None ¶
Allows for tasks to be manually added to the BatchTask.
- property num: int¶
Returns number of tasks in batch.
- property tasks: list[Task]¶
Returns all tasks contained in batch.
- 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: Literal['input', 'output'] = 'output')¶
Bases:
Task
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: Literal['input', 'output']¶
Stores the input mode of the sampler, which controls whether N valid inputs or outputs are produced from the system.
- class lightworks.Simulator(circuit: PhotonicCircuit, inputs: State | list[State], outputs: State | list[State] | None = None)¶
Bases:
Task
Simulates a circuit for a provided number of inputs and outputs, returning the probability amplitude between them.
- Parameters:
circuit (PhotonicCircuit) – The circuit which is to be used for simulation.
inputs (list) – A list of the input states to simulate. For multiple inputs this should be a list of States.
outputs (list | None, optional) – A list of the output states to simulate, this can also be set to None to automatically find all possible outputs.
- property circuit: PhotonicCircuit¶
Stores the circuit to be used for simulation, should be a PhotonicCircuit object.