Is there a way in Qiskit to take a circuit object and return a list of tuples where each tuple consists of a gate and the qubit(s) they act on? The list obeys some partial order since the gate order cannot be swapped unless they commute.
1 Answer
$\begingroup$
$\endgroup$
You can inspect the QuantumCircuit.data structure:
https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.html
For example, here is a loop that prints the name, qubits and any other parameters for all the gates in a circuit.
for gate in qc.data:
print('\ngate name:', gate[0].name)
print('qubit(s) acted on:', gate[1])
print('other paramters (such as angles):', gate[0].params)