Skip to content

Upload nonlinear amplitude transformation demo#1738

Open
drdren wants to merge 28 commits into
masterfrom
dren-nonlinear-QSVT
Open

Upload nonlinear amplitude transformation demo#1738
drdren wants to merge 28 commits into
masterfrom
dren-nonlinear-QSVT

Conversation

@drdren
Copy link
Copy Markdown
Contributor

@drdren drdren commented Apr 8, 2026

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 then
    run 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)

  • Tutorial
  • [ X] Demo
  • How-to

@drdren drdren requested review from a team as code owners April 8, 2026 16:52
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

👋 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!

Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Try to fix pip install

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Remove pip install

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Add pip install pyqsp

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Comment on lines +197 to +210
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])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Take a look to qml.Reflection(wires)
That should replace all this code 😄

Comment on lines +440 to +445
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))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this qml.PCPhase?

Comment on lines +447 to +456
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Remove pip install pyqsp

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 17, 2026

Your preview is ready 🎉!

You can view your changes here

Deployed at: 2026-05-15 15:15:56 UTC

Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Update figures

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/metadata.json Outdated
Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/metadata.json Outdated
Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/metadata.json Outdated
Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Fix figure formatting

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Better format

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Fix title

Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Update formatting

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Manifest a bullet point list

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Fix bullet point list

Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Fix bullet points

Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Comment thread demonstrations_v2/tutorial_nonlinear_amplitude_transformation/demo.py Outdated
Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Fix bullets

Copy link
Copy Markdown
Contributor Author

@drdren drdren left a comment

Choose a reason for hiding this comment

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

Here are some suggestions!

Comment on lines +10 to +15
# 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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The transition from the first paragraph this sentence is harsh. It's clear why nonlinear transformations -> ... previous demos, ..., block encoding, ...

How about:

Suggested change
# 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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
# [`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>`__,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
# 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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
# `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": [
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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*
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now that we have a great graphic explaining the process, maybe you want to point back to it throughout the demo?

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.

3 participants