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 bug where unexpected queuing occurs in qml.ctrl among other functions #6284

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

KetpuntoG
Copy link
Contributor

@KetpuntoG KetpuntoG commented Sep 19, 2024

This PR seeks to fix this bug.

The issue was that unwanted operators were being added when applying the qml.ctrl, qml.prod, qml.cond and qml.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.

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.70%. Comparing base (de54c54) to head (342a92c).
Report is 3 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

@KetpuntoG KetpuntoG changed the title [WIP] Fix bug where unexpected queuing occurs in qml.ctrl among other functions Fix bug where unexpected queuing occurs in qml.ctrl among other functions Sep 20, 2024
Copy link
Contributor

@astralcai astralcai left a 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?

@@ -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):
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@KetpuntoG
Copy link
Contributor Author

qml.cond also contains similar logic. Can you also update that to use this recursive method?

I tried this but it seems qml.cond only accept operators, not functions as qml.ctrl or qml.adjoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants