-
Notifications
You must be signed in to change notification settings - Fork 602
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 bug where unexpected queuing occurs in qml.ctrl
among other functions
#6284
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6284 +/- ##
=======================================
Coverage 99.70% 99.70%
=======================================
Files 444 444
Lines 42133 42151 +18
=======================================
+ Hits 42008 42026 +18
Misses 125 125 ☔ View full report in Codecov by Sentry. |
qml.ctrl
among other functionsqml.ctrl
among other functions
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.
qml.cond
also contains similar logic. Can you also update that to use this recursive method?
pennylane/ops/op_math/controlled.py
Outdated
@@ -199,11 +199,29 @@ def create_controlled_op(op, control, control_values=None, work_wires=None): | |||
return _ctrl_transform(op, control, control_values, work_wires) | |||
|
|||
|
|||
def remove_from_queue_args_and_kwargs(item): |
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.
Maybe move this helper method to the tape
module and just call it something like recursively_remove_operators_from_queue
.
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.
Sounds good, is okey in tape/operation_recorder.py
?
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.
Might be more suitable in pennylane/queueing.py
actually.
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.
We can use pytrees and simply do:
leaves, _ = qml.pytrees.flatten((args, kwargs), lambda obj: isinstance(obj, Operator))
_ = [qml.QueuingManager.remove(l) for l in leaves if isinstance(l, Operator)]
Given this is just two lines, I'd be worried that adding a public function adds more complexity and coupling that it solves. Duplicate code is not a bad thing when it helps keep modules simple and loosely coupled.
I'd prefer to just copy those two lines into adjoint
, controlled
, and TransformDispatcher._qfunc_transform
.
I tried this but it seems |
**Context:** The PennyLane CI suffers from sporadic failures due to stochasticity of test cases. In order to save CI runtime, we have seeded many tests. However, this approach introduces the risk of a test case passing due to a special seed, potentially hiding bugs that could have been discovered. Therefore, it is beneficial to periodically update the seeds to review such tests. **Description of the Change:** - The test suite uses `pytest-rng` to handle seed generation. A `seed` fixture is now available to use for every test case. If seeding is required, please use the seed provided by `pytest-rng` ```python def test_some_function(..., seed): dev = qml.device("default.qubit", seed=seed) ``` - A `local_salt` test marker has been added that allows you to modify the seed locally for a particular test case if the generated seed happens to make your test fail. ```python @pytest.mark.local_salt(42) def test_some_function(..., seed): dev = qml.device("default.qubit", seed=seed) ``` - All tests that uses local seeds has been updated to use the new seeding approach. - An `rng_salt` has been added to `pytest.ini`. This controls the seed generation for the entire test suite. We want to periodically change this `rng_salt` which updates all the seeds across the test suite. - The fixture that sets the global seed for every test case has been removed, and another fixture is added that restores the global seed after each test in case the test modifies the global seed. **Benefits:** We will be able to catch bugs hidden in tests that are passing only because of a magic seed that was set locally. **Possible Drawbacks:** This is a chore to maintain this seed an ensure that all tests pass with the new salt when it is updated. **Related Shortcut Story:** [sc-74294] --------- Co-authored-by: Mudit Pandey <[email protected]>
…nnylane into queueing_controls
…ions (#6474) This PR is a copy of this [other one](#6284) pointing to v0.39.0-rc0 [[sc-73690](https://app.shortcut.com/xanaduai/story/73690)] --------- Co-authored-by: Astral Cai <[email protected]>
The issue was that unwanted operators were being added when applying the
qml.ctrl
,qml.prod
,qml.cond
andqml.adjoint
functions if they were located as arguments or kwargs.To solve it I do a recursive search, for operators inside args and kwargs and I remove them.
Drawback:
This will delete it always. I can't think of a case where we want to add an operator to the queue by passing it as an argument.
Fixes #6267
[sc-73690]