Q-Bridge
Quantum Circuit Depth and Gate Count: How to Read Them
Gate count tells you how many operations a circuit has; depth tells you how many layers they stack into. Learn how to compute both from OpenQASM, why two-qubit gates matter most, and what Q-Bridge's analyzer does and does not report.
Two numbers that describe a circuit's size
When people talk about how big a quantum circuit is, they usually mean two different things. Gate count is how many operations the circuit contains. Depth is how many layers those operations stack into once you let independent gates happen at the same time.
The two can tell very different stories. A circuit that applies a Hadamard to each of many qubits has a gate count equal to the number of qubits, but a depth of one, because none of those gates share a qubit and all of them can happen in the same layer. A circuit that applies a chain of gates to a single qubit has a depth equal to its gate count, because each gate has to wait for the one before it.
Neither number is the size on its own. Read together, they tell you how much work the circuit asks for and how much of it has to happen in sequence.
How depth is counted
The usual way to compute depth from a gate list is to schedule every gate as early as it can go:
- Keep a layer counter for each qubit, starting at zero.
- Walk through the gates in order. For each gate, look at every qubit it touches and take the highest layer among them.
- Place the gate one layer above that, and move all of its qubits up to the new layer.
- When you reach the end, the highest layer on any qubit is the depth.
A two-qubit gate is what ties the qubits' timelines together. It cannot start until both of its qubits are free, so it pulls the less busy qubit forward to match the busier one. That is why a circuit with many two-qubit gates tends to have a depth that grows quickly even when each individual gate is simple.
A short worked example, in words. Take three qubits. Apply a Hadamard to the first, then a CNOT from the first to the second, then a CNOT from the second to the third. The Hadamard sits in the first layer. The first CNOT needs the first qubit, which is now busy until the end of layer one, so it goes in layer two. The second CNOT needs the second qubit, which is busy until the end of layer two, so it goes in layer three. Gate count three, depth three: every gate depends on the previous one. Now add a Hadamard on the third qubit at the very start. Gate count rises to four, but depth stays three, because that Hadamard fits into the first layer alongside the other one.
Why the two-qubit gates deserve the most attention
Not every gate costs the same. On current devices, two-qubit gates are generally slower and more error-prone than single-qubit gates, and they can only act directly on qubits that are physically connected. That makes three numbers worth looking at before anything else:
- Two-qubit gate count. A rough proxy for how much noise the circuit will accumulate on real hardware.
- Which qubit pairs interact. If your circuit links many different pairs, a device with limited connectivity may need extra operations to move information around, which adds both gates and depth.
- Depth. Qubits do not hold their state indefinitely, so a long sequence of dependent layers gives errors more time to build up.
None of these is a precise predictor. They are the quick reading that tells you whether a circuit is a sensible candidate for a device, or whether it is worth simplifying first.
Reading these numbers from OpenQASM text
OpenQASM is plain text, so you can get a first reading without running anything:
- Qubit count comes from the register declarations: `qreg q[n];` in version two, `qubit[n] q;` in version three.
- Gate count is roughly the number of gate statements, with one caveat: a gate applied to a whole register, such as `h q;`, is one gate per qubit in that register.
- Two-qubit gates are the statements with two qubit operands, such as `cx q[0], q[1];`.
- Measurements are written `measure q[0] -> c[0];` in version two and `c[0] = measure q[0];` in version three.
Two cautions apply to any count taken from the text. First, a custom `gate` definition hides its contents behind one name; counting the call as one operation understates what will eventually run. Second, the circuit you write is rarely the circuit that runs on hardware. Before execution it is typically rewritten into the device's native gate set and adapted to its connectivity, and both steps can change the gate count and depth. The numbers from your text describe your circuit as written, which is still the right place to start comparing versions of it.
The circuit analyzer in Q-Bridge
Q-Bridge is a web dashboard for writing OpenQASM circuits, running them and keeping the resulting jobs. Its circuit analyzer gives the reading described above without you counting by hand.
What it reports. Paste OpenQASM and it returns the gate count, depth, qubit count, a per-gate breakdown, the two-qubit gate count, the number of measurements, and which qubit pairs interact. It understands both register styles, `qreg` and `qubit[n]`, and both measurement syntaxes, so circuits written for either version of the language can be read.
How it computes depth. It schedules each operation as early as possible, the method described earlier, with a gate occupying one layer on every qubit it touches and a register-wide gate expanded to one gate per qubit. Measurements also occupy a layer on the qubits they read.
What it does not do. The analyzer is a deterministic text parse that runs in your browser, not a compiler pass. Specifically:
- A custom `gate` definition is counted as one operation; it is not expanded into the gates inside it.
- Classical control is ignored.
- It does not estimate execution time.
- It does not rewrite your circuit for any device, so the depth it reports is the depth of the text you pasted.
Those limits are the same cautions any text-based count carries. Within them, the analyzer is a quick way to compare two versions of a circuit: if you reduce the two-qubit gate count or the depth, you can see it straight away.
The analyzer sits inside the Q-Bridge dashboard, which requires an account. If you want to run the circuit after reading it, see running OpenQASM in the browser for the built-in simulator, and what shots are for how to read the counts that come back. Plan limits, including qubit limits, are on the pricing page, and you can create an account on the Free plan.
A habit worth building
Before running any circuit, read four numbers: qubit count, two-qubit gate count, the qubit pairs that interact, and depth. Then try one simplification, such as cancelling adjacent gates that undo each other or reordering independent gates, and read the numbers again. Over time this builds an instinct for which parts of a circuit are expensive, and it costs nothing, because none of it needs a run.
Create a Q-Bridge account, paste an OpenQASM circuit into the circuit analyzer, and compare its gate count, depth and two-qubit gate count before you run it.
Get started