barriers are ignored in QuantumCircuit.depth()
See original GitHub issueThe depth method on QuantumCircuit ignores barriers:
from qiskit import QuantumCircuit
circ_serial = QuantumCircuit(4)
circ_serial.h(0)
circ_serial.cx(0, 1)
circ_serial.barrier()
circ_serial.h(2)
circ_serial.cx(2, 3)
print(circ_serial)
print('depth: ', circ_serial.depth())
circ_parallel = QuantumCircuit(4)
circ_parallel.h(0)
circ_parallel.cx(0, 1)
circ_parallel.h(2)
circ_parallel.cx(2, 3)
print(circ_parallel)
print('depth: ', circ_parallel.depth())
βββββ β
q_0: |0>β€ H ββββ βββββββββββββββ
ββββββββ΄ββ β
q_1: |0>ββββββ€ X ββββββββββββββ
βββββ β βββββ
q_2: |0>ββββββββββββββ€ H ββββ ββ
β ββββββββ΄ββ
q_3: |0>βββββββββββββββββββ€ X β
β βββββ
depth: 2
βββββ
q_0: |0>β€ H ββββ ββ
ββββββββ΄ββ
q_1: |0>ββββββ€ X β
ββββββββββ
q_2: |0>β€ H ββββ ββ
ββββββββ΄ββ
q_3: |0>ββββββ€ X β
βββββ
depth: 2
The depth method on DAGCircuit is correct however:
from qiskit.converters import circuit_to_dag
circuit_to_dag(circ_serial).depth()
5
Note: snapshot should also behave similarly to barrier and extend the depth.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
1. Quantum Circuits and Operations - Qiskit Pocket Guide [Book]
The barrier() method places a barrier on a circuit (shown in Figure 1-4), providing both visual and functional separation between gates on a...
Read more >qiskit.circuit.QuantumCircuit β Qiskit 0.24.1 documentation
Return circuit depth (i.e., length of critical path). This does not include compiler or simulator directives such as 'barrier' or 'snapshot'.
Read more >Circuit Construction β pytket-manual documentation
This DAG representation describes the abstract circuit ignoring these ... Adding a barrier to a Circuit is done using the Circuit.add_barrier() method.
Read more >What is a "barrier" in Qiskit circuits?
I just started studying IBM Qiskit, and cannot find details about the barrier method on the QuantumCircuit class. It is shown in the...
Read more >Open Quantum Assembly Language arXiv:1707.03429v2 ...
rience that enables experiments with small depth quantum circuits. ... computation is done between quantum circuit executions.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This was by design. Should a snapshot actually change the depth? I think not as it is not a physical operation. As for barrier. Otherwise depth losses it property of being a measure of circuit length and gauge of whether a circuit can actually run.
| I consider scheduling part of compilation.
Youβre right, corrected to transpiler directive.