braket.default_simulator.result_types module

braket.default_simulator.result_types.from_braket_result_type(result_type) 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_type

Raises:

NotImplementedError – If no concrete ResultType class has been registered for the Braket instruction type

class braket.default_simulator.result_types.ResultType[source]

Bases: 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.

abstract 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, 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.

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, 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

property observable

The observable for which the desired result is calculated.

Type:

Observable

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:

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: ResultType

Simply 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: 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: 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: ResultType

Extracts 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: 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: 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: 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: Observable)[source]

Bases: ObservableResultType

Holds an observable \(O\) to calculate its variance.

Parameters:

observable (Observable) – The observable for which the desired result is calculated