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

Only update object's queue metadata if already in the queue #2612

Merged
merged 12 commits into from
May 30, 2022

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented May 24, 2022

In multiple places across the codebase, we see the pattern:

try:
    qml.QueuingContext.update_info(obj, **kwargs)
except QueuingError:
      obj.queue()
     qml.QueuingContext.update_info(obj, **kwargs)
except NotImplementedError:
    pass

Currently, the role of object metadata is to indicate whether an operation should be ignored by the tape processing step. So most of the time, there is no reason to queue the object only to mark it as invisible.

This also is a lot of repeated code.

This PR adds a safe_update_queue and _safe_update_queue methods to qml.QueuingContext that only updates the metadata if the object is in the queue. It will never raise QueuingError's.

@codecov
Copy link

codecov bot commented May 24, 2022

Codecov Report

Merging #2612 (881df0d) into master (5e411af) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2612      +/-   ##
==========================================
- Coverage   99.59%   99.58%   -0.02%     
==========================================
  Files         244      244              
  Lines       19670    19667       -3     
==========================================
- Hits        19590    19585       -5     
- Misses         80       82       +2     
Impacted Files Coverage Δ
pennylane/measurements.py 99.57% <100.00%> (-0.01%) ⬇️
pennylane/operation.py 96.50% <100.00%> (-0.33%) ⬇️
pennylane/ops/qubit/hamiltonian.py 100.00% <100.00%> (ø)
pennylane/queuing.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e411af...881df0d. Read the comment docs.

pennylane/queuing.py Outdated Show resolved Hide resolved
@albi3ro albi3ro requested a review from Jaybsoni May 26, 2022 18:07
Copy link
Contributor

@Jaybsoni Jaybsoni 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 👍🏼

Copy link
Contributor

@Jaybsoni Jaybsoni left a comment

Choose a reason for hiding this comment

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

Just CodeCov 👍🏼

@josh146 josh146 merged commit e40c47e into master May 30, 2022
@josh146 josh146 deleted the safe_queue_update_info branch May 30, 2022 17:10
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.

3 participants