braket.default_simulator.state_vector_simulation module

class braket.default_simulator.state_vector_simulation.StateVectorSimulation(qubit_count: int, shots: int, batch_size: int)[source]

Bases: braket.default_simulator.simulation.Simulation

This class tracks the evolution of a quantum system with qubit_count qubits. The state of system the evolves by application of GateOperation`s using the `evolve() method.

How operations are applied is determined by the batch_size argument in __init__.

If batch_size is set to 1, operations are applied one at a time.

If batch_size is greater than 1, the operation list is first partitioned into a sequence of contiguous batches, each of size batch_size. If the number of operations is not evenly divisible by batch_size, then the number of operations in the last batch will just be the remainder. The operations in each batch are then applied (contracted) together. The order of the operations in the batches are the same as the original order of the operations. In most cases, tasks complete faster when run on a larger batch, but require more memory. For more details, see the module batch_operation_strategy.

  • qubit_count (int) – The number of qubits being simulated. All the qubits start in the \(\ket{\mathbf{0}}\) computational basis state.
  • shots (int) – The number of samples to take from the simulation. If set to 0, only results that do not require sampling, such as state vector or expectation, are generated.
  • batch_size (int) – The size of the partitions to contract; if set to 1, the gates are applied one at a time, without any optimization of contraction order. Must be a positive integer.
evolve(operations: List[braket.default_simulator.operation.GateOperation]) → None[source]

Evolves the state of the simulation under the action of the specified gate operations.

Parameters:operations (List[GateOperation]) – Gate operations to apply for evolving the state of the simulation.


This method mutates the state of the simulation.

apply_observables(observables: List[braket.default_simulator.operation.Observable]) → None[source]

Applies the diagonalizing matrices of the given observables to the state of the simulation.

This method can only be called once.

Parameters:observables (List[Observable]) – The observables to apply
Raises:RuntimeError – If this method is called more than once
retrieve_samples() → List[int][source]

Retrieves samples of states from the state of the simulation, based on the probabilities.

Returns:List[int] – List of states sampled according to their probabilities in the state. Each integer represents the decimal encoding of the corresponding computational basis state.

The state vector specifying the current state of the simulation.


Mutating this array will mutate the state of the simulation.


The density matrix specifying the current state of the simulation.


The state vector diagonalized in the basis of the measured observables.

Raises:RuntimeError – If observables have not been applied
expectation(observable: braket.default_simulator.operation.Observable) → float[source]

The expected value of the observable in the given state.

Parameters:observable (Observable) – The observable to measure.
Returns:float – The expected value of the observable.

The probabilities of each computational basis state of the current state vector of the simulation.