A quantum compiler can reduce the number of two-qubit operations in a circuit or reduce the number of sequential layers. Both improvements can matter on hardware. They need not lead to the same implementation.

The choice is particularly interesting on processors with sparse connectivity. A logical operation between distant qubits may require additional operations to move quantum information. The compiler must decide where to place the logical qubits, how to route their interactions and how to express those interactions using the processor's native gates.

Two measures of circuit cost

Two-qubit gate count measures the number of operations acting on two qubits, including operations such as SWAP that are not entangling on their own. Two-qubit depth measures the number of sequential layers of those operations, when gates acting on disjoint qubits can be placed in the same layer. A circuit's physical duration is a separate measure, determined by the actual operations, their durations, dependencies and the scheduling rules of the device.

Illustration. Consider two hypothetical implementations of the same operation. One uses six two-qubit gates arranged in six layers. Another uses eight two-qubit gates arranged in four layers. The first uses fewer operations; the second has less two-qubit depth.

Which implementation is preferable depends on the experiment. Gate errors may make the smaller count attractive. If the additional operations are comparatively reliable and parallel execution reduces idle time, the shorter implementation may be more useful. A real comparison also depends on qubit placement and the reliability of individual couplers.

Counting operations and layers

The following small Python function measures two-qubit depth for a schedule of ordered pairs. It retains the order of operations involving the same qubit and assigns each operation to its earliest available layer. It assumes the listed operations are the only dependencies.

def two_qubit_depth(pairs):
    last = {}
    for a, b in pairs:
        layer = max(last.get(a, 0), last.get(b, 0)) + 1
        last[a] = last[b] = layer
    return max(last.values(), default=0)

serial = [(0, 1), (1, 2), (2, 3)]
parallel = [(0, 1), (2, 3), (1, 2)]
print(len(serial), two_qubit_depth(serial))
print(len(parallel), two_qubit_depth(parallel))

Both lists contain the same number of operations. The first has depth three, the second depth two. The lists illustrate a metric, not equivalent quantum circuits: changing the order of quantum gates can change the computation. For a compiled circuit, count and depth must be measured without altering its semantics. Single-qubit operations and measurement can also introduce dependencies omitted by the example.

Comparing compilation objectives

A useful experiment begins with a fixed input circuit and a fixed hardware target. Compile for gate count and for depth, retain the resulting circuits, and measure both objectives for every result. Keep the native gate set, connectivity, approximation policy and computational budget constant. If a compiler uses randomized search, record the seeds and summarize the distribution across runs.

Before comparing hardware performance, check the resulting circuits against the input, including the qubit mapping and any declared approximation. Two-qubit depth is a helpful proxy for duration, but a device schedule and calibration give a more direct account of the physical implementation.

A scatter plot with gate count on one axis and depth on the other can be more informative than a single ranking. An implementation dominated on both axes offers little reason for selection on those measures alone. Others occupy different points on the trade-off between them.

Applying this in a quantum experiment

The 4colors Quantum Compiler searches hardware-specific implementations. Its objective option sets what the search minimizes first: the fewest two-qubit gates (the default, then the smallest depth) or the smallest depth. The useful question is which objective reflects the resources that matter for your computation. For repeated execution of a circuit, even a modest change in its implementation can accumulate across evaluations.

Explore the 4colors Quantum Compiler.

Related reading: What better quantum compilation buys you.