Upload nonlinear amplitude transformation demo#1738
Conversation
|
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
drdren
left a comment
There was a problem hiding this comment.
Try to fix pip install
drdren
left a comment
There was a problem hiding this comment.
Remove pip install
drdren
left a comment
There was a problem hiding this comment.
Add pip install pyqsp
| def MultiControlledZ(wires, control_values=None): | ||
| if control_values is None: | ||
| control_values = [0] * (len(wires) - 1) | ||
| qml.ctrl(qml.Z(wires=wires[-1]), | ||
| control=wires[:-1], | ||
| control_values=control_values) | ||
|
|
||
| # R_gate implements the reflection R used in the block construction. | ||
| def R(wires): | ||
| assert len(wires) % 2 == 1 | ||
| n = len(wires)//2 | ||
| qml.PauliX(wires=wires[0]) | ||
| MultiControlledZ(wires=wires[1:n+1]+[wires[0]]) | ||
| qml.PauliX(wires=wires[0]) |
There was a problem hiding this comment.
Take a look to qml.Reflection(wires)
That should replace all this code 😄
| def ProjCtrlPhaseShift(control_wires, target_wire, phi): | ||
| qml.MultiControlledX(wires=control_wires + target_wire, | ||
| control_values=[0] * len(control_wires)) | ||
| qml.RZ(phi = 2 * phi, wires=target_wire) | ||
| qml.MultiControlledX(wires=control_wires + target_wire, | ||
| control_values=[0] * len(control_wires)) |
| def generate_poly(deg, func, odd): | ||
| poly = PolyTaylorSeries().taylor_series( | ||
| func=func, degree=deg, max_scale=0.9, | ||
| chebyshev_basis=True, cheb_samples=2*deg) | ||
| pcoefs = poly.coef | ||
| if odd: | ||
| pcoefs[0::2] = 0 | ||
| else: | ||
| pcoefs[1::2] = 0 | ||
| return pcoefs |
There was a problem hiding this comment.
This is the way I get coefs given an arbitrary function
So no pyqsp needed here :)
from numpy.polynomial import Chebyshev as T
cheb_poly = T.interpolate(target_func, degree)
drdren
left a comment
There was a problem hiding this comment.
Remove pip install pyqsp
Your preview is ready 🎉!You can view your changes here
|
drdren
left a comment
There was a problem hiding this comment.
Fix figure formatting
drdren
left a comment
There was a problem hiding this comment.
Manifest a bullet point list
drdren
left a comment
There was a problem hiding this comment.
Fix bullet point list
drdren
left a comment
There was a problem hiding this comment.
Here are some suggestions!
| # As also described in previous demos, :doc:`block | ||
| # encoding <demos/tutorial_block_encoding>` | ||
| # [`1 <https://arxiv.org/abs/1804.01973>`__] and :doc:`quantum singular value | ||
| # transformation <demos/tutorial_intro_qsvt>` | ||
| # [`2 <https://arxiv.org/abs/1806.01838>`__] have become the “gold standard” for implementing matrix | ||
| # functions. However, these techniques primarily transform the singular values (or eigenvalues) of an |
There was a problem hiding this comment.
The transition from the first paragraph this sentence is harsh. It's clear why nonlinear transformations -> ... previous demos, ..., block encoding, ...
How about:
| # As also described in previous demos, :doc:`block | |
| # encoding <demos/tutorial_block_encoding>` | |
| # [`1 <https://arxiv.org/abs/1804.01973>`__] and :doc:`quantum singular value | |
| # transformation <demos/tutorial_intro_qsvt>` | |
| # [`2 <https://arxiv.org/abs/1806.01838>`__] have become the “gold standard” for implementing matrix | |
| # functions. However, these techniques primarily transform the singular values (or eigenvalues) of an | |
| # The "gold standard" methods to implement matrix transformations are :doc:`block | |
| # encoding <demos/tutorial_block_encoding>` | |
| # [`1 <https://arxiv.org/abs/1804.01973>`__] and :doc:`quantum singular value | |
| # transformation <demos/tutorial_intro_qsvt>` | |
| # [`2 <https://arxiv.org/abs/1806.01838>`__]. However, these techniques primarily transform the singular values (or eigenvalues) of an |
| # operator. In many quantum machine learning settings - especially amplitude encoding - the data isn’t | ||
| # stored in an operator at all. Instead, it lives directly in the amplitudes of a quantum state. | ||
| # | ||
| # To transform these amplitudes nonlinearly, we need a generalized approach. The Nonlinear Amplitude |
There was a problem hiding this comment.
I'm quite confused at this point. The goal is clear: come up with a method to perform nonlinear transformations when a quantum computer only does linear operations.
Somehow, that became block encoding and QSVT, but those don't work?
What is the true goal and problem that the nonlinear amplitude transformation addresses? Does NLAT keep the data in the form of amplitude encoding?
| # | ||
| # So the amplitude vector :math:`{\psi_i}` appears as the first column of :math:`U`. The obstacle is | ||
| # that QSVT does not act on a column of a unitary; it acts on the spectrum of an operator accessed | ||
| # through a block encoding. |
There was a problem hiding this comment.
A similar confusion has occurred here. I could understand the definition of a block encoding. I could also understand that |\psi> = U |0> implies that the elements of \psi are in fact the left-most column vector of U.
"The obstacle that QSVT does not act ..." comes out of nowhere. I think some previewing of what we're trying to argue at the end of "Once :math:A is available in this form, QSVT can implement polynomial transformations of the encoded operator, informally :math:A \mapsto P(A), by acting on its spectrum." would be helpful.
| # | ||
| # This is in sense equivalent to “encoding the first column into a diagonal,” but the key point is | ||
| # subtler: :math:`U` is not modified. Instead, an auxiliary unitary :math:`U_\Psi` is engineered so | ||
| # that the amplitudes :math:`\psi_i` appear as the diagonal entries of the encoded operator. In the |
There was a problem hiding this comment.
So creating a block encoding that has diagonal entries has the spectrum we want but U_A does not have?
| # spectrum (here, as the diagonal entries of :math:`\Psi`), a polynomial transform :math:`P(\Psi)` | ||
| # corresponds to applying :math:`\psi_k \mapsto P(\psi_k)` in parallel (up to postselection). | ||
| # | ||
| # Here, we build :math:`U_\Psi` explicitly for a small system (:math:`n=2`, so :math:`N=4`) to make |
There was a problem hiding this comment.
I know from context that n is the number of qubits and N = 2^n is the size of the Hilbert space but did you define those anywhere?
| # As a broader perspective, the same “linear mixing + elementwise nonlinearity” motif underpins more | ||
| # advanced architectures. Recent work has explored the feasibility of quantum implementations of | ||
| # transformer-style inference under various access models and resource assumptions | ||
| # [`6 <https://arxiv.org/abs/2402.16714>`__]. The QMLP here should be viewed as a minimal instance of |
There was a problem hiding this comment.
| # [`6 <https://arxiv.org/abs/2402.16714>`__]. The QMLP here should be viewed as a minimal instance of | |
| # [#qtransformer]_. The QMLP here should be viewed as a minimal instance of |
| # violating linearity. | ||
| # | ||
| # In this demo, we have implemented the nonlinear amplitude transformation described in Guo et | ||
| # al. (2024) and Rattew and Rebentrost (2024) [`3 <https://arxiv.org/abs/2107.10764>`__, |
There was a problem hiding this comment.
| # al. (2024) and Rattew and Rebentrost (2024) [`3 <https://arxiv.org/abs/2107.10764>`__, | |
| # al. (2024) and Rattew and Rebentrost (2024) [#ntca]_, |
| # | ||
| # In this demo, we have implemented the nonlinear amplitude transformation described in Guo et | ||
| # al. (2024) and Rattew and Rebentrost (2024) [`3 <https://arxiv.org/abs/2107.10764>`__, | ||
| # `4 <https://arxiv.org/abs/2309.09839>`__]. We verified the diagonal amplitude block encoding on a |
There was a problem hiding this comment.
| # `4 <https://arxiv.org/abs/2309.09839>`__]. We verified the diagonal amplitude block encoding on a | |
| # [#importancesampling]_. We verified the diagonal amplitude block encoding on a |
| ], | ||
| "seoDescription": "Learn about the nonlinear amplitude transformation using QSVT", | ||
| "doi": "", | ||
| "references": [ |
There was a problem hiding this comment.
If the bibliography in demo.py is correct, then this references section should be changed accordingly.
| # :width: 95% | ||
| # :align: center | ||
| # | ||
| # Figure 1: *A schematic of the nonlinear transformation transformation with QSVT* |
There was a problem hiding this comment.
Now that we have a great graphic explaining the process, maybe you want to point back to it throughout the demo?
Before submitting
Please complete the following checklist when submitting a PR:
Ensure that your tutorial executes correctly, and conforms to the
guidelines specified in the README.
Remember to do a grammar check of the content you include.
All tutorials conform to
PEP8 standards.
To auto format files, simply
pip install black, and thenrun
black -l 100 path/to/file.py.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Title:
Summary:
Relevant references:
Possible Drawbacks:
Related GitHub Issues:
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
GOALS — Why are we working on this now?
Eg. Promote a new PL feature or show a PL implementation of a recent paper.
AUDIENCE — Who is this for?
Eg. Chemistry researchers, PL educators, beginners in quantum computing.
KEYWORDS — What words should be included in the marketing post?
Which of the following types of documentation is most similar to your file?
(more details here)