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

Deprecate pulse parameter scoping #11691

Merged
merged 4 commits into from
Feb 1, 2024

Conversation

wshanks
Copy link
Contributor

@wshanks wshanks commented Jan 31, 2024

As noted in #11654, parameter scoping does not work properly beginning with Qiskit 0.45.0. The problem is that the Parameter name is now used for the hash value and so the parameter produced with the scoped name is not equivalent to the original parameter and does not substitute for it when using parameter assignment. Since the scoped parameter mechanism was a convenience feature and not widely used, it is simply deprecated rather than made to work with parameter assignment.

Related removal in #11692.

As noted in Qiskit#11654, parameter
scoping does not work properly beginning with Qiskit 0.45.0. The problem
is that the `Parameter` name is now used for the hash value and so the
parameter produced with the scoped name is not equivalent to the
original parameter and does not substitute for it when using parameter
assignment. Since the scoped parameter mechanism was a convenience
feature and not widely used, it is simply deprecated rather than made to
work with parameter assignment.
@wshanks wshanks requested review from eggerdj and a team as code owners January 31, 2024 17:46
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core
  • @nkanazawa1989

@wshanks
Copy link
Contributor Author

wshanks commented Jan 31, 2024

I think this might be well past the deadline for adding deprecations to 0.46? I hope it can still make it as an exception because it is a sort of bug fix as well. It adds a warning to a feature that already is not working correctly and which we plan to remove rather than fix.

nkanazawa1989
nkanazawa1989 previously approved these changes Jan 31, 2024
Copy link
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @wshanks for the quick update before the deadline.

@wshanks wshanks added Changelog: Deprecation Include in "Deprecated" section of changelog mod: pulse Related to the Pulse module labels Jan 31, 2024
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that this is way past the freeze deadline (and the removal one is similarly past the deadline for 1.0), but given that the deprecation and removal look to be fairly clean, and as you say, they're for features that don't really work correctly and are preventing an absolutely necessary bugfix (#11652), I'll accept them if you and Naoki are sure that these methods aren't used by any pulse code we're aware of.

edit: the point being that I'm not very aware of the pulse ecosystem and use, so I don't know how it's used.

Comment on lines 1987 to 1990
warnings.warn(
"Scoped parameters may not work correctly with parameter assignment.",
stacklevel=3,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip this - it's not really user actionable, and it's in a private function that's only used by deprecated functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used stacklevel 3 here as this private function is used by both public functions that return scoped parameters. Maybe it's better practice to put the warning in each public function directly. In any case, the plan is to remove the two public functions and this private function together as soon as permissible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does mean that the methods produce both a user warning and a deprecation warning, but it felt like squeezing too much in to add this text about the current behavior not working correctly into the deprecation warning .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the function is deprecated, I think it'd be better to move the warning message into the methods' docstring and not issue an actual warning which will trigger on every call. In the interests of moving forwards on release day, I'll just push that up and merge the PR.

@jakelishman
Copy link
Member

jakelishman commented Jan 31, 2024

I guess a better way of setting the acceptance criteria would be: was it possible to write a useful program using scoped parameters? Could a user have actually done meaningful things with them?

My approximate understanding is "no", because assignment wouldn't work due to hash-map lookups failing, and that's my reason for accepting the PR - if there are useful things that could have been done, I think it's a bit more questionable. The scope of the documentation change in #11692 makes me a bit more nervous.

@wshanks
Copy link
Contributor Author

wshanks commented Feb 1, 2024

You're right that this is way past the freeze deadline (and the removal one is similarly past the deadline for 1.0), but given that the deprecation and removal look to be fairly clean, and as you say, they're for features that don't really work correctly and are preventing an absolutely necessary bugfix (#11652), I'll accept them if you and Naoki are sure that these methods aren't used by any pulse code we're aware of.

Yes, I had hoped to come to a resolution in #11654 a little more quickly but even that was past the deadline. Personally, I don't have a pending feature relying on this removal or on #11652. My only goal was to keep known bugs out of new releases, but they aren't critical bugs -- they are in 0.45 and no one has complained -- so if we need to push them off to the next release that is okay. I was just giving best effort to get the fixes in.

I guess a better way of setting the acceptance criteria would be: was it possible to write a useful program using scoped parameters? Could a user have actually done meaningful things with them?

My approximate understanding is "no", because assignment wouldn't work due to hash-map lookups failing, and that's my reason for accepting the PR - if there are useful things that could have been done, I think it's a bit more questionable. The scope of the documentation change in #11692 makes me a bit more nervous.

Right, scoped parameters are mostly broken in 0.45, so I don't think anyone will be affected by their removal. @nkanazawa1989 and I don't know of anyone using them, and my GitHub-wide searches for usage didn't find anything. Nested/scoped pulse schedules in general are something we set up and planned to start using but so far hadn't gotten to using. The one thing that I do find the removed methods useful for is schedule introspection in the REPL (printing out where parameters are used). This usage is not affected by the assignment bug and is part of why I wondered about changing the methods to return dicts of {scope: Parameter} (breaking API change but still produces something readable in the REPL for seeing under what scopes the parameters are used). The ScheduleBlock docstring uses them in this way to print out the parameter scopes and that is why #11692 had to change the docstring so much.

It sounds like we are okay with merging all the PR's. If we had to we could just mark the test failures in #11652 as expected failures and push this PR to the next release. It would be nice to be able to remove the code in 1.0 though.

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks Will. I'm a shade nervous about this, but if it hadn't been close to the release deadline, I'd never even have looked at the pulse PR, so I'm fine just deferring to you and Naoki on it. I am glad to get the Parameter fixes unblocked.

@jakelishman jakelishman enabled auto-merge February 1, 2024 12:16
@jakelishman jakelishman added this pull request to the merge queue Feb 1, 2024
Merged via the queue into Qiskit:stable/0.46 with commit 6b914c7 Feb 1, 2024
11 checks passed
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants