4
$\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$

1 Answer 1

5
$\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)
$\endgroup$

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .