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

Avoid deepcopy in pulse parser #9063

Merged
merged 2 commits into from
Nov 3, 2022

Conversation

jakelishman
Copy link
Member

Summary

This deepcopy is not strictly necessary; since we already own the nodes we're modifying, we only need to shallow copy nodes that we want to replace. In practice, the deep copy seems to cause difficult-to-resolve reference cycles within Jupyter that can get the parser.

Details and comments

Fix #8783.

I was never able to use any of the cells given in that issue to reliably reproduce the issue, but I did seem to hit a similar issue when trying to transpile for an internal backend. This just ensures that all nodes that need to be mutated during the expression visit are only shallow copied, avoiding the deep-copy problem. I don't understand why that caused particular issues, though.

@nkanazawa1989: perhaps you can check me here, but I believe this should be fine and safe.

This deepcopy is not strictly necessary; since we already own the nodes
we're modifying, we only need to shallow copy nodes that we want to
replace.  In practice, the deep copy seems to cause difficult-to-resolve
reference cycles within Jupyter that can get the parser.
@jakelishman jakelishman added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Nov 2, 2022
@jakelishman jakelishman requested review from a team, eggerdj and wshanks as code owners November 2, 2022 20:20
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, but I'm going to hold off on tagging this as automerge until @nkanazawa1989 can take a look because he's the most familiar with this code.

@mtreinish mtreinish added this to the 0.22.2 milestone Nov 2, 2022
@coveralls
Copy link

coveralls commented Nov 2, 2022

Pull Request Test Coverage Report for Build 3384677280

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 115 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.2%) to 84.359%

Files with Coverage Reduction New Missed Lines %
src/optimize_1q_gates.rs 1 95.16%
qiskit/extensions/quantum_initializer/squ.py 2 79.78%
qiskit/pulse/library/waveform.py 3 91.49%
src/sampled_exp_val.rs 14 63.93%
src/results/marginalization.rs 36 67.82%
src/sabre_swap/mod.rs 59 80.94%
Totals Coverage Status
Change from base Build 3381988739: -0.2%
Covered Lines: 62255
Relevant Lines: 73798

💛 - Coveralls

@nkanazawa1989
Copy link
Contributor

nkanazawa1989 commented Nov 3, 2022

I wrote this almost 3 years ago but I don't quite remember why I needed the deep copy of the AST node here. This copy occurs to support parameter partial binding, so I believe this change should be okey as long as unittest for partial bindings works normally. Probably we can remove copy as well. Anyways partial binding will never occur in the current use case, and indeed this parser is sort of overengineering. Please go ahead with merging.

@jakelishman jakelishman added stable backport potential The bug might be minimal and/or import enough to be port to stable automerge labels Nov 3, 2022
@mergify mergify bot merged commit 45f7836 into Qiskit:main Nov 3, 2022
mergify bot pushed a commit that referenced this pull request Nov 3, 2022
This deepcopy is not strictly necessary; since we already own the nodes
we're modifying, we only need to shallow copy nodes that we want to
replace.  In practice, the deep copy seems to cause difficult-to-resolve
reference cycles within Jupyter that can get the parser.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 45f7836)
mergify bot added a commit that referenced this pull request Nov 3, 2022
This deepcopy is not strictly necessary; since we already own the nodes
we're modifying, we only need to shallow copy nodes that we want to
replace.  In practice, the deep copy seems to cause difficult-to-resolve
reference cycles within Jupyter that can get the parser.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 45f7836)

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
@jakelishman jakelishman deleted the remove-pulse-deepcopy branch November 14, 2022 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

transpilation-related commands take extremely long time in Jupyter notebook
5 participants