braket.default_simulator.result_types module
- braket.default_simulator.result_types.from_braket_result_type(result_type) ResultType[source]
Creates a
ResultTypecorresponding to the given Braket instruction.- Parameters:
result_type – Result type for a circuit specified using the
braket.ir.jacqdformat.- Returns:
ResultType – Instance of specific
ResultTypecorresponding to the type of result_type- Raises:
NotImplementedError – If no concrete
ResultTypeclass has been registered for the Braket instruction type
- class braket.default_simulator.result_types.ResultType[source]
Bases:
ABCAn abstract class that when implemented defines a calculation on a quantum state simulation.
Note
All result types are calculated exactly, instead of approximated from samples. Sampled results are returned from
Simulation.retrieve_samples, which can be processed by, for example, the Amazon Braket SDK.- abstractmethod calculate(simulation: Simulation) Any[source]
Calculate a result from the given quantum state vector simulation.
- Parameters:
simulation (Simulation) – The simulation to use in the calculation.
- Returns:
Any – The result of the calculation.
- class braket.default_simulator.result_types.TargetedResultType(targets: list[int] | None = None)[source]
Bases:
ResultType,ABCHolds an observable that may target qubits.
- Parameters:
targets (list[int], optional) – The target qubits of the result type. If None, no specific qubits are targeted.
- property targets: tuple[int, ...] | None
The target qubits of the result type, if any.
- Type:
tuple[int], optional
- class braket.default_simulator.result_types.ObservableResultType(observable: Observable)[source]
Bases:
TargetedResultType,ABCHolds an observable to perform a calculation in conjunction with a state.
- Parameters:
observable (Observable) – The observable for which the desired result is calculated
- property observable
The observable for which the desired result is calculated.
- Type:
- property targets: tuple[int, ...] | None
The target qubits of the result type, if any.
- Type:
tuple[int], optional
- calculate(simulation: Simulation) float | list[float][source]
Calculates the result type using the underlying observable.
Returns a real number if the observable has defined targets, or a list of real numbers, one for the result type on each target, if the observable has no target.
- Parameters:
simulation (Simulation) – The simulation to use in the calculation.
- Returns:
float | list[float] – The value of the result type; will be a real due to self-adjointness of observable.
- class braket.default_simulator.result_types.StateVector[source]
Bases:
ResultTypeSimply returns the given state vector.
- calculate(simulation: StateVectorSimulation) ndarray[source]
Return the given state vector of the simulation.
- Parameters:
simulation (StateVectorSimulation) – The simulation whose state vector will be returned
- Returns:
np.ndarray – The state vector (before observables) of the simulation
- class braket.default_simulator.result_types.DensityMatrix(targets: list[int] | None = None)[source]
Bases:
TargetedResultTypeSimply returns the given density matrix.
- Parameters:
targets (list[int] | None) – The qubit indices on which the reduced density matrix are desired. If no targets are specified, the full density matrix is calculated. Default:
None
- calculate(simulation: Simulation) ndarray[source]
Return the given density matrix of the simulation.
- Parameters:
simulation (Simulation) – The simulation whose (full or reduced) density matrix will be returned.
- Returns:
np.ndarray – The density matrix (before observables) of the simulation
- class braket.default_simulator.result_types.Amplitude(states: list[str])[source]
Bases:
ResultTypeExtracts the amplitudes of the desired computational basis states.
- Parameters:
states (list[str]) – The computational basis states whose amplitudes are desired
- calculate(simulation: StateVectorSimulation) dict[str, complex][source]
Return the amplitudes of the desired computational basis states in the state of the given simulation.
- Parameters:
simulation (StateVectorSimulation) – The simulation whose state vector amplitudes will be returned
- Returns:
dict[str, complex] – A dict keyed on computational basis states as bitstrings, with corresponding values the amplitudes
- class braket.default_simulator.result_types.Probability(targets: list[int] | None = None)[source]
Bases:
TargetedResultTypeComputes the marginal probabilities of computational basis states on the desired qubits.
- Parameters:
targets (list[int] | None) – The qubit indices on which probabilities are desired. If no targets are specified, the probabilities are calculated on the entire state. Default:
None
- calculate(simulation: Simulation) ndarray[source]
Return the marginal probabilities of computational basis states on the target qubits.
Probabilities are marginalized over all non-target qubits.
- Parameters:
simulation (Simulation) – The simulation from which probabilities are calculated.
- Returns:
np.ndarray – An array of probabilities of length equal to 2^(number of target qubits), indexed by the decimal encoding of the computational basis state on the target qubits
- class braket.default_simulator.result_types.Expectation(observable: Observable)[source]
Bases:
ObservableResultTypeHolds an observable \(O\) to calculate its expected value.
- Parameters:
observable (Observable) – The observable for which the desired result is calculated
- class braket.default_simulator.result_types.Variance(observable: Observable)[source]
Bases:
ObservableResultTypeHolds an observable \(O\) to calculate its variance.
- Parameters:
observable (Observable) – The observable for which the desired result is calculated