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 expand_fn in fourier #1720

Merged
merged 8 commits into from
Oct 6, 2021

Conversation

dwierichs
Copy link
Contributor

While the stopping_criterion for the expansion function expand_multi_par_and_no_gen was adapted during the PR #1681,
the trigger to start the decomposition does not include the condition of a generator missing.

Due to initial expansion of gates when creating a QNode together with an overlap between the two criteria for expansion (multiple gate parameters and missing generator) in the test case, this was overlooked by the test that was designed to check this particular case.

@dwierichs
Copy link
Contributor Author

@josh146 This is a hot fix of #1681 merged in today. I found the bug while recycling the expand_multi_par_and_no_gen function.

@codecov
Copy link

codecov bot commented Oct 6, 2021

Codecov Report

Merging #1720 (2e154d0) into master (c9e044c) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1720   +/-   ##
=======================================
  Coverage   99.22%   99.22%           
=======================================
  Files         204      204           
  Lines       15395    15395           
=======================================
  Hits        15275    15275           
  Misses        120      120           
Impacted Files Coverage Δ
pennylane/fourier/qnode_spectrum.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 c9e044c...2e154d0. Read the comment docs.

@josh146 josh146 added the bug 🐛 Something isn't working label Oct 6, 2021
Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

Fastest bug fix ever 🙂

Only one main request, which is to add a test that ensures this behaviour/edge case is fixed (ideally, this test would fail on master, but will pass on this branch)

pennylane/fourier/qnode_spectrum.py Show resolved Hide resolved
Comment on lines 442 to 444
* Fixes a bug in the newly introduced expansion function `expand_multi_par_and_no_gen` in
`qml.fourier.qnode_spectrum`.
[(#1720)](https://github.com/PennyLaneAI/pennylane/pull/1720)
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a bugfix to new code/logic, typically we simply append the new PR link to the old changelog entry 🙂 So basically, both #1618 and #1720 were involved in introducing qml.fourier.qnode_spectrum.

Since the changelog shows changes relative to the last stable release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, that makes much more sense :)

@@ -376,19 +376,19 @@ def decomposition(theta, wires):
raise NotImplementedError()

@qml.qnode(dev)
def circuit(x, z1, y, z2):
def circuit(x, z0, y, z1):
Copy link
Member

Choose a reason for hiding this comment

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

Curious if there was a reason for changing this (aside from just preferring 0-indexing 😆 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope :)

@@ -400,20 +400,22 @@ def test_no_generator_expansion(self):
class _CRX(qml.CRX):
generator = [None, 1]

@qml.qnode(dev)
def circuit(x, z1, y, z2):
@qml.qnode(dev, max_expansion=0)
Copy link
Member

Choose a reason for hiding this comment

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

So this is to avoid CRX being decomposed now that the stopping condition has changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, previously, CRX was already decomposed in circuit.construct, so that the tape expansion would not be triggered based on the missing generator. This was key to the bug not being seen by this test case.

@dwierichs
Copy link
Contributor Author

The modified test case fails on master :) It did not before, because of the missing max_expansion=0.

Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

The modified test case fails on master :) It did not before, because of the missing max_expansion=0.

🤦 Yes you're right. Good to go 🙂

Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

🤦 🤦 🤦 🤦
It's too late on my end and I clicked the wrong button!

@dwierichs
Copy link
Contributor Author

:D Have a good night :)

@dwierichs dwierichs merged commit fba5aa0 into PennyLaneAI:master Oct 6, 2021
@dwierichs dwierichs deleted the fix-expand_fn-in-fourier branch October 6, 2021 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants