AnyonTarget#
- class qiskit_calculquebec.backends.targets.anyon_target.AnyonTarget(description: str | None = None, num_qubits: int | None = 0, dt: float | None = None, granularity: int = 1, min_length: int = 1, pulse_alignment: int = 1, acquire_alignment: int = 1, qubit_properties: list | None = None, concurrent_measurements: list | None = None, **_subclass_kwargs)#
Bases:
Target,ABCAbstract base class describing a quantum hardware target for Anyon devices.
This class extends
qiskit.transpiler.Targetand provides a common interface for defining the characteristics of Anyon-based quantum devices, such as Yukon or MonarQ.The target defines:
The physical qubits available on the device
The device coupling map
The supported gate set
Gate durations and error rates
Measurement operations
Hardware calibration data (gate errors, measurement errors, and coherence times) are optionally retrieved through
qiskit_calculquebec.API.adapter.ApiAdapter.Subclasses must implement methods describing the hardware topology.
- Note:
This class is abstract and cannot be instantiated directly. Concrete subclasses must implement:
coupling_map()qubits()device_name()
- Example:
Example of a concrete device target:
class Yukon(AnyonTarget): def coupling_map(self): return [(0, 1), (1, 0), (1, 2), (2, 1)] def qubits(self): return list(range(6)) def device_name(self): return "Yukon"
- <<<<<<< HEAD
…
Initialize the hardware target.
This constructor:
Initializes the Qiskit
TargetLoads qubit properties
Defines the default gate set
Registers supported instructions with their associated duration and error rates
Attributes
Return dt.
Get the list of tuples (
Instruction, (qargs)) for the targetGet the operation names in the target.
Get the operation objects in the target.
Returns a sorted list of physical qubits.
The set of qargs in the target.
- acquire_alignment#
- concurrent_measurements#
- description#
- dt#
Return dt.
- granularity#
- instructions#
Get the list of tuples (
Instruction, (qargs)) for the targetFor globally defined variable width operations the tuple will be of the form
(class, None)where class is the actual operation class that is globally defined.
- min_length#
- num_qubits#
- operation_names#
Get the operation names in the target.
- operations#
Get the operation objects in the target.
- physical_qubits#
Returns a sorted list of physical qubits.
- pulse_alignment#
- qargs#
The set of qargs in the target.
- qubit_properties#
Methods
add_instruction(instruction[, properties, ...])Add a new instruction to the
Targetbuild_coupling_map([two_q_gate, ...])Get a
CouplingMapfrom this target.Return the device coupling map.
Return the name of the quantum device.
Get an InstructionDurations object from the target
from_configuration(basis_gates[, ...])Create a target object from the individual global configuration
gate_has_angle_bounds(name)Check if a specific gate gate has an angle bound set
get(key[, default])Gets an item from the Target.
Return the non-global operation names for the target
Check if there are any angle bounds set in the target
instruction_properties(index)Get the instruction properties for a specific instruction tuple
instruction_supported([operation_name, ...])Return whether the instruction (operation + qubits) is supported by the target
items()Returns pairs of Gate names and its property map (str, dict[tuple, InstructionProperties])
keys()Return the keys (operation_names) of the Target
operation_from_name(instruction)Get the operation class object for a given name
operation_names_for_qargs(qargs, /)Get the operation names for a specified qargs tuple
operations_for_qargs(qargs, /)Get the operation class object for a specified qargs tuple
qargs_for_operation_name(operation)Get the qargs for a given operation name
qubits()Return the list of physical qubits available on the device.
seconds_to_dt(duration)Convert a given duration in seconds to units of dt
supported_angle_bound(name, angles)Check that parameters on a specific gate conform to the angle bounds
Get an
TimingConstraintsobject from the targetupdate_instruction_properties(instruction, ...)Update the property object for an instruction qarg pair already in the Target.
values()Return the Property Map (qargs -> InstructionProperties) of every instruction in the Target
- add_instruction(instruction, properties=None, name=None, *, angle_bounds=None)#
Add a new instruction to the
TargetAs
Targetobjects are strictly additive this is the primary method for modifying aTarget. Typically, you will use this to fully populate aTargetbefore using it inBackendV2. For example:from qiskit.circuit.library import CXGate from qiskit.transpiler import Target, InstructionProperties target = Target() cx_properties = { (0, 1): None, (1, 0): None, (0, 2): None, (2, 0): None, (0, 3): None, (2, 3): None, (3, 0): None, (3, 2): None } target.add_instruction(CXGate(), cx_properties)
Will add a
CXGateto the target with no properties (duration, error, etc) with the coupling edge list:(0, 1), (1, 0), (0, 2), (2, 0), (0, 3), (2, 3), (3, 0), (3, 2). If there are properties available for the instruction you can replace theNonevalue in the properties dictionary with anInstructionPropertiesobject. This pattern is repeated for eachInstructionthe target supports.- Parameters:
instruction (Union[qiskit.circuit.Instruction, Type[qiskit.circuit.Instruction]]) – The operation object to add to the map. If it’s parameterized any value of the parameter can be set. Optionally for variable width instructions (such as control flow operations such as
ForLooporMCXGate) you can specify the class. If the class is specified then thenameargument must be specified. When a class is used the gate is treated as global and not having any properties set.properties (dict) – A dictionary of qarg entries to an
InstructionPropertiesobject for that instruction implementation on the backend. Properties are optional for any instruction implementation, if there are noInstructionPropertiesavailable for the backend the value can be None. If there are no constraints on the instruction (as in a noiseless/ideal simulation) this can be set to{None, None}which will indicate it runs on all qubits (or all available permutations of qubits for multi-qubit gates). The firstNoneindicates it applies to all qubits and the secondNoneindicates there are noInstructionPropertiesfor the instruction. By default, if properties is not set it is equivalent to passing{None: None}.name (str) – An optional name to use for identifying the instruction. If not specified the
nameattribute ofgatewill be used. All gates in theTargetneed unique names. Backends can differentiate between different parameterization of a single gate by providing a unique name for each (e.g. “rx30”, “rx60”, `”rx90”`` similar to the example in the documentation for theTargetclass).angle_bounds (list) – The bounds on the parameters for a given gate. This is specified by a list of tuples (low, high) which represent the low and high bound (inclusively) on what float values are allowed for the parameter in that position. If a parameter doesn’t have an angle bound you can use
Noneto represent that. For example if a 3 parameter gate only had a bound on the second parameter you would represent that with:[None, [0, 3.14], None]which means the first and third parameter allow any value but the second parameter only accepts values between 0 and 3.14.
- Raises:
AttributeError – If gate is already in map
TranspilerError – If an operation class is passed in for
instructionand no name is specified orpropertiesis set.
- build_coupling_map(two_q_gate=None, filter_idle_qubits=False)#
Get a
CouplingMapfrom this target.If there is a mix of two qubit operations that have a connectivity constraint and those that are globally defined this will also return
Nonebecause the global connectivity means there is no constraint on the target. If you wish to see the constraints of the two qubit operations that have constraints you should use thetwo_q_gateargument to limit the output to the gates which have a constraint.- Parameters:
two_q_gate (str) – An optional gate name for a two qubit gate in the
Targetto generate the coupling map for. If specified the output coupling map will only have edges between qubits where this gate is present.filter_idle_qubits (bool) – If set to
Truethe outputCouplingMapwill remove any qubits that don’t have any operations defined in the target. Note that using this argument will result in an outputCouplingMapobject which has holes in its indices which might differ from the assumptions of the class. The typical use case of this argument is to be paired withCouplingMap.connected_components()which will handle the holes as expected.
- Returns:
- The
CouplingMapobject for this target. If there are no connectivity constraints in the target this will return
None.
- The
- Return type:
CouplingMap
- Raises:
ValueError – If a non-two qubit gate is passed in for
two_q_gate.IndexError – If an Instruction not in the
Targetis passed in fortwo_q_gate.
- abstractmethod coupling_map()#
Return the device coupling map.
The coupling map defines the connectivity between physical qubits.
- Returns:
List of directed qubit connections.
- Return type:
list[tuple[int, int]]
- abstractmethod device_name()#
Return the name of the quantum device.
- Returns:
Device name used to retrieve calibration data.
- Return type:
str
- durations()#
Get an InstructionDurations object from the target
- Returns:
- The instruction duration represented in the
target
- Return type:
InstructionDurations
- classmethod from_configuration(basis_gates: list[str], num_qubits: int | None = None, coupling_map: CouplingMap | None = None, instruction_durations: InstructionDurations | None = None, concurrent_measurements: list[list[int]] | None = None, dt: float | None = None, timing_constraints: TimingConstraints | None = None, custom_name_mapping: dict[str, Any] | None = None) Target#
Create a target object from the individual global configuration
Prior to the creation of the
Targetclass, the constraints of a backend were represented by a collection of different objects which combined represent a subset of the information contained in theTarget. This function provides a simple interface to convert those separate objects to aTarget.This constructor will use the input from
basis_gates,num_qubits, andcoupling_mapto build a base model of the backend and theinstruction_durations,backend_properties, andinst_mapinputs are then queried (in that order) based on that model to look up the properties of each instruction and qubit. If there is an inconsistency between the inputs any extra or conflicting information present ininstruction_durations,backend_properties, orinst_mapwill be ignored.- Parameters:
basis_gates – The list of basis gate names for the backend. For the target to be created these names must either be in the output from
get_standard_gate_name_mapping()or present in the specifiedcustom_name_mappingargument.num_qubits – The number of qubits supported on the backend.
coupling_map – The coupling map representing connectivity constraints on the backend. If specified all gates from
basis_gateswill be supported on all qubits (or pairs of qubits).instruction_durations – Optional instruction durations for instructions. If specified it will take priority for setting the
durationfield in theInstructionPropertiesobjects for the instructions in the target.concurrent_measurements (list) – A list of sets of qubits that must be measured together. This must be provided as a nested list like
[[0, 1], [2, 3, 4]].dt – The system time resolution of input signals in seconds
timing_constraints – Optional timing constraints to include in the
Targetcustom_name_mapping – An optional dictionary that maps custom gate/operation names in
basis_gatesto anOperationobject representing that gate/operation. By default, most standard gates names are mapped to the standard gate object fromqiskit.circuit.librarythis only needs to be specified if the inputbasis_gatesdefines gates in names outside that set.
- Returns:
the target built from the input configuration
- Return type:
Target
- Raises:
TranspilerError – If the input basis gates contain > 2 qubits and
coupling_mapisspecified. –
KeyError – If no mapping is available for a specified
basis_gate.
- gate_has_angle_bounds(name)#
Check if a specific gate gate has an angle bound set
- Parameters:
name (str) – The instruction name to check if it has an angle bound set
- Returns:
This will return
Trueif the gate is in the target and has angle bounds defined. It will returnFalseif the gate does not have angle bounds defined or is not in the target.- Return type:
bool
- get(key, default=None)#
Gets an item from the Target. If not found return a provided default or None.
- get_non_global_operation_names(strict_direction=False)#
Return the non-global operation names for the target
The non-global operations are those in the target which don’t apply on all qubits (for single qubit operations) or all multi-qubit qargs (for multi-qubit operations).
- Parameters:
strict_direction (bool) – If set to
Truethe multi-qubit operations considered as non-global respect the strict direction (or order of qubits in the qargs is significant). For example, ifcxis defined on(0, 1)andecris defined over(1, 0)by default neither would be considered non-global, but ifstrict_directionis setTruebothcxandecrwould be returned.- Returns:
A list of operation names for operations that aren’t global in this target
- Return type:
List[str]
- has_angle_bounds()#
Check if there are any angle bounds set in the target
- Returns:
This will return
Trueif there are angle bounds set on any instructions in the circuit- Return type:
bool
- instruction_properties(index)#
Get the instruction properties for a specific instruction tuple
This method is to be used in conjunction with the
instructionsattribute of aTargetobject. You can use this method to quickly get the instruction properties for an element ofinstructionsby using the index in that list. However, if you’re not working withinstructionsdirectly it is likely more efficient to access the target directly via the name and qubits to get the instruction properties. For example, ifinstructionsreturned:[(XGate(), (0,)), (XGate(), (1,))]
you could get the properties of the
XGateon qubit 1 with:props = target.instruction_properties(1)
but just accessing it directly via the name would be more efficient:
props = target['x'][(1,)]
(assuming the
XGate’s canonical name in the target is'x') This is especially true for larger targets as this will scale worse with the number of instruction tuples in a target.- Parameters:
index (int) – The index of the instruction tuple from the
instructionsattribute. For, example if you want the properties from the third element ininstructionsyou would set this to be2.- Returns:
The instruction properties for the specified instruction tuple
- Return type:
InstructionProperties
- instruction_supported(operation_name=None, qargs=Ellipsis, operation_class=None, parameters=None, check_angle_bounds=True)#
Return whether the instruction (operation + qubits) is supported by the target
- Parameters:
operation_name (str) – The name of the operation for the instruction. Either this or
operation_classmust be specified, if both are specifiedoperation_classwill take priority and this argument will be ignored.qargs (tuple) – The tuple of qubit indices for the instruction. If this is not specified then this method will return
Trueif the specified operation is supported on any qubits. The typical application will always have this set (otherwise it’s the same as just checking if the target contains the operation). Normally you would not set this argument if you wanted to check more generally that the target supports an operation with theparameterson any qubits.operation_class (Type[qiskit.circuit.Instruction]) – The operation class to check whether the target supports a particular operation by class rather than by name. This lookup is more expensive as it needs to iterate over all operations in the target instead of just a single lookup. If this is specified it will supersede the
operation_nameargument. The typical use case for this operation is to check whether a specific variant of an operation is supported on the backend. For example, if you wanted to check whether aRXGatewas supported on a specific qubit with a fixed angle. That fixed angle variant will typically have a name different from the object’snameattribute ("rx") in the target. This can be used to check if any instances of the class are available in such a case.parameters (list) –
A list of parameters to check if the target supports them on the specified qubits. If the instruction supports the parameter values specified in the list on the operation and qargs specified this will return
Truebut if the parameters are not supported on the specified instruction it will returnFalse. If this argument is not specified this method will returnTrueif the instruction is supported independent of the instruction parameters. If specified with anyParameterobjects in the list, that entry will be treated as supporting any value, however parameter names will not be checked (for example if an operation in the target is listed as parameterized with"theta"and"phi"is passed into this function that will returnTrue). For example, if called with:parameters = [Parameter("theta")] target.instruction_supported("rx", (0,), parameters=parameters)
will return
Trueif anRXGateis supported on qubit 0 that will accept any parameter. If you need to check for a fixed numeric value parameter this argument is typically paired with theoperation_classargument. For example:target.instruction_supported("rx", (0,), RXGate, parameters=[pi / 4])
will return
Trueif an RXGate(pi/4) exists on qubit 0.check_angle_bounds (bool) – If set to True (the default) the value of
parameterswill be validated against any angle bounds set in the target. If any of the values inparametersare set to beParameterExpressioninstances this flag will have no effect as angle bounds only impact non-parameterized operations in the circuit.
- Returns:
Returns
Trueif the instruction is supported andFalseif it isn’t.- Return type:
bool
- items()#
Returns pairs of Gate names and its property map (str, dict[tuple, InstructionProperties])
- keys()#
Return the keys (operation_names) of the Target
- operation_from_name(instruction)#
Get the operation class object for a given name
- Parameters:
instruction (str) – The instruction name to get the
Instructioninstance for- Returns:
The Instruction instance corresponding to the name. This also can also be the class for globally defined variable with operations.
- Return type:
qiskit.circuit.Instruction
- operation_names_for_qargs(qargs, /)#
Get the operation names for a specified qargs tuple
- Parameters:
qargs (tuple) – A
qargstuple of the qubits to get the gates that apply to it. For example,(0,)will return the set of all instructions that apply to qubit 0. If set toNonethis will return the names for any globally defined operations in the target.- Returns:
The set of operation names that apply to the specified
qargs.- Return type:
set
- Raises:
KeyError – If
qargsis not in target
- operations_for_qargs(qargs, /)#
Get the operation class object for a specified qargs tuple
- Parameters:
qargs (tuple) – A qargs tuple of the qubits to get the gates that apply to it. For example,
(0,)will return the set of all instructions that apply to qubit 0. If set toNonethis will return any globally defined operations in the target.- Returns:
The list of
Instructioninstances that apply to the specified qarg. This may also be a class if a variable width operation is globally defined.- Return type:
list
- Raises:
KeyError – If qargs is not in target
- qargs_for_operation_name(operation)#
Get the qargs for a given operation name
- Parameters:
operation (str) – The operation name to get qargs for
- Returns:
The set of qargs the gate instance applies to.
- Return type:
set
- abstractmethod qubits()#
Return the list of physical qubits available on the device.
- Returns:
Indices of physical qubits.
- Return type:
list[int]
- seconds_to_dt(duration: float) int#
Convert a given duration in seconds to units of dt
- Parameters:
duration – The duration in seconds, such as in an
InstructionPropertiesfield for an instruction in the target.
- Returns
duration: The duration in units of dt
- supported_angle_bound(name, angles)#
Check that parameters on a specific gate conform to the angle bounds
- Parameters:
name (str) – The instruction name to check the angle bounds of
angles (list) – A list of float parameter values for
nameto see if they conform to the defined angle bounds.
- Returns:
Returns
Trueif the parameter values specified are compatible with the angle bounds.Falseis returned if the any of the parameters are outside the defined bounds.- Return type:
bool
- Raises:
TranspilerError – If
nameis not in the target or does nothave angle bounds defined. –
- timing_constraints()#
Get an
TimingConstraintsobject from the target- Returns:
The timing constraints represented in the
Target- Return type:
TimingConstraints
- update_instruction_properties(instruction, qargs, properties)#
Update the property object for an instruction qarg pair already in the Target.
For ease of access, a user is able to obtain the mapping between an instruction’s applicable qargs and its instruction properties via the mapping protocol (using
__getitem__), with the instruction’s name as the key. This method is the only way to modify/update the properties of an instruction in theTarget. Usage of the mapping protocol for modifications is not supported.- Parameters:
instruction (str) – The instruction name to update
qargs (tuple) – The qargs to update the properties of
properties (InstructionProperties) – The properties to set for this instruction
- Raises:
KeyError – If
instructionorqargare not in the target
- values()#
Return the Property Map (qargs -> InstructionProperties) of every instruction in the Target