Suppose I have a QuantumCircuit
object named FC
, which explicitly contains the identity gate, and convert it into a gate using .to_instruction()
:
gate = FC.to_instruction()
and I use this to create a bigger QuantumCircuit
object named circuit
, which looks like this:
Now, when I iterate over the elements of the circuit
, using this code:
for instruction, qarg, carg in circuit:
print(instruction)
I get this:
Instruction(name='gate', num_qubits=3, num_clbits=0, params=[])
Instruction(name='gate', num_qubits=3, num_clbits=0, params=[])
However, gate
itself is made up of its constituent elements, which don't show up in the above list. How do I "collapse" the circuit, so that I can iterate over all the components present in circuit
, rather than just gate
? One way you can go about doing this is to transpile the circuit like this:
from qiskit import Aer, transpile
simulator = Aer.get_backend('aer_simulator')
circ = transpile(circ, simulator)
and iterate over circ
, but when I do that, the identity gate does not show up.