question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

barriers are ignored in QuantumCircuit.depth()

See original GitHub issue

The 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:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
nonhermitiancommented, Jul 6, 2019

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.

0reactions
taalexandercommented, Jul 8, 2019

| I consider scheduling part of compilation.

You’re right, corrected to transpiler directive.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found