2
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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)
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.