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?
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:
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:
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? ):
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:
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:
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!
See the "Quantum Circuit Properties" here:
for an explanation.