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 parameter handling for NLocal(..., flatten=True) and standard gates #13482

Merged
merged 4 commits into from
Nov 26, 2024

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Nov 22, 2024

Summary

Fixes #13478.

The fast-path for parameterizing standard gates caused an inconsistent state of the circuit, which is now fixed by using the explicit circuit._append_standard_gate method.

Details and comments

I'm not 100% sure what exactly the inconsistency was. Another way to fix this issue was to have the Rust-side assign_parameter_inner to explicitly re-assign the params attribute of the cached Python gate. So I'm assuming the old path didn't correctly register the gate in the cache, but I couldn't pin point the exact location in the code. If someone has more insight that would be great to know 🙂

@Cryoris Cryoris 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: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Nov 22, 2024
@Cryoris Cryoris requested a review from a team as a code owner November 22, 2024 18:09
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@coveralls
Copy link

coveralls commented Nov 22, 2024

Pull Request Test Coverage Report for Build 12034807511

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 7 of 7 (100.0%) changed or added relevant lines in 1 file are covered.
  • 13 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.002%) to 88.934%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/parse.rs 6 97.15%
crates/qasm2/src/lex.rs 7 91.48%
Totals Coverage Status
Change from base Build 11977726745: -0.002%
Covered Lines: 79403
Relevant Lines: 89283

💛 - Coveralls

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.

I don't think this actually fixes the issue. This is sidestepping the underlying bug by changing the construction of the n local circuit to not initially populate the py gate cache anymore. This means that the params in the cached python gate objects and the what's stored in circuit data/circuit instruction/packed instruction don't go out of sync because there isn't anything cached yet. If you updated the test to read every gate object from the circuit before assigning the params I think this would fail in the same way reported in the issue.

To fix this fully I'm pretty sure you need to update: https://github.com/Qiskit/qiskit/blob/main/crates/circuit/src/circuit_data.rs#L1382-L1389 to update the cached py gate, if the cache has been set.

@mtreinish mtreinish added this to the 1.3.0 milestone Nov 22, 2024
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.

LGTM now, this looks the correct fix, thanks for updating.

@mtreinish mtreinish added this pull request to the merge queue Nov 26, 2024
Merged via the queue into Qiskit:main with commit 4e5d9f8 Nov 26, 2024
17 checks passed
mergify bot pushed a commit that referenced this pull request Nov 26, 2024
…ates (#13482)

* Use _append_standard_gate directly

* update params on cache

* Revert "Use _append_standard_gate directly"

This reverts commit 9769785.

* Add test and reno

(cherry picked from commit 4e5d9f8)
github-merge-queue bot pushed a commit that referenced this pull request Nov 26, 2024
…ates (#13482) (#13495)

* Use _append_standard_gate directly

* update params on cache

* Revert "Use _append_standard_gate directly"

This reverts commit 9769785.

* Add test and reno

(cherry picked from commit 4e5d9f8)

Co-authored-by: Julien Gacon <[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: circuit Related to the core of the `QuantumCircuit` class or the circuit library 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.

Parameter assignment of QuantumCircuitdoes not update the data attribute when inplace=True
4 participants