braket.default_simulator.density_matrix_simulation module
- class braket.default_simulator.density_matrix_simulation.DensityMatrixSimulation(qubit_count: int, shots: int)[source]
Bases:
Simulation
This class tracks the evolution of the density matrix of a quantum system with
qubit_count
qubits. The state of system evolves by applications ofGateOperation`s and `KrausOperation`s using the `evolve()
method.- Parameters:
qubit_count (int) – The number of qubits being simulated.
shots (int) – The number of samples to take from the simulation. If set to 0, only results that do not require sampling, such as density matrix or expectation, are generated.
- evolve(operations: list[GateOperation | KrausOperation]) 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 density_matrix: ndarray
The density matrix specifying the current state of the simulation.
Note
Mutating this array will mutate the state of the simulation.
- Type:
np.ndarray
- property state_with_observables: ndarray
The density matrix 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 density matrix of the simulation.
- Type:
np.ndarray