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

Allow tuple-valued control_values with qml.ctrl on a Controlled instance. #5725

Merged
merged 8 commits into from
May 24, 2024

Conversation

dwierichs
Copy link
Contributor

@dwierichs dwierichs commented May 22, 2024

Context:
By default, control_values of Controlled instances are lists.
qml.defer_measurements passes a tuple as control_values to ctrl.
create_controlled_op, called by ctrl, tries to merge control_values of the base operation and the provided control_values.
The consequence is an attempted addition of list and tuple, if qml.defer_measurements hits a qml.cond of a Controlled instance, leading to #5717

Description of the Change:
This PR fixes the above problem in two (redundant!) ways:

  • tuples are allowed to be passed as control_values to ctrl, which casts them to a list.
  • defer_measurements passes a list itself.

Clearly those changes are redundant for the bug #5717, with the former also providing users with the option of using tuples for control_values. We could skip the change to defer_measurements, thus.

Benefits:

Possible Drawbacks:

Related GitHub Issues:
Fixes #5717

[sc-63645]

Copy link

codecov bot commented May 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (fdca352) to head (105b0a0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5725      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.01%     
==========================================
  Files         416      416              
  Lines       39053    38763     -290     
==========================================
- Hits        38929    38638     -291     
- Misses        124      125       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dwierichs dwierichs added the review-ready 👌 PRs which are ready for review by someone from the core team. label May 22, 2024
pennylane/transforms/defer_measurements.py Outdated Show resolved Hide resolved
@lillian542 lillian542 self-requested a review May 23, 2024 13:49
Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks @dwierichs!

@dwierichs dwierichs added merge-ready ✔️ All tests pass and the PR is ready to be merged. and removed review-ready 👌 PRs which are ready for review by someone from the core team. labels May 23, 2024
@dwierichs dwierichs enabled auto-merge (squash) May 23, 2024 21:50
@dwierichs dwierichs merged commit 85ff62b into master May 24, 2024
38 checks passed
@dwierichs dwierichs deleted the ctrl-values branch May 24, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-ready ✔️ All tests pass and the PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] defer_measurements does not work with qml.cond applied to controlled gates
3 participants