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 a Target. Typically you will use this to fully populate a Target before using it in BackendV2. 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 the None value in the properties dictionary with an InstructionProperties object. This pattern is repeated for each Instruction the target supports.

  • 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 or MCXGate) you can specify the class. If the class is specified than the name 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 no InstructionProperties 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 first None indicates it applies to all qubits and the second None indicates there are no InstructionProperties 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 of gate will be used. All gates in the Target 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 the Target class).

  • AttributeError – If gate is already in map

  • TranspilerError – If an operation class is passed in for instruction and no name is specified or properties is set.