-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Discard cache for standard gates in assign_parameters
#13557
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 12285836607Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @raynelfss, this seems to work nicely.
I left just one comment and will merge once addressed.
crates/circuit/src/circuit_data.rs
Outdated
// Standard gates can all rebuild their definitions, so if the | ||
// cached py_op exists, update the `params` attribute and clear out | ||
// any existing cache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update this comment and perhaps add a GitHub link to the relevant issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
Fix incorrect behavior in :class:`.CircuitData` in which, upon parameter assignment, | ||
we attempted to modify the cached operation inside of a ``PackedInstruction``. Now | ||
we instead discard said cache prompting the ``PackedInstruction`` to build a new Python | ||
operation should it be needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to link the issue here, but let's do that in #13556.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this is how the original fix looked like 🙂 It seems that Kevin's comments is also addressed and I double checked that this fixed the original bug reported in #13504.
* Fix: Discard cache when assigning new parameters in `CircuitData`. * Docs: Add release note * Test: Add test case * Docs: Add relevant comment (cherry picked from commit 17a2ccc)
) * Fix: Discard cache when assigning new parameters in `CircuitData`. * Docs: Add release note * Test: Add test case * Docs: Add relevant comment (cherry picked from commit 17a2ccc) Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>
Summary
This is an initial fix to #13504, and should precede #13543.
The following commits discard the cached gate when assigning parameters for a standard gate rather than trying to modify the Python object.
Details and comments
A more in-depth fix is present in #13543, but since it is such a big change, we've decided to include this smaller fix to allow more time to re-evaluate our approach.
When retrieving a
PackedInstruction
from theEquivalenceLibrary
during thecompose_transforms
phase of theBasisTranslator
the parameter modifications done in other places are not reflected on the cached gate, therefore leading to issues when runningQISKIT_PARALLEL=TRUE
due to a modified object reference when callingCircuitData::assign_parameters()
.In the case of a standard gate, we were not removing the old cache but instead modifying it in place (which would not result in the expected outcome), while for other gate instances, we rebuild the non-cached item. Now we instead discard the cache in the
StandardGate
case too, getting rid of the stale shared reference.