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

98 lines
4.5 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
description: API reference for qiskit.circuit.InstructionSet
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/0.20/qiskit/circuit/instructionset.py" signature="InstructionSet(circuit_cregs=None, *, resource_requester=None)" modifiers="class">
Bases: `object`
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**
* **circuit\_cregs** (*list\[*[*ClassicalRegister*](qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister")*]*)
Optional. List of cregs of the circuit to which the instruction is added. Default: None.
<Admonition title="Deprecated since version qiskit-terra" type="danger">
0.19 The classical registers are insufficient to access all classical resources in a circuit, as there may be loose classical bits as well. It can also cause integer indices to be resolved incorrectly if any registers overlap. Instead, pass a complete requester to the `resource_requester` argument.
</Admonition>
* **resource\_requester** (`Optional`\[`Callable`])
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`](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`](qiskit.circuit.Clbit "qiskit.circuit.Clbit") and [`ClassicalRegister`](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>
**Raises**
**CircuitError** if both `resource_requester` and `circuit_cregs` are passed. Only one of these may be passed, and it should be `resource_requester`.
## Methods
### add
<Function id="qiskit.circuit.InstructionSet.add" signature="InstructionSet.add(gate, qargs, cargs)">
Add an instruction and its context (where it is attached).
</Function>
### c\_if
<Function id="qiskit.circuit.InstructionSet.c_if" signature="InstructionSet.c_if(classical, val)">
Set a classical equality condition on all the instructions in this set between the [`ClassicalRegister`](qiskit.circuit.ClassicalRegister "qiskit.circuit.ClassicalRegister") or [`Clbit`](qiskit.circuit.Clbit "qiskit.circuit.Clbit") `classical` and value `val`.
<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** (`Union`\[`Clbit`, `ClassicalRegister`, `int`]) the classical resource the equality condition should be on. If this is given as an integer, it will be resolved into a [`Clbit`](qiskit.circuit.Clbit "qiskit.circuit.Clbit") using the same conventions as the circuit these instructions are attached to.
* **val** (`int`) the value the classical resource should be equal to.
**Return type**
`InstructionSet`
**Returns**
This same instance of [`InstructionSet`](qiskit.circuit.InstructionSet "qiskit.circuit.InstructionSet"), but now mutated to have the given equality condition.
**Raises**
**CircuitError** if the passed classical resource is invalid, or otherwise not resolvable to a concrete resource that these instructions are permitted to access.
</Function>
### inverse
<Function id="qiskit.circuit.InstructionSet.inverse" signature="InstructionSet.inverse()">
Invert all instructions.
</Function>
## Attributes
### cargs
<Attribute id="qiskit.circuit.InstructionSet.cargs" />
### instructions
<Attribute id="qiskit.circuit.InstructionSet.instructions" />
### qargs
<Attribute id="qiskit.circuit.InstructionSet.qargs" />
</Class>