1
$\begingroup$

I wanted to calculate the count of each gate used in the specific quantum circuit. For example in the below circuit, the result should be something like:

{'rz': 1, 'h': 4, 'cx': 3, 'measure': 4}

I saw a similar question asked, but it counts all the gates only in the longest path of the dag circuit which it creates using circuit_to_dag.

enter image description here

$\endgroup$

2 Answers 2

1
$\begingroup$

You can use QuantumCircuit's count_ops() method:

print(dict(circ.count_ops()))
$\endgroup$
1
$\begingroup$

I think you are looking for the QuantumCircuit.count_ops() method. The documentation for it can be found here: https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.count_ops.html#qiskit.circuit.QuantumCircuit.count_ops it returns a dictionary of the number of each particular operation in the circuit.

$\endgroup$
1
  • $\begingroup$ Thank you. It worked. $\endgroup$ Apr 13 at 5:52

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.