Criteria
- class braket.circuits.noise_model.criteria.CriteriaKey(*values)[source]
Bases:
StrEnumSpecifies 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(*values)[source]
Bases:
StrEnumThe 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:
ABCRepresents conditions that need to be met for a noise to apply to a circuit.
- abstractmethod applicable_key_types()[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.
- Return type:
Iterable[CriteriaKey]- Returns:
Iterable[CriteriaKey] – The relevant set of keys for the Criteria.
- abstractmethod get_keys(key_type)[source]
Returns a set of key for a given key type.
- Parameters:
key_type (CriteriaKey) – The criteria key type.
- Return type:
CriteriaKeyResult|set[Any]- Returns:
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.
- abstractmethod to_dict()[source]
Converts this Criteria object into a dict representation
- Return type:
dict- Returns:
dict – A dictionary object representing the Criteria.
- classmethod from_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.
- Return type:
- Returns:
Criteria – An object of this class that corresponds to the passed in dictionary.
- classmethod register_criteria(criteria)[source]
Register a criteria implementation by adding it into the Criteria class.
- class GateCriteria(gates=None, qubits=None)
Bases:
CircuitInstructionCriteriaThis class models noise Criteria based on named Braket SDK Gates.
- Parameters:
Creates Gate-based Criteria. See instruction_matches() for more details.
- Parameters:
gates (Gate | Iterable[Gate] | None) – 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 (QubitSetInput | None) – 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()
Returns an Iterable of criteria keys.
- Return type:
Iterable[CriteriaKey]- Returns:
Iterable[CriteriaKey] – This Criteria operates on Gates and Qubits.
- classmethod from_dict(criteria)
Deserializes a dictionary into a Criteria object.
- Parameters:
criteria (dict) – A dictionary representation of a GateCriteria.
- Return type:
- Returns:
Criteria – A deserialized GateCriteria represented by the passed in serialized data.
- get_keys(key_type)
Gets the keys for a given CriteriaKey.
- Parameters:
key_type (CriteriaKey) – The relevant Criteria Key.
- Return type:
CriteriaKeyResult|set[Any]- Returns:
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)
Returns true if an Instruction matches the criteria.
- Parameters:
instruction (Instruction) – An Instruction to match.
- Return type:
bool- 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()
Converts a dictionary representing an object of this class into an instance of this class.
- Return type:
dict- Returns:
dict – A dictionary representing the serialized version of this Criteria.
- class MeasureCriteria(qubits=None)
Bases:
CircuitInstructionCriteriaThis class models noise Criteria based on Measure instructions.
- Parameters:
qubits (
Union[Qubit,int,Iterable[Union[Qubit,int]],None])
Creates Measure-based Criteria.
- Parameters:
qubits (QubitSetInput | None) – A set of relevant qubits. If no qubits are provided, all (possible) qubits are considered to be relevant.
- applicable_key_types()
Returns an Iterable of criteria keys.
- Return type:
Iterable[CriteriaKey]- Returns:
Iterable[CriteriaKey] – This Criteria operates on Qubits.
- classmethod from_dict(criteria)
Deserializes a dictionary into a Criteria object.
- Parameters:
criteria (dict) – A dictionary representation of a MeasureCriteria.
- Return type:
- Returns:
Criteria – A deserialized MeasureCriteria represented by the passed in serialized data.
- get_keys(key_type)
Gets the keys for a given CriteriaKey.
- Parameters:
key_type (CriteriaKey) – The relevant Criteria Key.
- Return type:
CriteriaKeyResult|set[Any]- Returns:
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.
- instruction_matches(instruction)
Returns true if an Instruction matches the criteria.
- Parameters:
instruction (Instruction) – An Instruction to match.
- Return type:
bool- Returns:
bool – Returns true if the instruction is a Measure instruction 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 accept any Measure instruction target.
- to_dict()
Converts a dictionary representing an object of this class into an instance of this class.
- Return type:
dict- Returns:
dict – A dictionary representing the serialized version of this Criteria.
- class ObservableCriteria(observables=None, qubits=None)
Bases:
ResultTypeCriteriaThis class models noise Criteria based on the Braket SDK Observable classes.
- Parameters:
observables (
Observable|Iterable[Observable] |None)qubits (
Union[Qubit,int,Iterable[Union[Qubit,int]],None])
Creates Observable-based Criteria. See instruction_matches() for more details.
- Parameters:
observables (Observable | Iterable[Observable] | None) – 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 (QubitSetInput | None) – A set of relevant qubits. If no qubits are provided, all (possible) qubits are considered to be relevant.
- applicable_key_types()
Returns an Iterable of criteria keys.
- Return type:
Iterable[CriteriaKey]- Returns:
Iterable[CriteriaKey] – This Criteria operates on Observables and Qubits.
- classmethod from_dict(criteria)
Deserializes a dictionary into a Criteria object.
- Parameters:
criteria (dict) – A dictionary representation of a GateCriteria.
- Return type:
- Returns:
Criteria – A deserialized GateCriteria represented by the passed in serialized data.
- get_keys(key_type)
Gets the keys for a given CriteriaKey.
- Parameters:
key_type (CriteriaKey) – The relevant Criteria Key.
- Return type:
CriteriaKeyResult|set[Any]- Returns:
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)
Returns true if a result type matches the criteria.
- Parameters:
result_type (ResultType) – A result type or list of result types to match.
- Return type:
bool- 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()
Converts a dictionary representing an object of this class into an instance of this class.
- Return type:
dict- Returns:
dict – A dictionary representing the serialized version of this Criteria.
- class QubitInitializationCriteria(qubits=None)
Bases:
InitializationCriteriaThis class models initialization noise Criteria based on qubits.
- Parameters:
qubits (
Union[Qubit,int,Iterable[Union[Qubit,int]],None])
Creates initialization noise Qubit-based Criteria.
- Parameters:
qubits (QubitSetInput | None) – A set of relevant qubits. If no qubits are provided, all (possible) qubits are considered to be relevant.
- applicable_key_types()
Gets the QUBIT criteria key.
- Return type:
Iterable[CriteriaKey]- Returns:
Iterable[CriteriaKey] – This Criteria operates on Qubits, but is valid for all Gates.
- classmethod from_dict(criteria)
Deserializes a dictionary into a Criteria object.
- Parameters:
criteria (dict) – A dictionary representation of a QubitCriteria.
- Return type:
- Returns:
Criteria – A deserialized QubitCriteria represented by the passed in serialized data.
- get_keys(key_type)
Gets the keys for a given CriteriaKey.
- Parameters:
key_type (CriteriaKey) – The relevant Criteria Key.
- Return type:
CriteriaKeyResult|set[Any]- Returns:
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)
Returns subset of passed qubits that match the criteria.
- Parameters:
qubits (QubitSetInput) – A qubit or set of qubits that may match the criteria.
- Return type:
Union[Qubit,int,Iterable[Union[Qubit,int]]]- Returns:
QubitSetInput – The subset of passed qubits that match the criteria.
- to_dict()
Converts a dictionary representing an object of this class into an instance of this class.
- Return type:
dict- Returns:
dict – A dictionary representing the serialized version of this Criteria.
- class UnitaryGateCriteria(unitary, qubits=None)
Bases:
CircuitInstructionCriteriaThis class models noise Criteria based on unitary gates represented as a matrix.
- Parameters:
unitary (
Unitary)qubits (
Union[Qubit,int,Iterable[Union[Qubit,int]],None])
Creates unitary gate-based Criteria. See instruction_matches() for more details.
- Parameters:
unitary (Unitary) – A unitary gate matrix represented as a Braket Unitary.
qubits (QubitSetInput | None) – 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()
Returns keys based on criterion.
- Return type:
Iterable[CriteriaKey]- Returns:
Iterable[CriteriaKey] – This Criteria operates on unitary gates and Qubits.
- classmethod from_dict(criteria)
Deserializes a dictionary into a Criteria object.
- Parameters:
criteria (dict) – A dictionary representation of a UnitaryGateCriteria.
- Return type:
- Returns:
Criteria – A deserialized UnitaryGateCriteria represented by the passed in serialized data.
- get_keys(key_type)
Gets the keys for a given CriteriaKey.
- Parameters:
key_type (CriteriaKey) – The relevant Criteria Key.
- Return type:
CriteriaKeyResult|set[Any]- Returns:
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)
Returns true if an Instruction matches the criteria.
- Parameters:
instruction (Instruction) – An Instruction to match.
- Return type:
bool- 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()
Converts a dictionary representing an object of this class into an instance of this class.
- Return type:
dict- Returns:
dict – A dictionary representing the serialized version of this Criteria.