ResultTypes
- class braket.circuits.result_types.StateVector[source]
Bases:
ResultTypeThe 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:
ValueError –
ascii_symbolsisNone
- class braket.circuits.result_types.DensityMatrix(target=None)[source]
Bases:
ResultTypeThe full density matrix as a requested result type. This is available on simulators only when
shots=0.- Parameters:
target (QubitSetInput | None)
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
>>> result_types.DensityMatrix(target=[0, 1])
- static density_matrix(target=None)[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.- Return type:
ResultType
- Returns:
ResultType – density matrix as a requested result type
Examples
>>> circ = Circuit().density_matrix(target=[0, 1])
- class braket.circuits.result_types.AdjointGradient(observable, target=None, parameters=None)[source]
Bases:
ObservableParameterResultTypeThe gradient of the expectation value of the provided observable, applied to target, with respect to the given parameter.
- Parameters:
observable (Observable)
target (list[QubitSetInput] | None)
parameters (list[str | FreeParameter] | None)
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[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=Noneand the observable’s qubit count is not 1.
Examples
>>> result_types.AdjointGradient(observable=observables.Z(0), parameters=["alpha", "beta"]) >>> result_types.AdjointGradient(observable=observables.Z(), target=0, parameters=["alpha", "beta"])
>>> tensor_product = observables.Y(0) @ observables.Z(1) >>> hamiltonian = observables.Y(0) @ observables.Z(1) + observables.H(0) >>> result_types.AdjointGradient( >>> observable=tensor_product, >>> parameters=["alpha", "beta"], >>> )
- static adjoint_gradient(observable, target=None, parameters=None)[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[str | FreeParameter] | None) – The free parameters in the circuit to differentiate with respect to. Default:
all.
- Return type:
ResultType
- 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=observables.Z(0), parameters=[alpha, beta] >>> )
- class braket.circuits.result_types.Amplitude(state)[source]
Bases:
ResultTypeThe amplitude of the specified quantum states as a requested result type. This is available on simulators only when
shots=0.- Parameters:
state (
list[str])
Initializes an
Amplitude.- Parameters:
state (list[str]) – list of quantum states as strings with “0” and “1”
- Raises:
ValueError – If state is
Noneor an empty list, or state is not a list of strings of ‘0’ and ‘1’
Examples
>>> result_types.Amplitude(state=["01", "10"])
- property state: list[str]
- class braket.circuits.result_types.Probability(target=None)[source]
Bases:
ResultTypeProbability 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. Forshots=0, this is supported only on simulators and represents the exact result.- Parameters:
target (QubitSetInput | None)
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
>>> result_types.Probability(target=[0, 1])
- static probability(target=None)[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.- Return type:
ResultType
- Returns:
ResultType – probability as a requested result type
Examples
>>> circ = Circuit().probability(target=[0, 1])
- class braket.circuits.result_types.Expectation(observable, target=None)[source]
Bases:
ObservableResultTypeExpectation 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. Forshots=0, this is supported only by simulators and represents the exact result.See
braket.circuits.observablesmodule for all of the supported observables.- Parameters:
observable (Observable)
target (QubitSetInput | None)
Inits an
Expectation.- Parameters:
observable (Observable) – the observable for the result type
target (QubitSetInput | None) – Target qubits that the result type is requested for. If not provided, the observable’s target will be used instead. If neither exist, then it is applied to all qubits in parallel; in this case the observable must operate only on 1 qubit. Default:
None.
Examples
>>> result_types.Expectation(observable=observables.Z(0)) >>> result_types.Expectation(observable=observables.Z(), target=0)
>>> tensor_product = observables.Y(0) @ observables.Z(1) >>> result_types.Expectation(observable=tensor_product)
- static expectation(observable, target=None)[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.
- Return type:
ResultType
- Returns:
ResultType – expectation as a requested result type
Examples
>>> circ = Circuit().expectation(observable=observables.Z(0))
- class braket.circuits.result_types.Sample(observable, target=None)[source]
Bases:
ObservableResultTypeSample 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.observablesmodule for all of the supported observables.- Parameters:
observable (Observable)
target (QubitSetInput | None)
Inits a
Sample.- Parameters:
observable (Observable) – the observable for the result type
target (QubitSetInput | None) – Target qubits that the result type is requested for. If not provided, the observable’s target will be used instead. If neither exist, then it is applied to all qubits in parallel; in this case the observable must operate only on 1 qubit. Default:
None.
Examples
>>> result_types.Sample(observable=observables.Z(0)) >>> result_types.Sample(observable=observables.Z(), target=0)
>>> tensor_product = observables.Y(0) @ observables.Z(1) >>> result_types.Sample(observable=tensor_product)
- static sample(observable, target=None)[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.
- Return type:
ResultType
- Returns:
ResultType – sample as a requested result type
Examples
>>> circ = Circuit().sample(observable=observables.Z(0))
- class braket.circuits.result_types.Variance(observable, target=None)[source]
Bases:
ObservableResultTypeVariance 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. Forshots=0, this is supported only by simulators and represents the exact result.See
braket.circuits.observablesmodule for all of the supported observables.- Parameters:
observable (Observable)
target (QubitSetInput | None)
Inits a
Variance.- Parameters:
observable (Observable) – the observable for the result type
target (QubitSetInput | None) – Target qubits that the result type is requested for. If not provided, the observable’s target will be used instead. If neither exist, then it is applied to all qubits in parallel; in this case the observable must operate only on 1 qubit. Default:
None.
- Raises:
ValueError – If the observable’s qubit count does not equal the number of target qubits, or if
target=Noneand the observable’s qubit count is not 1.
Examples
>>> result_types.Variance(observable=observables.Z(0)) >>> result_types.Variance(observable=observables.Z(), target=0)
>>> tensor_product = observables.Y(0) @ observables.Z(1) >>> result_types.Variance(observable=tensor_product)
- static variance(observable, target=None)[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
- Return type:
ResultType
- Returns:
ResultType – variance as a requested result type
Examples
>>> circ = Circuit().variance(observable=observables.Z(0))