Skip to content

Update qsvt demos #1522

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 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions demonstrations_v2/tutorial_apply_qsvt/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def my_circuit():
# This ultimately requires computing :math:`\vec{x} = A^{-1} \cdot \vec{b},` where for simplicity we
# assume that :math:`A` is invertible.
#
# .. note::
# Be careful to follow the notation in this section carefully.
# :math:`x` is a scalar and :math:`\vec{x}` is a vector. Sometimes we are talking about the scalar
# function :math:`P(x) = s \cdot \frac{1}{x}` and sometimes we are talking about the matrix-vector
# function :math:`A \cdot \vec{x} = \vec{b}.`
Comment on lines +81 to +85
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feedback from user: found it confusing that x is both a vector and a scalar and it was difficult to track

Temporarily added a note, there are likely better options. Could we switch to another variable other than x?

#
# :math:`A^{-1}` can be constructed directly by inverting the singular values of :math:`A^{T}.` We can
# leverage QSVT to accomplish this by finding the phase angles which apply a polynomial approximation
# to the transformation :math:`\frac{1}{x}.` This may seem simple in theory, but in practice there are
Expand Down
2 changes: 1 addition & 1 deletion demonstrations_v2/tutorial_apply_qsvt/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"executable_stable": true,
"executable_latest": true,
"dateOfPublication": "2023-08-22T00:00:00+00:00",
"dateOfLastModification": "2024-12-05T00:00:00+00:00",
"dateOfLastModification": "2025-08-22T00:00:00+00:00",
"categories": [
"Quantum Computing",
"Algorithms",
Expand Down
16 changes: 13 additions & 3 deletions demonstrations_v2/tutorial_intro_qsvt/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,20 @@
:math:`(5 x^3 - 3x)/2`.
As you will soon learn, QSP can be viewed as a special case of QSVT. We thus use the :func:`~.pennylane.qsvt`
operation to construct the output matrix and compare the resulting transformation to
the target polynomial.
the target polynomial. This function implements alternate products of :math:`U(a)` and :math:`S(\phi)`
as described above:

"""

target_poly = [0, -3 * 0.5, 0, 5 * 0.5]
a = 0.5
qml.draw_mpl(qml.qsvt(a, target_poly, encoding_wires=[0], block_encoding="embedding").decomposition)()

##############################################################################
# In this figure :math:`\Pi_\phi` are phase angle rotations (:math:`S(\phi)`) and `BlockEncode` calls
# are implementations of a block encoding of the scalar :math:`a`. (this needs to be rewritten because
# block encoding is not explaine yet in the demo)
Comment on lines +96 to +108
Copy link
Contributor Author

Choose a reason for hiding this comment

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

User feedback: would like to see what the circuit looks like, trying to draw gave a black box qsvt

We can make it easier by drawing the decomposition for them. This gives one more visual to help understanding the alternating pattern in QSVT/QSP


import pennylane as qml
import numpy as np
import matplotlib.pyplot as plt
Expand All @@ -115,8 +125,8 @@ def qsvt_output(a):
qsvt = [np.real(qsvt_output(a)) for a in a_vals] # neglect small imaginary part
target = [np.polyval(target_poly[::-1], a) for a in a_vals] # evaluate polynomial

plt.plot(a_vals, target, label="target")
plt.plot(a_vals, qsvt, "*", label="qsvt")
plt.plot(a_vals, target, label="target polynomial: (5x^3 - 3x)/2")
plt.plot(a_vals, qsvt, "*", label="qsvt circuit matrix top left entry")
Comment on lines +128 to +129
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is meant to help address

User feedback: confused about what the points mean in this graph

Would like a better label for qsvt than suggested here.


plt.legend()
plt.show()
Expand Down
2 changes: 1 addition & 1 deletion demonstrations_v2/tutorial_intro_qsvt/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"executable_stable": true,
"executable_latest": true,
"dateOfPublication": "2023-05-23T00:00:00+00:00",
"dateOfLastModification": "2025-01-21T00:00:00+00:00",
"dateOfLastModification": "2025-08-22T00:00:00+00:00",
"categories": [
"Algorithms",
"Quantum Computing"
Expand Down
Loading