braket.devices.local_simulator module

class braket.devices.local_simulator.LocalSimulator(backend: str | BraketSimulator = 'default', noise_model: NoiseModel | None = None)[source]

Bases: Device

A simulator meant to run directly on the user’s machine.

This class wraps a BraketSimulator object so that it can be run and returns results using constructs from the SDK rather than Braket IR.

Initializes a LocalSimulator.

Parameters:
  • backend (Union[str, BraketSimulator]) – The name of the simulator backend or the actual simulator instance to use for simulation. Defaults to the default simulator backend name.

  • noise_model (Optional[NoiseModel]) – The Braket noise model to apply to the circuit before execution. Noise model can only be added to the devices that support noise simulation.

run(task_specification: Circuit | Problem | Program | AnalogHamiltonianSimulation, shots: int = 0, inputs: dict[str, float] | None = None, *args: Any, **kwargs: Any) LocalQuantumTask[source]

Runs the given task with the wrapped local simulator.

Parameters:
  • task_specification (Union[Circuit, Problem, Program, AnalogHamiltonianSimulation]) – The quantum task specification.

  • shots (int) – The number of times to run the circuit or annealing problem. Default is 0, which means that the simulator will compute the exact results based on the quantum task specification. Sampling is not supported for shots=0.

  • inputs (Optional[dict[str, float]]) – Inputs to be passed along with the IR. If the IR supports inputs, the inputs will be updated with this value. Default: {}.

  • *args (Any) – Arbitrary arguments.

  • **kwargs (Any) – Arbitrary keyword arguments.

Returns:

LocalQuantumTask – A LocalQuantumTask object containing the results of the simulation

Note

If running a circuit, the number of qubits will be passed to the backend as the argument after the circuit itself.

Examples

>>> circuit = Circuit().h(0).cnot(0, 1)
>>> device = LocalSimulator("default")
>>> device.run(circuit, shots=1000)
run_batch(task_specifications: Circuit | Problem | Program | AnalogHamiltonianSimulation | list[Circuit | Problem | Program | AnalogHamiltonianSimulation], shots: int | None = 0, max_parallel: int | None = None, inputs: dict[str, float] | list[dict[str, float]] | None = None, *args, **kwargs) LocalQuantumTaskBatch[source]

Executes a batch of quantum tasks in parallel

Parameters:
  • task_specifications (Union[Union[Circuit, Problem, Program, AnalogHamiltonianSimulation], list[Union[Circuit, Problem, Program, AnalogHamiltonianSimulation]]]) – Single instance or list of quantum task specification.

  • shots (Optional[int]) – The number of times to run the quantum task. Default: 0.

  • max_parallel (Optional[int]) – The maximum number of quantum tasks to run in parallel. Default is the number of CPU.

  • inputs (Optional[Union[dict[str, float], list[dict[str, float]]]]) – Inputs to be passed along with the IR. If the IR supports inputs, the inputs will be updated with this value. Default: {}.

Returns:

LocalQuantumTaskBatch – A batch containing all of the quantum tasks run

property properties: DeviceCapabilities

Return the device properties

Please see braket.device_schema in amazon-braket-schemas-python

Type:

DeviceCapabilities

static registered_backends() set[str][source]

Gets the backends that have been registered as entry points

Returns:

set[str] – The names of the available backends that can be passed into LocalSimulator’s constructor