Skip to content
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

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

jakelishman
Copy link
Member

Summary

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.

Details and comments

I updated some documentation still using the old paths here, but in looking at it, I'm not 100% sure that:

  • the new PadDynamicalDecoupling also adds node start times to anything new it inserts in a way that the visualiser will understand
  • we shouldn't just make the old-style schedulers save this information as well so the ugly draw 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.

@jakelishman jakelishman added Changelog: Deprecation Include in "Deprecated" section of changelog mod: pulse Related to the Pulse module mod: visualization qiskit.visualization mod: transpiler Issues and PRs related to Transpiler labels Sep 16, 2023
@jakelishman jakelishman added this to the 0.45.0 milestone Sep 16, 2023
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

@coveralls
Copy link

coveralls commented Sep 16, 2023

Pull Request Test Coverage Report for Build 6207977535

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 11 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.001%) to 87.272%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 5 91.41%
crates/qasm2/src/parse.rs 6 97.6%
Totals Coverage Status
Change from base Build 6204306855: 0.001%
Covered Lines: 74195
Relevant Lines: 85016

💛 - 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`.
Copy link
Contributor

@ElePT ElePT left a 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,
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

@ElePT ElePT left a 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!

@ElePT ElePT added this pull request to the merge queue Oct 16, 2023
Merged via the queue into Qiskit:main with commit 3b97b37 Oct 16, 2023
13 checks passed
@jakelishman jakelishman deleted the fix-timeline-scheduling-deprecation branch October 16, 2023 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Deprecation Include in "Deprecated" section of changelog mod: pulse Related to the Pulse module mod: transpiler Issues and PRs related to Transpiler mod: visualization qiskit.visualization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants