MCPcopy
hub / github.com/Qiskit/qiskit / append

Method append

qiskit/circuit/quantumcircuit.py:2832–2943  ·  view source on GitHub ↗

Append one or more instructions to the end of the circuit, modifying the circuit in place. The ``qargs`` and ``cargs`` will be expanded and broadcast according to the rules of the given :class:`~.circuit.Instruction`, and any non-:class:`.Bit` specifiers (such as int

(
        self,
        instruction: Operation | CircuitInstruction,
        qargs: Sequence[QubitSpecifier] | None = None,
        cargs: Sequence[ClbitSpecifier] | None = None,
        *,
        copy: bool = True,
    )

Source from the content-addressed store, hash-verified

2830 return instructions
2831
2832 def append(
2833 self,
2834 instruction: Operation | CircuitInstruction,
2835 qargs: Sequence[QubitSpecifier] | None = None,
2836 cargs: Sequence[ClbitSpecifier] | None = None,
2837 *,
2838 copy: bool = True,
2839 ) -> InstructionSet:
2840 """Append one or more instructions to the end of the circuit, modifying the circuit in
2841 place.
2842
2843 The ``qargs`` and ``cargs`` will be expanded and broadcast according to the rules of the
2844 given :class:`~.circuit.Instruction`, and any non-:class:`.Bit` specifiers (such as
2845 integer indices) will be resolved into the relevant instances.
2846
2847 If a :class:`.CircuitInstruction` is given, it will be unwrapped, verified in the context of
2848 this circuit, and a new object will be appended to the circuit. In this case, you may not
2849 pass ``qargs`` or ``cargs`` separately.
2850
2851 Args:
2852 instruction: :class:`~.circuit.Instruction` instance to append, or a
2853 :class:`.CircuitInstruction` with all its context. Objects implementing
2854 ``to_instruction`` are also supported, but passing an
2855 :class:`~.circuit.Instruction` directly is generally preferred, since that
2856 avoids the repeated conversion cost.
2857 qargs: specifiers of the :class:`~.circuit.Qubit`\\ s to attach instruction to.
2858 cargs: specifiers of the :class:`.Clbit`\\ s to attach instruction to.
2859 copy: if ``True`` (the default), then the incoming ``instruction`` is copied before
2860 adding it to the circuit if it contains symbolic parameters, so it can be safely
2861 mutated without affecting other circuits the same instruction might be in. If you
2862 are sure this instruction will not be in other circuits, you can set this ``False``
2863 for a small speedup.
2864
2865 Returns:
2866 qiskit.circuit.InstructionSet: a handle to the :class:`.CircuitInstruction`\\ s that
2867 were actually added to the circuit.
2868
2869 Raises:
2870 CircuitError: if the operation passed is not an instance of :class:`~.circuit.Instruction`,
2871 or cannot be converted to one by calling ``to_instruction`` on it.
2872 """
2873 if isinstance(instruction, CircuitInstruction):
2874 operation = instruction.operation
2875 qargs = instruction.qubits
2876 cargs = instruction.clbits
2877 else:
2878 operation = instruction
2879
2880 # Convert input to instruction
2881 if not isinstance(operation, Operation):
2882 if hasattr(operation, "to_instruction"):
2883 operation = operation.to_instruction()
2884 if not isinstance(operation, Operation):
2885 raise CircuitError("operation.to_instruction() is not an Operation.")
2886 else:
2887 if issubclass(operation, Operation):
2888 raise CircuitError(
2889 "Object is a subclass of Operation, please add () to "

Callers 15

_get_dd_sequenceMethod · 0.95
runMethod · 0.95
_apply_annotationsMethod · 0.95
_conjugate_reduce_opMethod · 0.95
swap_decomposeMethod · 0.95
from_bytecodeFunction · 0.95
_mcsu2_real_diagonalFunction · 0.95
synth_clifford_layersFunction · 0.95
adder_ripple_c04Function · 0.95
adder_ripple_v95Function · 0.95
adder_qft_d00Function · 0.95

Calls 14

_current_scopeMethod · 0.95
has_identifierMethod · 0.95
_check_dupsMethod · 0.95
_add_refMethod · 0.95
CircuitErrorClass · 0.90
_validate_exprFunction · 0.85
InstructionSetClass · 0.85
CircuitInstructionClass · 0.85
iter_capturesMethod · 0.80
to_instructionMethod · 0.45