1
$\begingroup$

I ran into a problem of how to extract circuit depth from Cirq circuit object. In Cirq circuits consist of a list of Moments. Number of moments is not equal to the circuit depth in general case. I might be missing something, but I looked into documentation and source code and still wasn't able to find it.

So, I am wondering if there is a simple way to extract circuit depth?

This is one of the main circuit properties, it is very strange why it is not implemented directly. For example in Qiskit there are methods qc.depth() and qc.count_ops().

Thanks!

$\endgroup$
3
$\begingroup$

On hardware, the number of moments is the relevant metric. That is why cirq focuses on that.

To compute circuit depth in cirq, create a new circuit using just the operations. It defaults to packing them as tightly as possible, so the number of moments will be the depth.

depth = len(cirq.Circuit(my_circuit.all_operations()))
$\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.