# The result of qiskit calculating T-depth and its calculation method

I have encountered doubts when using qiskit to calculate T-depth. I am not sure whether it is a problem with the way the code is written, or I am still a little vague about T-depth, so I would like to ask everyone for advice.

I use this code to get T_depth containing T and T*

T_depth= ​​circ.depth(lambda gate: gate[0].name in ['t', 'tdg'])

The following is an example of a circuit that I have doubts about: Original circuit: Circuit after automatic arrangement:

So far, I can understand why it is arranged like this, but I don’t understand why the T-depth result shows not 7, but 4?

Looking at the code that implements the .depth() method for a QuantumCircuit, it seems that when using a lambda function, a gate will not be counted as part of a separate layer if that gate can be executed in parallel in any possible way with other gates from list provided, even if that gate could in principle be executed before the others.

Here's what I mean. Even though in your circuit the first $$T^{\dagger}$$ gate on $$q_2$$ can be executed one layer before the next $$T$$ gate (which occurs on $$q_0$$), you could "slide" the $$T^{\dagger}$$ gate to the right so that the two of them get executed simultaneously. Same with the first $$T^{\dagger}$$ on $$q_0$$, you can "slide" it to the right and execute it in parallel with the second $$T^{\dagger}$$ on $$q_2$$.

In other words, the function will find the minimum possible depth to execute the gates passed to the lambda function.

One thing to keep in mind is that this might not be the way things get executed in hardware, so it will be up to you to add barriers wherever are needed if you wanted for those gates to be executed in parallel.

• Thank you very much. I have been observing the results for a long time, and it seems that the lower depth is indeed found by sliding.
– Dona
Commented Jun 3 at 3:30

In the first figure you added barriers which prevents a transpiler from circuit optimization. This means that T-depth can be higher than in case of the circuit without barriers.

On first qubit you have $$T$$ gate and its inversion next to each other. So, these two gates are replaced with identity operator leading to another decrease in T-depth.

Thinking further, two gates $$T^\dagger$$ on last qubit can be replaced with $$S^\dagger$$ as $$S=T^2$$.

Overall, T-depth of the circuit is four: one gate on first qubit, one gate on second qubit and two gates on last qubit

• Originally, I thought this was the case too, but that is not how the .depth() function in Qiskit counts gates. Unless you transpile the circuit, the simplifications you are referring to will not be taken into consideration to calculate the number of layers for a given type of gate. Commented May 30 at 12:09