Skip to main content

Module depth

Module depth 

Source
Expand description

Circuit depth calculation via a per-wire ASAP longest-path DP.

Every instruction node contributes one layer on the qubits it touches; barriers synchronize their listed qubits (an empty list is a global barrier over all circuit qubits). With recurse = true, structured control flow is unfolded into an estimated depth: if/switch take the max branch, while counts the body once, for with a statically-known unsigned constant range is fully unrolled (else counted once). CircuitGate is opaque (depth 1).

The algorithm runs in O(n) without constructing a graph: it keeps a per-qubit frontier depth and, for each operation in program order, advances every synchronized wire to base + local_depth.