-
Notifications
You must be signed in to change notification settings - Fork 212
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
base: master
Are you sure you want to change the base?
Update qsvt demos #1522
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is meant to help address
Would like a better label for qsvt than suggested here. |
||
|
||
plt.legend() | ||
plt.show() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporarily added a note, there are likely better options. Could we switch to another variable other than x?