braket.circuits.noise_model.criteria module

class braket.circuits.noise_model.criteria.CriteriaKey(value)[source]

Bases: str, Enum

Specifies the types of keys that a criteria may use to match an instruction, observable, etc.

QUBIT = 'QUBIT'
GATE = 'GATE'
UNITARY_GATE = 'UNITARY_GATE'
OBSERVABLE = 'OBSERVABLE'
class braket.circuits.noise_model.criteria.CriteriaKeyResult(value)[source]

Bases: str, Enum

The get_keys() method may return this enum instead of actual keys for a given criteria key type.

ALL = 'ALL'
class braket.circuits.noise_model.criteria.Criteria[source]

Bases: ABC

Represents conditions that need to be met for a noise to apply to a circuit.

abstract applicable_key_types() Iterable[CriteriaKey][source]

Returns the relevant set of keys for the Criteria

This informs what the Criteria operates on and can be used to optimize which Criteria is relevant.

Returns:

Iterable[CriteriaKey] – The relevant set of keys for the Criteria.

abstract get_keys(key_type: CriteriaKey) CriteriaKeyResult | set[Any][source]

Returns a set of key for a given key type.

Parameters:

key_type (CriteriaKey) – The criteria key type.

Returns:

Union[CriteriaKeyResult, set[Any]] – Returns a set of keys for a key type. The actual returned keys will depend on the CriteriaKey. If the provided key type is not relevant the returned list will be empty. If the provided key type is relevant for all possible inputs, the string CriteriaKeyResult.ALL will be returned.

abstract to_dict() dict[source]

Converts this Criteria object into a dict representation

Returns:

dict – A dictionary object representing the Criteria.

classmethod from_dict(criteria: dict) Criteria[source]

Converts a dictionary representing an object of this class into an instance of this class.

Parameters:

criteria (dict) – A dictionary representation of an object of this class.

Returns:

Criteria – An object of this class that corresponds to the passed in dictionary.

classmethod register_criteria(criteria: type[Criteria]) None[source]

Register a criteria implementation by adding it into the Criteria class.

Parameters:

criteria (type[Criteria]) – Criteria class to register.

class GateCriteria(gates: Gate | Iterable[Gate] | None = None, qubits: Qubit | int | Iterable[Qubit | int] | None = None)

Bases: CircuitInstructionCriteria

This class models noise Criteria based on named Braket SDK Gates.

Creates Gate-based Criteria. See instruction_matches() for more details.

Parameters:
  • gates (Optional[Union[Gate, Iterable[Gate]]]) – A set of relevant Gates. All the Gates must have the same fixed_qubit_count(). Optional. If gates are not provided this matcher will match on all gates.

  • qubits (Optional[QubitSetInput]) – A set of relevant qubits. If no qubits are provided, all (possible) qubits are considered to be relevant.

Raises:
  • ValueError – If the gates don’t all operate on the same number of qubits, or if

  • qubits are not valid targets for the provided gates.

applicable_key_types() Iterable[CriteriaKey]

Returns an Iterable of criteria keys.

Returns:

Iterable[CriteriaKey] – This Criteria operates on Gates and Qubits.

classmethod from_dict(criteria: dict) Criteria

Deserializes a dictionary into a Criteria object.

Parameters:

criteria (dict) – A dictionary representation of a GateCriteria.

Returns:

Criteria – A deserialized GateCriteria represented by the passed in serialized data.

get_keys(key_type: CriteriaKey) CriteriaKeyResult | set[Any]

Gets the keys for a given CriteriaKey.

Parameters:

key_type (CriteriaKey) – The relevant Criteria Key.

Returns:

Union[CriteriaKeyResult, set[Any]] – The return value is based on the key type: GATE will return a set of Gate classes that are relevant to this Criteria. QUBIT will return a set of qubit targets that are relevant to this Criteria, or CriteriaKeyResult.ALL if the Criteria is relevant for all (possible) qubits. All other keys will return an empty list.

instruction_matches(instruction: Instruction) bool

Returns true if an Instruction matches the criteria.

Parameters:

instruction (Instruction) – An Instruction to match.

Returns:

bool – Returns true if the operator is one of the Gates provided in the constructor and the target is a qubit (or set of qubits) provided in the constructor. If gates were not provided in the constructor, then this method will accept any Gate. If qubits were not provided in the constructor, then this method will accept any Instruction target.

to_dict() dict

Converts a dictionary representing an object of this class into an instance of this class.

Returns:

dict – A dictionary representing the serialized version of this Criteria.

class ObservableCriteria(observables: Observable | Iterable[Observable] | None = None, qubits: Qubit | int | Iterable[Qubit | int] | None = None)

Bases: ResultTypeCriteria

This class models noise Criteria based on the Braket SDK Observable classes.

Creates Observable-based Criteria. See instruction_matches() for more details.

Parameters:
  • observables (Optional[Union[Observable, Iterable[Observable]]]) – A set of relevant Observables. Observables must only operate on a single qubit. Optional. If observables are not specified, this criteria will match on any observable.

  • qubits (Optional[QubitSetInput]) – A set of relevant qubits. If no qubits are provided, all (possible) qubits are considered to be relevant.

Throws:

ValueError: If the operators operate on more than one qubit.

applicable_key_types() Iterable[CriteriaKey]

Returns an Iterable of criteria keys.

Returns:

Iterable[CriteriaKey] – This Criteria operates on Observables and Qubits.

classmethod from_dict(criteria: dict) Criteria

Deserializes a dictionary into a Criteria object.

Parameters:

criteria (dict) – A dictionary representation of a GateCriteria.

Returns:

Criteria – A deserialized GateCriteria represented by the passed in serialized data.

get_keys(key_type: CriteriaKey) CriteriaKeyResult | set[Any]

Gets the keys for a given CriteriaKey.

Parameters:

key_type (CriteriaKey) – The relevant Criteria Key.

Returns:

Union[CriteriaKeyResult, set[Any]] – The return value is based on the key type: OBSERVABLE will return a set of Observable classes that are relevant to this Criteria, or CriteriaKeyResult.ALL if the Criteria is relevant for all (possible) observables. QUBIT will return a set of qubit targets that are relevant to this Criteria, or CriteriaKeyResult.ALL if the Criteria is relevant for all (possible) qubits. All other keys will return an empty set.

result_type_matches(result_type: ResultType) bool

Returns true if a result type matches the criteria.

Parameters:

result_type (ResultType) – A result type or list of result types to match.

Returns:

bool – Returns true if the result type is one of the Observables provided in the constructor and the target is a qubit (or set of qubits)provided in the constructor. If observables were not provided in the constructor, then this method will accept any Observable. If qubits were not provided in the constructor, then this method will accept any result type target.

to_dict() dict

Converts a dictionary representing an object of this class into an instance of this class.

Returns:

dict – A dictionary representing the serialized version of this Criteria.

class QubitInitializationCriteria(qubits: Qubit | int | Iterable[Qubit | int] | None = None)

Bases: InitializationCriteria

This class models initialization noise Criteria based on qubits.

Creates initialization noise Qubit-based Criteria.

Parameters:

qubits (Optional[QubitSetInput]) – A set of relevant qubits. If no qubits are provided, all (possible) qubits are considered to be relevant.

applicable_key_types() Iterable[CriteriaKey]

Gets the QUBIT criteria key.

Returns:

Iterable[CriteriaKey] – This Criteria operates on Qubits, but is valid for all Gates.

classmethod from_dict(criteria: dict) Criteria

Deserializes a dictionary into a Criteria object.

Parameters:

criteria (dict) – A dictionary representation of a QubitCriteria.

Returns:

Criteria – A deserialized QubitCriteria represented by the passed in serialized data.

get_keys(key_type: CriteriaKey) CriteriaKeyResult | set[Any]

Gets the keys for a given CriteriaKey.

Parameters:

key_type (CriteriaKey) – The relevant Criteria Key.

Returns:

Union[CriteriaKeyResult, set[Any]] – The return value is based on the key type: QUBIT will return a set of qubit targets that are relevant to this Criteria, or CriteriaKeyResult.ALL if the Criteria is relevant for all (possible) qubits. All other keys will return an empty set.

qubit_intersection(qubits: Qubit | int | Iterable[Qubit | int]) Qubit | int | Iterable[Qubit | int]

Returns subset of passed qubits that match the criteria.

Parameters:

qubits (QubitSetInput) – A qubit or set of qubits that may match the criteria.

Returns:

QubitSetInput – The subset of passed qubits that match the criteria.

to_dict() dict

Converts a dictionary representing an object of this class into an instance of this class.

Returns:

dict – A dictionary representing the serialized version of this Criteria.

class UnitaryGateCriteria(unitary: Unitary, qubits: Qubit | int | Iterable[Qubit | int] | None = None)

Bases: CircuitInstructionCriteria

This class models noise Criteria based on unitary gates represented as a matrix.

Creates unitary gate-based Criteria. See instruction_matches() for more details.

Parameters:
  • unitary (Unitary) – A unitary gate matrix represented as a Braket Unitary.

  • qubits (Optional[QubitSetInput]) – A set of relevant qubits. If no qubits are provided, all (possible) qubits are considered to be relevant.

Raises:

ValueError – If unitary is not a Unitary type.

applicable_key_types() Iterable[CriteriaKey]

Returns keys based on criterion.

Returns:

Iterable[CriteriaKey] – This Criteria operates on unitary gates and Qubits.

classmethod from_dict(criteria: dict) Criteria

Deserializes a dictionary into a Criteria object.

Parameters:

criteria (dict) – A dictionary representation of a UnitaryGateCriteria.

Returns:

Criteria – A deserialized UnitaryGateCriteria represented by the passed in serialized data.

get_keys(key_type: CriteriaKey) CriteriaKeyResult | set[Any]

Gets the keys for a given CriteriaKey.

Parameters:

key_type (CriteriaKey) – The relevant Criteria Key.

Returns:

Union[CriteriaKeyResult, set[Any]] – The return value is based on the key type: UNITARY_GATE will return a set containing the bytes of the unitary matrix representing the unitary gate. QUBIT will return a set of qubit targets that are relevant to this Criteria, or CriteriaKeyResult.ALL if the Criteria is relevant for all (possible) qubits. All other keys will return an empty list.

instruction_matches(instruction: Instruction) bool

Returns true if an Instruction matches the criteria.

Parameters:

instruction (Instruction) – An Instruction to match.

Returns:

bool – Returns true if the operator is one of the Unitary gates provided in the constructor and the target is a qubit (or set of qubits) provided in the constructor. If qubits were not provided in the constructor, then this method will ignore the Instruction target.

to_dict() dict

Converts a dictionary representing an object of this class into an instance of this class.

Returns:

dict – A dictionary representing the serialized version of this Criteria.