-
Notifications
You must be signed in to change notification settings - Fork 575
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
Fix expand_fn
in fourier
#1720
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1720 +/- ##
=======================================
Coverage 99.22% 99.22%
=======================================
Files 204 204
Lines 15395 15395
=======================================
Hits 15275 15275
Misses 120 120
Continue to review full report at Codecov.
|
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.
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)
doc/releases/changelog-dev.md
Outdated
* 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) |
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.
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.
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): |
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.
Curious if there was a reason for changing this (aside from just preferring 0-indexing 😆 )
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.
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) |
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.
So this is to avoid CRX being decomposed now that the stopping condition has changed?
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.
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.
The modified test case fails on master :) It did not before, because of the missing |
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.
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 🙂
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.
🤦 🤦 🤦 🤦
It's too late on my end and I clicked the wrong button!
:D Have a good night :) |
While the
stopping_criterion
for the expansion functionexpand_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.