-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deprecation warning of unscheduled circuits in timeline drawer #10851
Fix deprecation warning of unscheduled circuits in timeline drawer #10851
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 6207977535
💛 - Coveralls |
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`.
4eb84cb
to
b6049e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I just have a small question.
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, the use of stacklevel=3
is so that the warning points to timeline_drawer
, correct? Asking because most of our deprecation warnings are stacklevel=2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in this case it's a higher stack level because the function that triggers the warning is a "helper" function to the public API, so we need to unwind one extra stack frame before blaming it. The idea is that warnings.warn(stacklevel=n)
blames the code n
calls above warnings.warn
for being wrong. So stacklevel=1
(the default) blames the caller of warn
, and stacklevel=2
blames the caller of the caller of warn
. In public-library code, that's usually the API entry point, because it's usually entry points' jobs to normalise inputs and issue deprecation warnings. When we use a helper function to unify the warning logic, the stack level often rises to 3, because the entry point calls the helper, which calls warn
, and it was still the user's fault.
In this case, load_program
is kind of public API itself, but in practice the user entry point is almost invariable timeline.draw
. The worst that happens if the stack level is too high, though, is that some other code a level higher than the user's function (which is almost certainly still user code) gets blamed instead, so it should still show.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed explanation, LGTM!
Summary
The warning was previously emitted with a
stacklevel
that blamed the caller ofwarnings.warn
, which would not be shown to users with the default warning filters. This moves the stack level up to blame the caller oftimeline_drawer
.Details and comments
I updated some documentation still using the old paths here, but in looking at it, I'm not 100% sure that:
PadDynamicalDecoupling
also adds node start times to anything new it inserts in a way that the visualiser will understanddraw
wrapper in the (legacy)DynamicalDecoupling
pass is unnecessary.I'm not at all familiar with this code though, so I don't know what's best on it.