# Depth Counter

The `Depth Counter`

is a part of the quantum computer Trace
Simulator.
It is used to gather counts of the depth of
every operation invoked in a quantum program. All operations from
`Microsoft.Quantum.Primitive`

are expressed in terms of single qubit rotations,
T gates, single qubit Clifford gates, CNOT gates and measurements of multi-qubit
Pauli observables. Users can set the depth for each of the primitive operations.

By default, all operations have depth 0 except the T gate which has depth 1. This means that by default, only the T depth of operations is computed (which is often desirable). Collected statistics are aggregated over all the edges of the operations call graph.

Let us now compute the `T`

depth
of the `CCNOT`

operation. We will use the following Q# driver code:

```
open Microsoft.Quantum.Primitive;
operation CCNOTDriver() : () {
body {
using( qubits = Qubit[3] ) {
CCNOT(qubits[0],qubits[1],qubits[2]);
T(qubits[0]);
}
}
}
```

## Using Depth Counter within a C# Program

To check that `CCNOT`

has `T`

depth 5 and `CCNOTDriver`

has `T`

depth 6
we can use the following C# code:

```
using Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators;
using System.Diagnostics;
var config = new QCTraceSimulatorConfiguration();
config.useDepthCounter = true;
var sim = new QCTraceSimulator(config);
var res = CCNOTDriver.Run(sim).Result;
double tDepth = sim.GetMetric<Primitive.CCNOT, CCNOTDriver>(DepthCounter.Metrics.Depth);
double tDepthAll = sim.GetMetric<CCNOTDriver>(DepthCounter.Metrics.Depth);
```

The first part of the program executes `CCNOTDriver`

. In the second part, we use the method
`QCTraceSimulator.GetMetric`

to get the `T`

depth of `CCNOT`

and `CCNOTDriver`

:

```
double tDepth = sim.GetMetric<Primitive.CCNOT, CCNOTDriver>(DepthCounter.Metrics.Depth);
double tDepthAll = sim.GetMetric<CCNOTDriver>(DepthCounter.Metrics.Depth);
```

Finally, to output all the statistics collected by `Depth Counter`

in CSV format we can
use the following:

```
string csvSummary = sim.ToCSV()[MetricCalculatorsNames.depthCounter];
```

## See also

- The quantum computer Trace Simulator overview.