qiskit.transpiler.Target.add_instruction¶
- Target.add_instruction(instruction, properties=None, name=None)[source]¶
Add a new instruction to the
Target
As
Target
objects are strictly additive this is the primary method for modifying aTarget
. Typically you will use this to fully populate aTarget
before 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
CXGate
to 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 theNone
value in the properties dictionary with anInstructionProperties
object. This pattern is repeated for eachInstruction
the target supports.- Parameters
instruction (qiskit.circuit.Instruction) – The operation object to add to the map. If it’s paramerterized any value of the parameter can be set. Optionally for variable width instructions (such as control flow operations such as
ForLoop
orMCXGate
) you can specify the class. If the class is specified than thename
argument 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
InstructionProperties
object for that instruction implementation on the backend. Properties are optional for any instruction implementation, if there are noInstructionProperties
available for the backend the value can be None. If there are no constraints on the instruction (as in a noisless/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 firstNone
indicates it applies to all qubits and the secondNone
indicates there are noInstructionProperties
for 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
name
attribute ofgate
will be used. All gates in theTarget
need unique names. Backends can differentiate between different parameterizations of a single gate by providing a unique name for each (e.g. “rx30”, “rx60”, `”rx90”`` similar to the example in the documentation for theTarget
class).
- Raises
AttributeError – If gate is already in map
TranspilerError – If an operation class is passed in for
instruction
and no name is specified orproperties
is set.