Hi @CatalinaAlbornoz ,
Thank you for your help. I have installed the master version of Pennylane as you have advised. Now, I can use qml.qsvt
by using the angle_solver="iterative"
argument to the function.
However, I would like to discuss an issue that I encountered. Let me walk through the code that I am experimenting with. It is based on the Pennylane demos Intro to QSVT | PennyLane Demos and QSVT in Practice | PennyLane Demos.
Firstly, I import the dependencies and generate the polynomial sign function’s coefficients using pyqsp
import pennylane as qml
from pyqsp.poly import PolySign
from pyqsp.angle_sequence import QuantumSignalProcessingPhases
import numpy as np
import matplotlib.pyplot as plt
DEGREE = 25
pg = PolySign()
pcoefs, scale = pg.generate(
degree=DEGREE,
delta=10,
ensure_bounded=True,
return_scale=True,
chebyshev_basis=True,
cheb_samples=250
)
Then I use qml.qsvt
to apply the polynomial sign function to a list of points
a_vals = np.linspace(-1, 1, 50)
target = [scale * np.sign(x) for x in a_vals]
x_vals = np.linspace(-1, 1, 16)
A = np.diag(x_vals)
target_poly = pcoefs.tolist()
wire_order = list(range(5))
U_A = qml.matrix(qml.qsvt, wire_order=wire_order)(
A, target_poly, encoding_wires=wire_order, angle_solver="iterative", block_encoding="embedding"
) # block-encoded in 5-qubit system
qsvt_A = np.real(np.diagonal(U_A))[:16] # retrieve transformed eigenvalues
plt.title("QSVT with iterative angle solver")
plt.plot(a_vals, target, label="target")
plt.plot(x_vals, qsvt_A, label="qsvt")
plt.legend()
plt.show()
plt.close("all")
The output of the plot is as below:
As you can see, the qml.qsvt
generated output doesn’t seem to map to the target.
Next, I used pyqsp
QuantumSignalProcessingPhases
function to generate the angles and used qml.QSVT
instead. Note that the transformed values are in the imaginary part for this case.
(phi_pyqsp, reduced_phi, parity) = QuantumSignalProcessingPhases(pcoefs, signal_operator="Wx", chebyshev_basis=True, method="sym_qsp", tolerance=1e-12)
phi_qsvt = qml.transform_angles(phi_pyqsp, "QSP", "QSVT") # convert pyqsp angles to be compatible with QSVT
block_encoding = qml.BlockEncode(A, wires=wire_order)
projectors = [qml.PCPhase(angle, dim=A.shape[0], wires=wire_order) for angle in phi_qsvt]
U_A = qml.matrix(qml.QSVT, wire_order=wire_order)(block_encoding, projectors)
qsvt_A = np.imag(np.diagonal(U_A))[:16] # Note that the transformed values are in the imaginary part for this case
plt.title("QSVT with angles from pyqsp")
plt.plot(a_vals, target, label="target")
plt.plot(x_vals, qsvt_A.real, label="qsvt")
plt.legend()
plt.show()
plt.close("all")
The output of the plot is as below:
As you can see, the qml.QSVT
output resembles close to the target function except at values close to 0 which I think is expected for the sign function.
I’m not sure why there output differs. Also, I realized that the iterative
angle solving in qml.qsvt
gets slow when I increase the number of degrees, e.g. 161 degrees, compared to pyqsp
angle generation function QuantumSignalProcessingPhases
. Looking forward to your kind reply.