Target¶
- class Target(description=None, num_qubits=0, dt=None, granularity=1, min_length=1, pulse_alignment=1, acquire_alignment=1, qubit_properties=None)[código fonte]¶
Bases:
Mapping
The intent of the
Target
object is to inform Qiskit’s compiler about the constraints of a particular backend so the compiler can compile an input circuit to something that works and is optimized for a device. It currently contains a description of instructions on a backend and their properties as well as some timing information. However, this exact interface may evolve over time as the needs of the compiler change. These changes will be done in a backwards compatible and controlled manner when they are made (either through versioning, subclassing, or mixins) to add on to the set of information exposed by a target.As a basic example, let’s assume backend has two qubits, supports
UGate
on both qubits andCXGate
in both directions. To model this you would create the target like:from qiskit.transpiler import Target, InstructionProperties from qiskit.circuit.library import UGate, CXGate from qiskit.circuit import Parameter gmap = Target() theta = Parameter('theta') phi = Parameter('phi') lam = Parameter('lambda') u_props = { (0,): InstructionProperties(duration=5.23e-8, error=0.00038115), (1,): InstructionProperties(duration=4.52e-8, error=0.00032115), } gmap.add_instruction(UGate(theta, phi, lam), u_props) cx_props = { (0,1): InstructionProperties(duration=5.23e-7, error=0.00098115), (1,0): InstructionProperties(duration=4.52e-7, error=0.00132115), } gmap.add_instruction(CXGate(), cx_props)
Each instruction in the Target is indexed by a unique string name that uniquely identifies that instance of an
Instruction
object in the Target. There is a 1:1 mapping between a name and anInstruction
instance in the target and each name must be unique. By default the name is thename
attribute of the instruction, but can be set to anything. This lets a single target have multiple instances of the same instruction class with different parameters. For example, if a backend target has two instances of anRXGate
one is parameterized over any theta while the other is tuned up for a theta of pi/6 you can add these by doing something like:import math from qiskit.transpiler import Target, InstructionProperties from qiskit.circuit.library import RXGate from qiskit.circuit import Parameter target = Target() theta = Parameter('theta') rx_props = { (0,): InstructionProperties(duration=5.23e-8, error=0.00038115), } target.add_instruction(RXGate(theta), rx_props) rx_30_props = { (0,): InstructionProperties(duration=1.74e-6, error=.00012) } target.add_instruction(RXGate(math.pi / 6), rx_30_props, name='rx_30')
Then in the
target
object accessing byrx_30
will get the fixed angleRXGate
whilerx
will get the parameterizedRXGate
.Nota
This class assumes that qubit indices start at 0 and are a contiguous set if you want a submapping the bits will need to be reindexed in a new``Target`` object.
Nota
This class only supports additions of gates, qargs, and qubits. If you need to remove one of these the best option is to iterate over an existing object and create a new subset (or use one of the methods to do this). The object internally caches different views and these would potentially be invalidated by removals.
Create a new Target object
Obsoleto desde a versão 0.23.0:
qiskit.transpiler.target.Target.__init__()
”s argumentaquire_alignment
is deprecated as of qiskit-terra 0.23.0. It will be removed no earlier than 3 months after the release date. Instead, use the argumentacquire_alignment
, which behaves identically.- Parâmetros
description (str) – An optional string to describe the Target.
num_qubits (int) – An optional int to specify the number of qubits the backend target has. If not set it will be implicitly set based on the qargs when
add_instruction()
is called. Note this must be set if the backend target is for a noiseless simulator that doesn’t have constraints on the instructions so the transpiler knows how many qubits are available.dt (float) – The system time resolution of input signals in seconds
granularity (int) – An integer value representing minimum pulse gate resolution in units of
dt
. A user-defined pulse gate should have duration of a multiple of this granularity value.min_length (int) – An integer value representing minimum pulse gate length in units of
dt
. A user-defined pulse gate should be longer than this length.pulse_alignment (int) – An integer value representing a time resolution of gate instruction starting time. Gate instruction should start at time which is a multiple of the alignment value.
acquire_alignment (int) – An integer value representing a time resolution of measure instruction starting time. Measure instruction should start at time which is a multiple of the alignment value.
qubit_properties (list) – A list of
QubitProperties
objects defining the characteristics of each qubit on the target device. If specified the length of this list must match the number of qubits in the target, where the index in the list matches the qubit number the properties are defined for. If some qubits don’t have properties available you can set that entry toNone
- Levanta
ValueError – If both
num_qubits
andqubit_properties
are bothdefined and the value of num_qubits differs from the length of –
qubit_properties` –
Methods
Add a new instruction to the
Target
Get a
CouplingMap
from this target.Get an InstructionDurations object from the target
Create a target object from the individual global configuration
Get calibrated pulse schedule for the instruction.
Return the non-global operation names for the target
Return whether the instruction (operation + qubits) defines a calibration.
Get the instruction properties for a specific instruction tuple
Return an
InstructionScheduleMap
for the instructions in the target with a pulse schedule defined.Return whether the instruction (operation + qubits) is supported by the target
Get the operation class object for a given name
Get the operation names for a specified qargs tuple
Get the operation class object for a specified qargs tuple
Get the qargs for a given operation name
Get an
TimingConstraints
object from the targetUpdate the target from an instruction schedule map.
Update the property object for an instruction qarg pair already in the Target
Attributes
- num_qubits¶
- description¶
- dt¶
- granularity¶
- min_length¶
- pulse_alignment¶
- acquire_alignment¶
- qubit_properties¶
- aquire_alignment¶
Alias of deprecated name. This will be removed.
Obsoleto desde a versão 0.24.0: The property
qiskit.transpiler.target.Target.aquire_alignment
is deprecated as of qiskit-terra 0.24.0. It will be removed no earlier than 3 months after the release date. Use the propertyacquire_alignment
instead.
- instructions¶
Get the list of tuples
(:class:`~qiskit.circuit.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.
- operation_names¶
Get the operation names in the target.
- operations¶
Get the operation class objects in the target.
- physical_qubits¶
Returns a sorted list of physical_qubits
- qargs¶
The set of qargs in the target.