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:
Simulation
This class tracks the evolution of a quantum system with
qubit_count
qubits. The state of system the evolves by application ofGateOperation`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 sizebatch_size
. If the number of operations is not evenly divisible bybatch_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 modulebatch_operation_strategy
.- Parameters:
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[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.
Note
This method mutates the state of the simulation.
- apply_observables(observables: list[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.
- property state_vector: ndarray
The state vector specifying the current state of the simulation.
Note
Mutating this array will mutate the state of the simulation.
- Type:
np.ndarray
- property density_matrix: ndarray
The density matrix specifying the current state of the simulation.
- Type:
np.ndarray
- property state_with_observables: ndarray
The state vector diagonalized in the basis of the measured observables.
- Raises:
RuntimeError – If observables have not been applied
- Type:
np.ndarray
- expectation(observable: 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.
- property probabilities: ndarray
The probabilities of each computational basis state of the current state vector of the simulation.
- Type:
np.ndarray