braket.circuits.result_type module

class braket.circuits.result_type.ResultType(ascii_symbol: str)[source]

Bases: object

Class ResultType represents a requested result type for the circuit. This class is considered the result type definition containing the metadata that defines what a requested result type is and what it does.

Parameters

ascii_symbol (str) – ASCII string symbol for the result type. This is used when printing a diagram of circuits.

Raises

ValueErrorascii_symbol is None

property ascii_symbol

Returns the ascii symbol for the requested result type.

Type

str

property name

Returns the name of the result type

Returns

The name of the result type as a string

to_ir(*args, **kwargs) → Any[source]

Returns IR object of the result type

Parameters
  • *args – Positional arguments

  • **kwargs – Keyword arguments

Returns

IR object of the result type

copy(target_mapping: Dict[Union[Qubit, int], Union[Qubit, int]] = {}, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)[source]

Return a shallow copy of the result type.

Note

If target_mapping is specified, then self.target is mapped to the specified qubits. This is useful apply an instruction to a circuit and change the target qubits.

Parameters
  • target_mapping (dictionary[int or Qubit, int or Qubit], optional) – A dictionary of qubit mappings to apply to the target. Key is the qubit in this target and the value is what the key is changed to. Default = {}.

  • target (int, Qubit, or iterable of int / Qubit, optional) – Target qubits for the new instruction.

Returns

ResultType – A shallow copy of the result type.

Raises

TypeError – If both target_mapping and target are supplied.

Examples

>>> result_type = ResultType.Probabilities(targets=[0])
>>> new_result_type = result_type.copy()
>>> new_result_type.targets
QubitSet(Qubit(0))
>>> new_result = result_type.copy(target_mapping={0: 5})
>>> new_result_type.target
QubitSet(Qubit(5))
>>> new_result = result_type.copy(target=[5])
>>> new_result_type.target
QubitSet(Qubit(5))
classmethod register_result_type(result_type: ResultType)[source]

Register a result type implementation by adding it into the ResultType class.

Parameters

result_type (ResultType) – ResultType instance to register.

class Amplitude(state: List[str])

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'])
static amplitude(state: List[str])braket.circuits.result_type.ResultType

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"])
property state
to_ir() → braket.ir.jaqcd.results.Amplitude

Returns IR object of the result type

Parameters
  • *args – Positional arguments

  • **kwargs – Keyword arguments

Returns

IR object of the result type

class Expectation(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)

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

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])
static expectation(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)braket.circuits.result_type.ResultType

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)
to_ir() → braket.ir.jaqcd.results.Expectation

Returns IR object of the result type

Parameters
  • *args – Positional arguments

  • **kwargs – Keyword arguments

Returns

IR object of the result type

class Probability(target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)

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. For shots=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])
static probability(target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)braket.circuits.result_type.ResultType

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])
property target
to_ir() → braket.ir.jaqcd.results.Probability

Returns IR object of the result type

Parameters
  • *args – Positional arguments

  • **kwargs – Keyword arguments

Returns

IR object of the result type

class Sample(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)

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])
static sample(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)braket.circuits.result_type.ResultType

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)
to_ir() → braket.ir.jaqcd.results.Sample

Returns IR object of the result type

Parameters
  • *args – Positional arguments

  • **kwargs – Keyword arguments

Returns

IR object of the result type

class StateVector

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_symbol (str) – ASCII string symbol for the result type. This is used when printing a diagram of circuits.

Raises

ValueErrorascii_symbol is None

static state_vector()braket.circuits.result_type.ResultType

Registers this function into the circuit class.

Returns

ResultType – state vector as a requested result type

Examples

>>> circ = Circuit().state_vector()
to_ir() → braket.ir.jaqcd.results.StateVector

Returns IR object of the result type

Parameters
  • *args – Positional arguments

  • **kwargs – Keyword arguments

Returns

IR object of the result type

class Variance(observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)

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

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

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

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)
class braket.circuits.result_type.ObservableResultType(ascii_symbol: str, observable: braket.circuits.observable.Observable, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)[source]

Bases: braket.circuits.result_type.ResultType

Result types with observables and targets. 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.

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.

property observable
property target