# Quantum trace simulator: depth counter

The depth counter is a part of the Quantum Development Kit Quantum trace simulator. You can use it to gather counts that represent the lower bound of the depth of every operation invoked in a quantum program.

## Depth values

By default, all operations have a depth of 0 except the T operation, which has a depth of 1. This means that by default, only the T depth of operations is computed (which is often desirable). The depth counter aggregates and collects statistics over all the edges of the operation's call graph.

All Microsoft.Quantum.Intrinsic namespace operations are expressed in terms of single-qubit rotations, T operation operations, single-qubit Clifford operations, CNOT operation operations, and measurements of multi-qubit Pauli observables. Users can set the depth for each of the primitive operations via the gateTimes field of QCTraceSimulatorConfiguration.

## Invoking the depth counter

To run the quantum trace simulator with the depth counter, you must create a QCTraceSimulatorConfiguration instance, set its UseDepthCounter property to true, and then create a new QCTraceSimulator instance with QCTraceSimulatorConfiguration as the parameter.

var config = new QCTraceSimulatorConfiguration();
config.UseDepthCounter = true;
var sim = new QCTraceSimulator(config);


## Using the depth counter in a C# host program

The C# example that follows in this section computes the T depth of the CCNOT operation, based on the following Q# sample code:

open Microsoft.Quantum.Intrinsic;

operation ApplySampleWithCCNOT() : Unit {
use qubits = Qubit[3]);
CCNOT(qubits[0], qubits[1], qubits[2]);
T(qubits[0]);
}


To check that CCNOT has T depth 5 and ApplySampleWithCCNOT has T depth 6, 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 = ApplySampleWithCCNOT.Run(sim).Result;

double tDepth = sim.GetMetric<Intrinsic.CCNOT, ApplySampleWithCCNOT>(DepthCounter.Metrics.Depth);
double tDepthAll = sim.GetMetric<ApplySampleWithCCNOT>(DepthCounter.Metrics.Depth);


The first part of the program runs ApplySampleWithCCNOT. The second part uses the GetMetric method to retrieve the T depth of CCNOT and ApplySampleWithCCNOT.

Finally, you can output all the statistics collected by the depth counter in CSV format using the following:

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