-
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
Generalize fourier spectrum #1681
Generalize fourier spectrum #1681
Conversation
We previously discussed that some multi-parameter gates that easily decompose into gates to which the Fourier analysis is applicable should have a flag like |
Codecov Report
@@ Coverage Diff @@
## master #1681 +/- ##
=======================================
Coverage 99.21% 99.22%
=======================================
Files 203 204 +1
Lines 15300 15395 +95
=======================================
+ Hits 15180 15275 +95
Misses 120 120
Continue to review full report at Codecov.
|
…nnylane into generalize-fourier-spectrum
…nnylane into generalize-fourier-spectrum
@josh Thanks for the review! I am not sure now whether you would like to make the two functions diffable or whether that is out of scope? |
@josh146 that comment is here. Unfortunately I still don't have any amazing suggestions for renaming. |
@glassnotes the link doesn't work for me 😆 |
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.
@dwierichs no major comments, just left a couple comments/questions. There is still the matter of renaming the functions, though.
Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>
…nnylane into generalize-fourier-spectrum
…nnylane into generalize-fourier-spectrum
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.
@dwierichs looks good to me, thanks for you work on this! 🎉
>>> _process_ids(None, None, circuit) | ||
(OrderedDict([('a', Ellipsis), ('b', Ellipsis), ('c', Ellipsis)]), [0, 1, 2]) | ||
|
||
Note that ``x`` does not appear here, because it has a default value defined and thus is |
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 new example and more detailed explanation are extremely helpful, thank you! 💯
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.
this docstring is amazing 😭
Co-authored-by: Olivia Di Matteo <2068515+glassnotes@users.noreply.github.com>
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.
Great work @dwierichs! Left some minor documentation fixes, but apart from that good to go on my end 🙂
I think there is only other thing that need to be changed as part of the renaming (although this can be left for a separate PR):
- Updating
spectrum
->circuit_spectrum
on theqml.fourier
module docpage (worth also mentioningqnode_spectrum
?)
>>> _process_ids(None, None, circuit) | ||
(OrderedDict([('a', Ellipsis), ('b', Ellipsis), ('c', Ellipsis)]), [0, 1, 2]) | ||
|
||
Note that ``x`` does not appear here, because it has a default value defined and thus is |
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.
this docstring is amazing 😭
Context:
This PR generalizes the
qml.fourier.spectrum
to more general circuits. It is part of the series of PRs that replace #1635.After reconsiderations, this is not implemented with a separate
ArgMap
class (see #1653).Description of the Change:
The spectrum is now computed with respect to QNode arguments, and no longer with respect to gate arguments. This allows to obtain the function structure with respect to parameters that actually are controlled directly by the user.
Classical preprocessing between QNode and gate parameters is taken into account and factored into the spectrum.
In order for the spectrum to actually describe the QNode fully, the return value needs to be an expectation value/a sum of expectation values, and the preprocessing needs to be linear.
spectrum
checks whether the Jacobian is constant acrossnum_pos+1
many points (including the originalargs
andnum_pos
additional, randomargs
). This does not 100% guarantee linearity of the processing but makes it very unlikely that non-linear processing is overlooked. The test can be deactivated by settingnum_pos=0
.The arguments and elements of arguments for which the spectrum is computed are controlled by
encoding_args
, which is adict
with argument names as keys and a list of index tuples for the respective argument as values. The value may be replaced by anEllipsis
, in which case all elements of the argument are considered. Ifencoding_args
is a set of argumentnames
instead, it is interpreted like{name: ... for name in names}
.Alternatively, the arguments to compute the spectrum for can be chosen by their index in the function signature via
argnum
.If neither
encoding_args
norargnum
are provided, those arguments of the QNode that do not have a default defined (and all their elements, if they are array-valued) are considered.Benefits:
More streamlined usage of the
spectrum
functionality on the level of QNodes instead of looking into a QNode.No gate
id
s have to be assigned anymore.Preprocessing of QNode arguments into gate arguments is taken into account both in the spectrum output and to exclude a large class of circuits that do yield a Fourier series in the sense considered by this function.
Possible Drawbacks:
This is a breaking change in multiple ways: The input arguments changed, the output format changed and the gate
id
s are no longer required or considered.Also, the content of the output changed because preprocessing is included in the spectrum.
Related GitHub Issues:
#1635
#1653