qiskit-documentation/docs/api/qiskit/1.2/qiskit.circuit.InstructionS...

100 lines
5.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: InstructionSet (v1.2)
description: API reference for qiskit.circuit.InstructionSet in qiskit v1.2
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.circuit.InstructionSet
---
# InstructionSet
<Class id="qiskit.circuit.InstructionSet" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/instructionset.py#L28-L177" signature="qiskit.circuit.InstructionSet(*, resource_requester=None)" modifiers="class">
Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)")
Instruction collection, and their contexts.
New collection of instructions.
The context (`qargs` and `cargs` that each instruction is attached to) is also stored separately for each instruction.
**Parameters**
**resource\_requester** (*Callable\[...,* [*ClassicalRegister*](circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") *|*[*Clbit*](circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit")*] | None*)
A callable that takes in the classical resource used in the condition, verifies that it is present in the attached circuit, resolves any indices into concrete [`Clbit`](circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit") instances, and returns the concrete resource. If this is not given, specifying a condition with an index is forbidden, and all concrete [`Clbit`](circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit") and [`ClassicalRegister`](circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") resources will be assumed to be valid.
<Admonition title="Note" type="note">
The callback `resource_requester` is called once for each call to [`c_if()`](#qiskit.circuit.InstructionSet.c_if "qiskit.circuit.InstructionSet.c_if"), and assumes that a call implies that the resource will now be used. It may throw an error if the resource is not valid for usage.
</Admonition>
## Attributes
### cargs
<Attribute id="qiskit.circuit.InstructionSet.cargs">
Legacy getter for the cargs components of an instruction set. This does not support mutation.
</Attribute>
### instructions
<Attribute id="qiskit.circuit.InstructionSet.instructions">
Legacy getter for the instruction components of an instruction set. This does not support mutation.
</Attribute>
### qargs
<Attribute id="qiskit.circuit.InstructionSet.qargs">
Legacy getter for the qargs components of an instruction set. This does not support mutation.
</Attribute>
## Methods
### add
<Function id="qiskit.circuit.InstructionSet.add" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/instructionset.py#L74-L82" signature="add(instruction, qargs=None, cargs=None)">
Add an instruction and its context (where it is attached).
</Function>
### c\_if
<Function id="qiskit.circuit.InstructionSet.c_if" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/instructionset.py#L108-L153" signature="c_if(classical, val)">
Set a classical equality condition on all the instructions in this set between the [`ClassicalRegister`](circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") or [`Clbit`](circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit") `classical` and value `val`.
<Admonition title="Note" type="note">
You should prefer to use the [`QuantumCircuit.if_test()`](qiskit.circuit.QuantumCircuit#if_test "qiskit.circuit.QuantumCircuit.if_test") builder interface, rather than using this method.
</Admonition>
<Admonition title="Note" type="note">
This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition on any of the contained instructions; it does not stack.
</Admonition>
**Parameters**
* **classical** ([*Clbit*](circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit") *|*[*ClassicalRegister*](circuit#qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") *|*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) the classical resource the equality condition should be on. If this is given as an integer, it will be resolved into a [`Clbit`](circuit#qiskit.circuit.Clbit "qiskit.circuit.Clbit") using the same conventions as the circuit these instructions are attached to.
* **val** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) the value the classical resource should be equal to.
**Returns**
This same instance of [`InstructionSet`](#qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet"), but now mutated to have the given equality condition.
**Raises**
[**CircuitError**](circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") if the passed classical resource is invalid, or otherwise not resolvable to a concrete resource that these instructions are permitted to access.
**Return type**
[InstructionSet](#qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet")
</Function>
### inverse
<Function id="qiskit.circuit.InstructionSet.inverse" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/instructionset.py#L89-L106" signature="inverse(annotated=False)">
Invert all instructions.
<Admonition title="Note" type="note">
It is preferable to take the inverse *before* appending the gate(s) to the circuit.
</Admonition>
</Function>
</Class>