1
$\begingroup$

I have been working on Qiksit. Is it possible to display just the angle of each gate in a circuit as an output?

For example, if the below code is my circuit is it possible to just print the angle of the gate. We have function QuantumCircuit.count_ops() to display the gate counts similarly is there a way to do so?

q2 = QuantumRegister(2)
circuit = QuantumCircuit(q2)
circuit.cu1(math.pi/2, q2[0], q2[1])
print(circuit)
$\endgroup$
1
$\begingroup$

I don't think there's a built in function for this, but you can always hack a little to iterate over the gate list:

from qiskit import QuantumCircuit, QuantumRegister
import math
q2 = QuantumRegister(2)
circuit = QuantumCircuit(q2)
circuit.cu1(math.pi/2, q2[0], q2[1])
for gate, _, _ in circuit._data:
    print(gate.params[0])

However, instructions in Qiskit do not have a standardized interface, meaning not every gate will have params[0] set (e.g. x gate) or only one parameter (e.g. u3 gate). So it's really a question of which gates you are going to use in your circuit and knowing how their angles are represented in Qiskit (using gate.defintion might help).

| improve this answer | |
$\endgroup$
1
$\begingroup$

If you iterate over the circuit data as in Gadi A's answer, and use gate.qasm(), then you get the gate printed in concise format with all the relevant parameters.

for gate in circuit.data:
    print(gate[0].qasm())
| 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.