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 pickling of conditioned custom gates from OpenQASM 2 import #11175

Merged

Conversation

jakelishman
Copy link
Member

Summary

The condition of a gate defined by a gate statement in an OpenQASM 2 program was not previously exported as part of its state during pickling, causing pickle roundtrips or deepcopies to lose the condition on the new copy.

Details and comments

Fix #11174.

The condition of a gate defined by a `gate` statement in an OpenQASM 2
program was not previously exported as part of its state during
pickling, causing pickle roundtrips or deepcopies to lose the condition
on the new copy.
@jakelishman jakelishman added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qasm2 Relating to OpenQASM 2 import or export labels Nov 2, 2023
@jakelishman jakelishman added this to the 0.45.1 milestone Nov 2, 2023
@jakelishman jakelishman requested a review from a team as a code owner November 2, 2023 14:19
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link

Pull Request Test Coverage Report for Build 6733858362

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • 11 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.007%) to 86.889%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
crates/qasm2/src/lex.rs 4 91.92%
crates/qasm2/src/parse.rs 6 97.6%
Totals Coverage Status
Change from base Build 6731270262: 0.007%
Covered Lines: 74033
Relevant Lines: 85204

💛 - Coveralls

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.

I am not an expert on OpenQASM but the fix looks reasonably simple and the test covers all the potential pain points described in #11174 (deep-copying and pickling), so LGTM. Out of curiosity, are there ways to define conditional custom gates without a gate statement? asking because of the way the reno is phrased.

@jakelishman
Copy link
Member Author

Out of curiosity, are there ways to define conditional custom gates without a gate statement?

No, the OQ2 language doesn't support that - the phrasing in the release note is supposed to imply

Previously, any conditional custom gate (i.e. those defined by a gate statement in an OpenQASM 2 file) would lose its condition when copied or pickled.

and not

Previously, any conditional custom gate (e.g. those defined by a gate statement in an OpenQASM 2 file) would lose its condition when copied or pickled.

I can change it if you prefer to be clearer.

@ElePT
Copy link
Contributor

ElePT commented Nov 16, 2023

I think that is ok, it's probably clear to the target audience of the reno and I was just lacking background knowledge.

@ElePT ElePT added this pull request to the merge queue Nov 16, 2023
Merged via the queue into Qiskit:main with commit 196221f Nov 16, 2023
14 checks passed
@jakelishman jakelishman deleted the qasm2/fix-deepcopy-custom-conditional branch November 16, 2023 14:21
mergify bot pushed a commit that referenced this pull request Nov 16, 2023
The condition of a gate defined by a `gate` statement in an OpenQASM 2
program was not previously exported as part of its state during
pickling, causing pickle roundtrips or deepcopies to lose the condition
on the new copy.

(cherry picked from commit 196221f)
github-merge-queue bot pushed a commit that referenced this pull request Nov 16, 2023
…) (#11258)

The condition of a gate defined by a `gate` statement in an OpenQASM 2
program was not previously exported as part of its state during
pickling, causing pickle roundtrips or deepcopies to lose the condition
on the new copy.

(cherry picked from commit 196221f)

Co-authored-by: Jake Lishman <[email protected]>
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 mod: qasm2 Relating to OpenQASM 2 import or export 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.

Incorrectly removing necessary classical conditions
4 participants