Add a new QuantumCircuit constructor QuantumCircuit.from_instructions
See original GitHub issueWhat should we add?
Creating a QuantumCircuit and appending operations into it is a very common pattern. It would be very convenient to be able to create a QuantumCircuit by directly passing an iterator of operations, something like:
@staticmethod
def from_ops(ops: Iterator[tuple[Instruction, Sequence[Qubit], Sequence[Clbit]]]) -> QuantumCircuit:
circuit = QuantumCircuit()
for op in ops:
circuit.append(*ops)
return circuit
Currently this is not possible as written but it would be if my proposal https://github.com/Qiskit/qiskit-terra/issues/8707 were implemented.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:11 (10 by maintainers)
Top Results From Across the Web
qiskit.circuit.QuantumCircuit
Create a new circuit. A circuit is a list of instructions bound to some registers. ... The registers to be included in the...
Read more >How to append an Instruction to a QuantumCircuit with ...
Basically, what I'm trying to do is the following: I have an Oracle Instruction which I want to append to my QuantumCircuit, ...
Read more >qiskit-terra/quantumcircuit.py at main - GitHub
"""Create a new circuit. A circuit is a list of instructions bound to some registers.
Read more >Introduction - Quantum Programming Studio
Name pyQuil Cirq Q# Qubits
id I I I 1
x X X X 1
y Y Y Y 1
Read more >Untitled circuit - IBM Quantum
... quantum circuits on quantum hardware or simulators. First time here? Build your first circuit. Get started. Been here before? See what's new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s important for it to be a sequence, because it defines the order that bits are applied to it when a circuit is used as an
Instruction
definition, for example - we associateCircuitInstruction.qubits
with theQuantumCircuit.qubits
by equal indices in the sequence. We do actually have the set view already, it’s just a private attribute - it’sQuantumCircuit._qubit_indices
, which is a dict. (I forgot about that when I was saying we’d need to track the set separately.)For a community member wanting to have a go at this, the rough interface would look like
CircuitInstruction
always contains onlyQubit
andClbit
instances, so we’d need to track the bits used in a set, and append them to the circuit before appending the instruction if they’re not already there. We’d also need to take care to ensure that any bits or registers that appear in thecondition
field of anInstruction
instance are added as well. For control-flow instructions, the method would need to inspect theblocks
field (which containsQuantumCircuit
instances, and ensure any registers in there are also in the top-level circuit.