braket.default_simulator.result_types module¶
-
braket.default_simulator.result_types.
from_braket_result_type
(result_type) → braket.default_simulator.result_types.ResultType[source]¶ Creates a
ResultType
corresponding to the given Braket instruction.Parameters: result_type – Result type for a circuit specified using the braket.ir.jacqd
format.Returns: ResultType – Instance of specific ResultType
corresponding to the type of result_typeRaises: NotImplementedError
– If no concreteResultType
class has been registered for the Braket instruction type
-
class
braket.default_simulator.result_types.
ResultType
[source]¶ Bases:
abc.ABC
An 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.-
calculate
(simulation: braket.default_simulator.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: Optional[List[int]] = None)[source]¶ Bases:
braket.default_simulator.result_types.ResultType
,abc.ABC
Holds 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. -
targets
¶ The target qubits of the result type, if any.
Type: Tuple[int], optional
-
-
class
braket.default_simulator.result_types.
ObservableResultType
(observable: braket.default_simulator.operation.Observable)[source]¶ Bases:
braket.default_simulator.result_types.TargetedResultType
,abc.ABC
Holds an observable to perform a calculation in conjunction with a state.
Parameters: observable (Observable) – The observable for which the desired result is calculated -
observable
¶ The observable for which the desired result is calculated.
Type: Observable
-
targets
¶ The target qubits of the result type, if any.
Type: Tuple[int], optional
-
calculate
(simulation: braket.default_simulator.simulation.Simulation) → Union[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: Union[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:
braket.default_simulator.result_types.ResultType
Simply returns the given state vector.
-
calculate
(simulation: braket.default_simulator.state_vector_simulation.StateVectorSimulation) → numpy.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: Optional[List[int]] = None)[source]¶ Bases:
braket.default_simulator.result_types.TargetedResultType
Simply returns the given density matrix.
Parameters: targets (Optional[List[int]]) – 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: braket.default_simulator.simulation.Simulation) → numpy.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:
braket.default_simulator.result_types.ResultType
Extracts the amplitudes of the desired computational basis states.
Parameters: states (List[str]) – The computational basis states whose amplitudes are desired -
calculate
(simulation: braket.default_simulator.state_vector_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: Optional[List[int]] = None)[source]¶ Bases:
braket.default_simulator.result_types.TargetedResultType
Computes the marginal probabilities of computational basis states on the desired qubits.
Parameters: targets (Optional[List[int]]) – 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: braket.default_simulator.simulation.Simulation) → numpy.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: braket.default_simulator.operation.Observable)[source]¶ Bases:
braket.default_simulator.result_types.ObservableResultType
Holds 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: braket.default_simulator.operation.Observable)[source]¶ Bases:
braket.default_simulator.result_types.ObservableResultType
Holds an observable \(O\) to calculate its variance.
Parameters: observable (Observable) – The observable for which the desired result is calculated