4
$\begingroup$

I'm using Qiskit to create quantum circuits wherein I've this attribute called depth. The documentation states it is the length of the critical path here. What does it represent and how to find it out manually?

$\endgroup$
9
$\begingroup$

The depth of a circuit is the longest path in the circuit. The path length is always an integer number, represents the number of gates it has to execute in that path.

For example, the following circuit has depth 3:

enter image description here

since if you look at the second qubit, there are 3 gates acting upon it. First by the CNOT gate, then by the RZ gate, then by another CNOT gate.


Another circuit would have depth 3 could be the following circuit:

enter image description here

However, the above circuit would have depth of $1$ after optimization. This is because CNOT follows by another CNOT is the same as doing nothing. That is, CNOT $\cdot$ CNOT $\cdot$ CNOT = CNOT. So you don't really need to do an additional two CNOTs.


Another example, consider this other circuit which has depth = 5 (Can you now see why this circuit has depth of 5? ):

enter image description here

But let's say you want to run it on a quantum computer, and you choose to run it on one of the IBM machine, in particular ibmq_ourense which has the following qubit layout:

enter image description here

Because not all the qubits are connected and not all the gates we've defined in our above circuit are actually native gates of ibmq_ourense, your circuit need to be transpiled to be run on the real hardware. Fortunately, this can be done automatically with Qiskit. And it is a feature that I believe they are still working to improve upon. So when you submit your depth 5 circuit to be run on the hardware, Qiskit will transpiled your circuit to the following circuit:

enter image description here

This circuit has depth 29, instead of depth 5 like the circuit we originally defined.


The point I wanted to make is the depth of your circuit might change under optimization and transpilation process so make sure you keep this in mind.


There is actually an option within Qiskit to let you check the depth of your circuit. This can be very useful. Here is an example of how you can do that:

provider = IBMQ.load_account()
qc = QuantumCircuit(1,1)
qc.x(0)
qc.y(0)
qc.rz(1,0)
print(qc)
print("The circuit depth is:", qc.depth())
qc_transpiled = transpile(qc, provider.get_backend('ibmq_ourense') , optimization_level=3)
print("The TRANSPILED circuit depth is:", qc_transpiled.depth())

I see that there is another similar question here: How to calculate circuit depth properly? There couple really good answers there as well. So hope this help!

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

See the "Quantum Circuit Properties" here:

https://qiskit.org/documentation/apidoc/circuit.html

for an explanation.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review $\endgroup$ – Mark S Nov 1 at 15:02
  • $\begingroup$ Or just leave a comment. $\endgroup$ – user1271772 Nov 17 at 0:06

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.