Skip to content

[WIP] Add demo on groups, FFTs and QFTs #1469

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

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

[WIP] Add demo on groups, FFTs and QFTs #1469

wants to merge 39 commits into from

Conversation

mariaschuld
Copy link
Contributor

This demo was internally discussed, and is supposed to enlarge our portfolio of Fourier-theoretic methods in quantum algorithms.

Copy link

👋 Hey, looks like you've updated some demos!

🐘 Don't forget to update the dateOfLastModification in the associated metadata files so your changes are reflected in Glass Onion (search and recommendations).

Please hide this comment once the field(s) are updated. Thanks!

Comment on lines 7 to 8
],
"dateOfPublication": "2025-07-30T10:00:00+00:00",
Copy link
Collaborator

Choose a reason for hiding this comment

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

These new metadata fields will let you control the executability of the demo. Not needed now, but in case there are dependency issues in the future you can set these to false to make the demo non-executable temporarily, without having to change the name of the demo:

Suggested change
],
"dateOfPublication": "2025-07-30T10:00:00+00:00",
],
"executable_stable": true,
"executable_latest": true,
"dateOfPublication": "2025-07-30T10:00:00+00:00",

Copy link
Collaborator

Choose a reason for hiding this comment

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

I applied these to trigger a rebuild 😄

@PennyLaneAI PennyLaneAI deleted a comment from github-actions bot Aug 6, 2025
Copy link

github-actions bot commented Aug 6, 2025

Your preview is ready 🎉!

You can view your changes here

@mariaschuld mariaschuld requested a review from KetpuntoG August 19, 2025 11:40
@mariaschuld
Copy link
Contributor Author

@alvaro-at-xanadu the demo is now in a final draft stage, and I tagged Vasilis and Guillermo for a technical review. What else would I need to do to proceed? Shall I ask Tarik for images? :)

@alvaro-at-xanadu
Copy link
Collaborator

@alvaro-at-xanadu the demo is now in a final draft stage, and I tagged Vasilis and Guillermo for a technical review. What else would I need to do to proceed? Shall I ask Tarik for images? :)

Hi @mariaschuld ! Yes, feel free to touch base with Tarik for images, and let us know when technical review is ready so we can do a quick product/content review.

Copy link

⚠️ Deprecation Warning ⚠️

You are modifying files in the demonstrations/ directory. This directory is no longer in use.

Please add or move your files to demonstrations_v2/, and use the following format:

your_demo_name/
    - demo.py
    - metadata.json
    - requirements.in (optional)

For additional information, please refer to the contributing guidelines

Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

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

Nice work! 🥳 Here some comments

# function :math:`f(x_1), ...,f(x_N)` evaluated or "sampled" at equidistant
# x-values :math:`x_1,...,x_N`. The Fourier coefficients are then given as
#
# .. math:: \hat{f}(k) = \frac{1}{\sqrt{N}}\sum_{i=1}^N f(x_i) e^{2 \pi i \frac{k x}{N}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest to use j = 1.... so the imaginary "i" is different

Copy link
Contributor

Choose a reason for hiding this comment

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

sub-index in x is missing

Comment on lines +62 to +64
# the interval :math:`0,..,N-1` is thought to be "periodically continued", which means that :math:`f(x_i) = f(x_i + N)`.
#
# Let's code this up:
Copy link
Contributor

Choose a reason for hiding this comment

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

In the way it is said here I thought you were going to show the periodicity

Comment on lines +155 to +164
def g(x):
"""Majority function for length-n bitstrings."""
count_ones = sum(x[i] for i in range(n))
return count_ones/n

def chi(x, k):
"""Character for Z_2^n"""
return np.prod([np.exp(1j * k[i] * x[i]) for i in range(n)])

def g_hat(k):
Copy link
Contributor

Choose a reason for hiding this comment

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

I was not sure what these function are since the names do not match the text

# Choosing :math:`N=2` we get the group :math:`Z_2^n` mentioned above, where we consider N "copies" of the binary set :math:`\{0,1\}`.
# This captures boolean logic ubiquitous in quantum algorithms. The characters for :math:`Z_2^n` are of the form
#
# .. math:: e^{i k_0 x_0} \dots e^{i k_{N-1} x_{N-1}}, \;\; k_0,...,k_{N-1} \in \{0,1\}, \; x_0,...,x_{N-1} \in \{0,1\}
Copy link
Contributor

Choose a reason for hiding this comment

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

There may be a $\pi$ on the exponent

Copy link
Contributor

Choose a reason for hiding this comment

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

Also in the code I think, but I may be wrong :)

Comment on lines +292 to +295
# .. admonition:: Subgroup
# :class: note
#
# A subgroup is a subset of the original set that, under the group operation, fulfills all group axioms.
Copy link
Contributor

Choose a reason for hiding this comment

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

If you are defining the bases, you could also say what dual G was before, I actually forgot what that means 🙈

Comment on lines +307 to +314
# The entire trick of the Cooley-Tukey algorithm is a change of variables,
#
# .. math::
# \begin{align}
# x &\rightarrow 3 x_1 + x_2, \;\; x_1 = 0,1, \; x_2 = 0,1,2 \\
# k &\rightarrow 2k_2 + k_1 , \;\; k_1 = 0,1,2 \; k_2 = 0,1
# \end{align}
#
Copy link
Contributor

Choose a reason for hiding this comment

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

Where this come from? What should I do if I have a different m Z_m?

#
# Essentially, the change in variables turns the Fourier basis function over period 6 into a Fourier basis function with period 2,
# which makes the dependency on :math:`k_2` disappear. This effectively turns the Fourier transform into a sum of "smaller" Fourier transforms
# over :math:`3x_1`, namely :math:`\{0, 3\}`, :math:`\{1, 4\}`, and :math:`\{2, 5\}`. These are combined with
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure what (0,3),(1,4), (2,5) is referring to

Comment on lines +310 to +313
# \begin{align}
# x &\rightarrow 3 x_1 + x_2, \;\; x_1 = 0,1, \; x_2 = 0,1,2 \\
# k &\rightarrow 2k_2 + k_1 , \;\; k_1 = 0,1,2 \; k_2 = 0,1
# \end{align}
Copy link
Contributor

Choose a reason for hiding this comment

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

render is not ideal, maybe \quad instead of ; solve the issue

#
# The splitting of the variable :math:`k` is related to the concept of "restricting a character" to the subgroup.
# Essentially, it allows us turn the characters, or Fourier basis functions :math:`e^{\frac{2 \pi i}{6} x k }`
# related to the original group, into characters of the subgroup, :math:`e^{\frac{2 \pi i}{2} x_1 k_1 }` by changing the period.
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

#

#######################################################################
# From FFTs to QFTs
Copy link
Contributor

Choose a reason for hiding this comment

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

In this section I have missed the connection with the previous section. After developing the mathematics I thought it would be clearer the connection. I saw the previous version where the formulas were and it was not clear to me neither, so I understand that it has been tried and it has not been easy 😅 (not a blocker but those were my thoughts after reading)

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.

5 participants