braket.circuits.result_types module

class braket.circuits.result_types.StateVector[source]

Bases: ResultType

The full state vector as a requested result type. This is available on simulators only when shots=0.

Initializes a ResultType.

Parameters:

ascii_symbols (list[str]) – ASCII string symbols for the result type. This is used when printing a diagram of circuits.

Raises:

ValueErrorascii_symbols is None

static state_vector() ResultType[source]

Registers this function into the circuit class.

Returns:

ResultType – state vector as a requested result type

Examples

>>> circ = Circuit().state_vector()
class braket.circuits.result_types.DensityMatrix(target: QubitSetInput | None = None)[source]

Bases: ResultType

The full density matrix as a requested result type. This is available on simulators only when shots=0.

Inits a DensityMatrix.

Parameters:

target (QubitSetInput | None) – The target qubits of the reduced density matrix. Default is None, and the full density matrix is returned.

Examples

>>> ResultType.DensityMatrix(target=[0, 1])
property target: QubitSet
static density_matrix(target: QubitSetInput | None = None) ResultType[source]

Registers this function into the circuit class.

Parameters:

target (QubitSetInput | None) – The target qubits of the reduced density matrix. Default is None, and the full density matrix is returned.

Returns:

ResultType – density matrix as a requested result type

Examples

>>> circ = Circuit().density_matrix(target=[0, 1])
class braket.circuits.result_types.AdjointGradient(observable: Observable, target: list[QubitSetInput] | None = None, parameters: list[str | FreeParameter] | None = None)[source]

Bases: ObservableParameterResultType

The gradient of the expectation value of the provided observable, applied to target, with respect to the given parameter.

Inits an AdjointGradient.

Parameters:
  • observable (Observable) – The expectation value of this observable is the function against which parameters in the gradient are differentiated.

  • target (list[QubitSetInput] | None) – Target qubits that the result type is requested for. Each term in the target list should have the same number of qubits as the corresponding term in the observable. Default is None, which means the observable must operate only on 1 qubit and it is applied to all qubits in parallel.

  • parameters (list[Union[str, FreeParameter]] | None) – The free parameters in the circuit to differentiate with respect to. Default: all.

Raises:

ValueError – If the observable’s qubit count does not equal the number of target qubits, or if target=None and the observable’s qubit count is not 1.

Examples

>>> ResultType.AdjointGradient(observable=Observable.Z(),
                            target=0, parameters=["alpha", "beta"])
>>> tensor_product = Observable.Y() @ Observable.Z()
>>> hamiltonian = Observable.Y() @ Observable.Z() + Observable.H()
>>> ResultType.AdjointGradient(
>>>     observable=tensor_product,
>>>     target=[[0, 1], [2]],
>>>     parameters=["alpha", "beta"],
>>> )
static adjoint_gradient(observable: Observable, target: list[QubitSetInput] | None = None, parameters: list[str | FreeParameter] | None = None) ResultType[source]

Registers this function into the circuit class.

Parameters:
  • observable (Observable) – The expectation value of this observable is the function against which parameters in the gradient are differentiated.

  • target (list[QubitSetInput] | None) – Target qubits that the result type is requested for. Each term in the target list should have the same number of qubits as the corresponding term in the observable. Default is None, which means the observable must operate only on 1 qubit and it is applied to all qubits in parallel.

  • parameters (list[Union[str, FreeParameter]] | None) – The free parameters in the circuit to differentiate with respect to. Default: all.

Returns:

ResultType – gradient computed via adjoint differentiation as a requested result type

Examples

>>> alpha, beta = FreeParameter('alpha'), FreeParameter('beta')
>>> circ = Circuit().h(0).h(1).rx(0, alpha).yy(0, 1, beta).adjoint_gradient(
>>>     observable=Observable.Z(), target=[0], parameters=[alpha, beta]
>>> )
class braket.circuits.result_types.Amplitude(state: list[str])[source]

Bases: ResultType

The amplitude of the specified quantum states as a requested result type. This is available on simulators only when shots=0.

Initializes an Amplitude.

Parameters:

state (list[str]) – list of quantum states as strings with “0” and “1”

Raises:

ValueError – If state is None or an empty list, or state is not a list of strings of ‘0’ and ‘1’

Examples

>>> ResultType.Amplitude(state=['01', '10'])
property state: list[str]
static amplitude(state: list[str]) ResultType[source]

Registers this function into the circuit class.

Parameters:

state (list[str]) – list of quantum states as strings with “0” and “1”

Returns:

ResultType – state vector as a requested result type

Examples

>>> circ = Circuit().amplitude(state=["01", "10"])
class braket.circuits.result_types.Probability(target: QubitSetInput | None = None)[source]

Bases: ResultType

Probability in the computational basis as the requested result type.

It can be the probability of all states if no targets are specified, or the marginal probability of a restricted set of states if only a subset of all qubits are specified as targets.

For shots>0, this is calculated by measurements. For shots=0, this is supported only on simulators and represents the exact result.

Inits a Probability.

Parameters:

target (QubitSetInput | None) – The target qubits that the result type is requested for. Default is None, which means all qubits for the circuit.

Examples

>>> ResultType.Probability(target=[0, 1])
property target: QubitSet
static probability(target: QubitSetInput | None = None) ResultType[source]

Registers this function into the circuit class.

Parameters:

target (QubitSetInput | None) – The target qubits that the result type is requested for. Default is None, which means all qubits for the circuit.

Returns:

ResultType – probability as a requested result type

Examples

>>> circ = Circuit().probability(target=[0, 1])
class braket.circuits.result_types.Expectation(observable: Observable, target: QubitSetInput | None = None)[source]

Bases: ObservableResultType

Expectation of the specified target qubit set and observable as the requested result type.

If no targets are specified, the observable must operate only on 1 qubit and it is applied to all qubits in parallel. Otherwise, the number of specified targets must be equivalent to the number of qubits the observable can be applied to.

For shots>0, this is calculated by measurements. For shots=0, this is supported only by simulators and represents the exact result.

See braket.circuits.observables module for all of the supported observables.

Inits an Expectation.

Parameters:
  • observable (Observable) – the observable for the result type

  • target (QubitSetInput | None) – Target qubits that the result type is requested for. Default is None, which means the observable must operate only on 1 qubit and it is applied to all qubits in parallel.

Examples

>>> ResultType.Expectation(observable=Observable.Z(), target=0)
>>> tensor_product = Observable.Y() @ Observable.Z()
>>> ResultType.Expectation(observable=tensor_product, target=[0, 1])
static expectation(observable: Observable, target: QubitSetInput | None = None) ResultType[source]

Registers this function into the circuit class.

Parameters:
  • observable (Observable) – the observable for the result type

  • target (QubitSetInput | None) – Target qubits that the result type is requested for. Default is None, which means the observable must operate only on 1 qubit and it is applied to all qubits in parallel.

Returns:

ResultType – expectation as a requested result type

Examples

>>> circ = Circuit().expectation(observable=Observable.Z(), target=0)
class braket.circuits.result_types.Sample(observable: Observable, target: QubitSetInput | None = None)[source]

Bases: ObservableResultType

Sample of specified target qubit set and observable as the requested result type.

If no targets are specified, the observable must operate only on 1 qubit and it is applied to all qubits in parallel. Otherwise, the number of specified targets must equal the number of qubits the observable can be applied to.

This is only available for shots>0.

See braket.circuits.observables module for all of the supported observables.

Inits a Sample.

Parameters:
  • observable (Observable) – the observable for the result type

  • target (QubitSetInput | None) – Target qubits that the result type is requested for. Default is None, which means the observable must operate only on 1 qubit and it is applied to all qubits in parallel.

Examples

>>> ResultType.Sample(observable=Observable.Z(), target=0)
>>> tensor_product = Observable.Y() @ Observable.Z()
>>> ResultType.Sample(observable=tensor_product, target=[0, 1])
static sample(observable: Observable, target: QubitSetInput | None = None) ResultType[source]

Registers this function into the circuit class.

Parameters:
  • observable (Observable) – the observable for the result type

  • target (QubitSetInput | None) – Target qubits that the result type is requested for. Default is None, which means the observable must operate only on 1 qubit and it is applied to all qubits in parallel.

Returns:

ResultType – sample as a requested result type

Examples

>>> circ = Circuit().sample(observable=Observable.Z(), target=0)
class braket.circuits.result_types.Variance(observable: Observable, target: QubitSetInput | None = None)[source]

Bases: ObservableResultType

Variance of specified target qubit set and observable as the requested result type.

If no targets are specified, the observable must operate only on 1 qubit and it is applied to all qubits in parallel. Otherwise, the number of targets specified must equal the number of qubits that the observable can be applied to.

For shots>0, this is calculated by measurements. For shots=0, this is supported only by simulators and represents the exact result.

See braket.circuits.observables module for all of the supported observables.

Inits a Variance.

Parameters:
  • observable (Observable) – the observable for the result type

  • target (QubitSetInput | None) – Target qubits that the result type is requested for. Default is None, which means the observable must operate only on 1 qubit and it is applied to all qubits in parallel.

Raises:

ValueError – If the observable’s qubit count does not equal the number of target qubits, or if target=None and the observable’s qubit count is not 1.

Examples

>>> ResultType.Variance(observable=Observable.Z(), target=0)
>>> tensor_product = Observable.Y() @ Observable.Z()
>>> ResultType.Variance(observable=tensor_product, target=[0, 1])
static variance(observable: Observable, target: QubitSetInput | None = None) ResultType[source]

Registers this function into the circuit class.

Parameters:
  • observable (Observable) – the observable for the result type

  • target (QubitSetInput | None) – Target qubits that the result type is requested for. Default is None, which means the observable must only operate on 1 qubit and it will be applied to all qubits in parallel

Returns:

ResultType – variance as a requested result type

Examples

>>> circ = Circuit().variance(observable=Observable.Z(), target=0)