Skip to content

Commit

Permalink
Fix deprecation warning of unscheduled circuits in timeline drawer (#…
Browse files Browse the repository at this point in the history
…10851)

The warning was previously emitted with a `stacklevel` that blamed the
caller of `warnings.warn`, which would not be shown to users with the
default warning filters.  This moves the stack level up to blame the
caller of `timeline_drawer`.
  • Loading branch information
jakelishman authored Oct 16, 2023
1 parent fc74ab9 commit 3b97b37
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
18 changes: 16 additions & 2 deletions qiskit/transpiler/passes/scheduling/dynamical_decoupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ class DynamicalDecoupling(TransformationPass):
from qiskit.transpiler import PassManager, InstructionDurations
from qiskit.transpiler.passes import ALAPSchedule, DynamicalDecoupling
from qiskit.visualization import timeline_drawer
# Because the legacy passes do not propagate the scheduling information correctly, it is
# necessary to run a no-op "re-schedule" before the output circuits can be drawn.
def draw(circuit):
from qiskit import transpile
scheduled = transpile(
circuit,
optimization_level=0,
instruction_durations=InstructionDurations(),
scheduling_method="alap",
)
return timeline_drawer(scheduled)
circ = QuantumCircuit(4)
circ.h(0)
circ.cx(0, 1)
Expand All @@ -69,7 +83,7 @@ class DynamicalDecoupling(TransformationPass):
pm = PassManager([ALAPSchedule(durations),
DynamicalDecoupling(durations, dd_sequence)])
circ_dd = pm.run(circ)
timeline_drawer(circ_dd)
draw(circ_dd)
# Uhrig sequence on qubit 0
n = 8
Expand All @@ -87,7 +101,7 @@ def uhrig_pulse_location(k):
]
)
circ_dd = pm.run(circ)
timeline_drawer(circ_dd)
draw(circ_dd)
"""

@deprecate_func(
Expand Down
1 change: 1 addition & 0 deletions qiskit/visualization/timeline/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def load_program(self, program: circuit.QuantumCircuit):
"This circuit should be transpiled with scheduler though it consists of "
"instructions with explicit durations.",
DeprecationWarning,
stacklevel=3,
)

try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
deprecations:
- |
Passing a circuit to :func:`qiskit.visualization.timeline_drawer` that does not have scheduled
node start-time information is deprecated. Only circuits that have gone through one of the
scheduling analysis passes (for example :class:`.ALAPScheduleAnalysis` or
:class:`.ASAPScheduleAnalysis`) can be visualised. If you have used one of the old-style
scheduling passes (for example :class:`.ALAPSchedule` or :class:`.ASAPSchedule`), you can
propagate the scheduling information by running::
from qiskit import transpile
from qiskit.transpiler import InstructionDurations
scheduled = transpile(
my_old_style_circuit,
optimization_level=0,
scheduling_method="alap",
instruction_durations=InstructionDurations(),
)
This behaviour was previously intended to be deprecated in Qiskit 0.37, but due to a bug in the
warning, it was not displayed to users until now. The behaviour will be removed in Qiskit 1.0.

0 comments on commit 3b97b37

Please sign in to comment.