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

Improved documentation for Quantum Arithmetic #6136

Closed
wants to merge 19 commits into from

Conversation

gmlejarza
Copy link
Collaborator

@gmlejarza gmlejarza commented Aug 23, 2024

Context:

Adding extra documentation of arithmetic templates

Description of the Change:

Adding a detailed explanation of the templates' usage details, pictures and a dedicated folder in the templates section.

@gmlejarza gmlejarza marked this pull request as draft August 23, 2024 21:08
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

Copy link

codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (v0.38.0-rc0@5ec56bd). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff               @@
##             v0.38.0-rc0    #6136   +/-   ##
==============================================
  Coverage               ?   99.66%           
==============================================
  Files                  ?      445           
  Lines                  ?    42359           
  Branches               ?        0           
==============================================
  Hits                   ?    42217           
  Misses                 ?      142           
  Partials               ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

mudit2812 and others added 11 commits August 26, 2024 15:52
As name says. Had to open a new PR due to merge conflicts.
As name says. Making myself a reviewer for the daily RC sync.
Automatic sync from the release candidate to master during a feature
freeze.

---------

Co-authored-by: Astral Cai <astral.cai@xanadu.ai>
Co-authored-by: GitHub Actions Bot <>
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
@gmlejarza gmlejarza changed the title [WIP] improved documentation for Quantum Arithmetic Improved documentation for Quantum Arithmetic Aug 27, 2024
@gmlejarza gmlejarza marked this pull request as ready for review August 27, 2024 20:55
@gmlejarza gmlejarza requested a review from soranjh August 28, 2024 14:13
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.

Thank you for adding this documentation! 🙌🚀
Here I leave some comments

Make sure the changes I suggest are applied to all templates if necessary.
On the other hand, this PR should point to v0.38.0-rc0 instead of master. You may get several new files when you make the change, let me know if you have problems.

pennylane/templates/subroutines/phase_adder.py Outdated Show resolved Hide resolved
pennylane/templates/subroutines/phase_adder.py Outdated Show resolved Hide resolved
Comment on lines +108 to +112
to encode the integer :math:`x < mod` in the Fourier basis. Therefore, we need at least
:math:`\lceil \log_2(x)\rceil` ``x_wires`` to represent :math:`x`. After performing the modular addition operation, the resulting integer
encoded in the Fourier basis can be as large as :math:`mod-1`. Hence, we need at least
:math:`\lceil \log_2(mod)\rceil` ``x_wires``
to represent all the possible results. Since :math:`x < mod` by definition, we just need at least :math:`\lceil \log_2(mod)\rceil` ``x_wires``.
Copy link
Contributor

Choose a reason for hiding this comment

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

I found this paragraph difficult to follow and repetitive, could you try to simplify it?

pennylane/templates/subroutines/out_adder.py Show resolved Hide resolved
pennylane/templates/subroutines/multiplier.py Outdated Show resolved Hide resolved
pennylane/templates/subroutines/multiplier.py Outdated Show resolved Hide resolved
Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
@isaacdevlugt isaacdevlugt changed the base branch from master to v0.38.0-rc0 August 28, 2024 20:36
Copy link
Contributor

@soranjh soranjh left a comment

Choose a reason for hiding this comment

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

Left some comment for one of the operators, which also applies to all others.

doc/introduction/templates.rst Show resolved Hide resolved
pennylane/templates/subroutines/adder.py Show resolved Hide resolved

The implementation is based on the quantum Fourier transform method presented in
`arXiv:2311.08555 <https://arxiv.org/abs/2311.08555>`_.
This operation can be represented in a quantum circuit as:
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure adding the image here is helpful. The equation is clear enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave it if possible. Although in the equation it is clear, it seems to me more visual the in-place / out-place difference seen in this way

\text{Adder}(k, mod) |x \rangle = | x+k \; \text{modulo} \; mod \rangle.
\text{Adder}(k, mod) |x \rangle = | x+k \; (mod) \rangle.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this is changed?

k (int): the number that needs to be added
x_wires (Sequence[int]): the wires the operation acts on
mod (int): the modulus for performing the addition, default value is :math:`2^{\text{len(x_wires)}}`
work_wires (Sequence[int]): the two auxiliary wires to be used for performing the addition when :math:`mod \neq 2^{\text{len(x_wires)}}`
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest mentioning the default, instead of the math equation and referring the user to check "usage details".


The first one is ``x_wires`` which is used
to encode the integer :math:`x < mod` in the computational basis. Therefore, we need at least
:math:`\lceil \log_2(x)\rceil` ``x_wires`` to represent :math:`x`. After performing the modular addition operation, the resulting integer
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
:math:`\lceil \log_2(x)\rceil` ``x_wires`` to represent :math:`x`. After performing the modular addition operation, the resulting integer
:math:`\lceil \log_2(x)\rceil` ``x_wires`` to represent :math:`x`. However, after performing the modular addition operation, the resulting integer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've rewritten this paragraph to be more concise and clear

:math:`\lceil \log_2(x)\rceil` ``x_wires`` to represent :math:`x`. After performing the modular addition operation, the resulting integer
encoded in the computational basis can be as large as :math:`mod-1`. Hence, we need at least
:math:`\lceil \log_2(mod)\rceil` ``x_wires``
to represent all the possible results. Since :math:`x < mod` by definition, we just need at least :math:`\lceil \log_2(mod)\rceil` ``x_wires``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
to represent all the possible results. Since :math:`x < mod` by definition, we just need at least :math:`\lceil \log_2(mod)\rceil` ``x_wires``.
to represent all the possible results. Since :math:`x < mod` by definition, we need at least :math:`\lceil \log_2(mod)\rceil` ``x_wires``.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've rewritten this paragraph to be more concise and clear

@isaacdevlugt isaacdevlugt added the do not merge ⚠️ Do not merge the pull request until this label is removed label Aug 28, 2024
Comment on lines -37 to +44
Note that :math:`x` must be smaller than :math:`mod` to get the correct result.
:math:`x` must be smaller than :math:`mod` to get the correct result.
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that "Note that" sounded repititive here but starting with a math symbol, x, is also not ideal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've changed to: "To obtain the correct result, :math:x must be smaller than :math:mod"

@gmlejarza gmlejarza marked this pull request as draft August 29, 2024 04:20
@mudit2812 mudit2812 added this to the v0.38 milestone Aug 29, 2024
@gmlejarza gmlejarza closed this Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge ⚠️ Do not merge the pull request until this label is removed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants