braket.circuits.result_types module¶
-
class
braket.circuits.result_types.
StateVector
[source]¶ Bases:
braket.circuits.result_type.ResultType
The full state vector as a requested result type. This is only available when
shots=0
for simulators.- Parameters
ascii_symbols (List[str]) – ASCII string symbols for the result type. This is used when printing a diagram of circuits.
- Raises
ValueError –
ascii_symbols
is None
-
to_ir
() → braket.ir.jaqcd.results.StateVector[source]¶ Returns IR object of the result type
- Parameters
*args – Positional arguments
**kwargs – Keyword arguments
- Returns
IR object of the result type
-
static
state_vector
() → braket.circuits.result_type.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.
Amplitude
(state: List[str])[source]¶ Bases:
braket.circuits.result_type.ResultType
The amplitude of specified quantum states as a requested result type. This is only available when
shots=0
for simulators.- Parameters
state (List[str]) – list of quantum states as strings with “0” and “1”
- Raises
ValueError – If state is None or an empty list
Examples
>>> ResultType.Amplitude(state=['01', '10'])
-
property
state
¶
-
to_ir
() → braket.ir.jaqcd.results.Amplitude[source]¶ Returns IR object of the result type
- Parameters
*args – Positional arguments
**kwargs – Keyword arguments
- Returns
IR object of the result type
-
static
amplitude
(state: List[str]) → braket.circuits.result_type.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: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)[source]¶ Bases:
braket.circuits.result_type.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 target.
For
shots>0
, this is calculated by measurements. Forshots=0
, this is supported only by simulators and represents the exact result.- Parameters
target (int, Qubit, or iterable of int / Qubit, optional) – 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
¶
-
to_ir
() → braket.ir.jaqcd.results.Probability[source]¶ Returns IR object of the result type
- Parameters
*args – Positional arguments
**kwargs – Keyword arguments
- Returns
IR object of the result type
-
static
probability
(target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None) → braket.circuits.result_type.ResultType[source]¶ Registers this function into the circuit class.
- Parameters
target (int, Qubit, or iterable of int / Qubit, optional) – 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: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)[source]¶ Bases:
braket.circuits.result_type.ObservableResultType
Expectation of specified target qubit set and observable as the requested result type.
If no targets are specified, the observable must only operate on 1 qubit and it will be 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.observables
module for all of the supported observables.- Parameters
observable (Observable) – the observable for the result type
target (int, Qubit, or iterable of int / Qubit, optional) – 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
- Raises
ValueError – If the observable’s qubit count and the number of target qubits are not equal. Or, if target=None and the observable’s qubit count is not 1.
Examples
>>> ResultType.Expectation(observable=Observable.Z(), target=0)
>>> tensor_product = Observable.Y() @ Observable.Z() >>> ResultType.Expectation(observable=tensor_product, target=[0, 1])
-
to_ir
() → braket.ir.jaqcd.results.Expectation[source]¶ Returns IR object of the result type
- Parameters
*args – Positional arguments
**kwargs – Keyword arguments
- Returns
IR object of the result type
-
static
expectation
(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None) → braket.circuits.result_type.ResultType[source]¶ Registers this function into the circuit class.
- Parameters
observable (Observable) – the observable for the result type
target (int, Qubit, or iterable of int / Qubit, optional) – 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 – expectation as a requested result type
Examples
>>> circ = Circuit().expectation(observable=Observable.Z(), target=0)
-
class
braket.circuits.result_types.
Sample
(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)[source]¶ Bases:
braket.circuits.result_type.ObservableResultType
Sample of specified target qubit set and observable as the requested result type.
If no targets are specified, the observable must only operate on 1 qubit and it will be 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.
This is only available for
shots>0
.See
braket.circuits.observables
module for all of the supported observables.- Parameters
observable (Observable) – the observable for the result type
target (int, Qubit, or iterable of int / Qubit, optional) – 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
- Raises
ValueError – If the observable’s qubit count and the number of target qubits are not equal. Or, if target=None and the observable’s qubit count is not 1.
Examples
>>> ResultType.Sample(observable=Observable.Z(), target=0)
>>> tensor_product = Observable.Y() @ Observable.Z() >>> ResultType.Sample(observable=tensor_product, target=[0, 1])
-
to_ir
() → braket.ir.jaqcd.results.Sample[source]¶ Returns IR object of the result type
- Parameters
*args – Positional arguments
**kwargs – Keyword arguments
- Returns
IR object of the result type
-
static
sample
(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None) → braket.circuits.result_type.ResultType[source]¶ Registers this function into the circuit class.
- Parameters
observable (Observable) – the observable for the result type
target (int, Qubit, or iterable of int / Qubit, optional) – 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 – sample as a requested result type
Examples
>>> circ = Circuit().sample(observable=Observable.Z(), target=0)
-
class
braket.circuits.result_types.
Variance
(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)[source]¶ Bases:
braket.circuits.result_type.ObservableResultType
Variance of specified target qubit set and observable as the requested result type.
If no targets are specified, the observable must only operate on 1 qubit and it will be 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.observables
module for all of the supported observables.- Parameters
observable (Observable) – the observable for the result type
target (int, Qubit, or iterable of int / Qubit, optional) – 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
- Raises
ValueError – If the observable’s qubit count and the number of target qubits are not equal. 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])
-
to_ir
() → braket.ir.jaqcd.results.Variance[source]¶ Returns IR object of the result type
- Parameters
*args – Positional arguments
**kwargs – Keyword arguments
- Returns
IR object of the result type
-
static
variance
(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None) → braket.circuits.result_type.ResultType[source]¶ Registers this function into the circuit class.
- Parameters
observable (Observable) – the observable for the result type
target (int, Qubit, or iterable of int / Qubit, optional) – 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)