|q⟩ Bad Qubits

advanced · Programming · Advanced Circuit Construction & Transpilation

Optimizing Circuit Depth

On near-term hardware, qubits decohere. Every layer of gates the circuit must execute is more time during which the fragile quantum state decays, so circuit depth — the number of sequential gate layers on the critical path — is a first-order determinant of how reliable a result will be. Reducing depth is therefore one of the most valuable optimizations a transpiler performs.

Depth versus gate count

Gate count and depth are different metrics. Count is how many gates there are in total; depth is the length of the longest chain of gates that must run one after another. Gates acting on disjoint qubits run in the same layer, so a wide circuit can have low depth despite a high count:

depth=length of the critical path in the gate dependency graph.\text{depth} = \text{length of the critical path in the gate dependency graph}.

Two gates can share a layer exactly when they touch no common qubit. The optimizer models the circuit as a directed acyclic graph of gate dependencies and asks for the minimum number of layers — a graph-scheduling problem.

Two levers for depth

Parallelization (scheduling). Pack independent gates into the same time step. A column of single-qubit gates on different qubits is depth 1, not depth nn. Greedy "as-soon-as-possible" scheduling slides each gate to the earliest layer where its qubits are free.

Cancellation and merging. Removing redundant gates shortens the critical path directly. If a chain contains XX=IX X = I, deleting the pair removes two layers of depth; merging a run of zz-rotations into one removes the rest. Depth reduction and gate-count reduction reinforce each other here.

Why equivalence still rules

As with every optimization, reducing depth must not change the unitary. Deleting an XXXX pair is safe because it equals the identity; reordering two gates is safe only if they commute. The grader compares full unitaries precisely so that a shallower circuit is accepted only when it computes the same operation.

Try it

The given circuit applies XX twice in a row before the CNOT — a redundant pair that inflates depth from 2 to 4. Produce the depth-optimized equivalent. The grader checks the full two-qubit unitary, so any circuit equal to H0H_0 followed by CX(0,1)\mathrm{CX}(0,1) passes.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.