qml.poly_to_angles¶
- poly_to_angles(poly, routine, angle_solver='root-finding')[source]¶
Computes the angles needed to implement a polynomial transformation with quantum signal processing (QSP) or quantum singular value transformation (QSVT).
The polynomial P(x)=∑nanxn must satisfy |P(x)|≤1 for x∈[−1,1], the coefficients an must be real and the exponents n must be either all even or all odd. For more details see arXiv:2105.02859.
- Parameters
poly (tensor-like) – coefficients of the polynomial ordered from lowest to highest power
routine (str) – the routine for which the angles are computed. Must be either
"QSP"
or"QSVT"
.angle_solver (str) – the method used to calculate the angles. Default is
"root-finding"
."root-finding"
is currently the only supported method.
- Returns
computed angles for the specified routine
- Return type
(tensor-like)
- Raises
AssertionError – if
poly
is not validAssertionError – if
routine
orangle_solver
is not supported
Example
This example generates the
QSVT
angles for the polynomial P(x)=x−x32+x53.>>> poly = np.array([0, 1.0, 0, -1/2, 0, 1/3]) >>> qsvt_angles = qml.poly_to_angles(poly, "QSVT") >>> print(qsvt_angles) [-5.49778714 1.57079633 1.57079633 0.5833829 1.61095884 0.74753829]
Usage Details
This example applies the polynomial P(x)=x−x32+x53 to a block-encoding of x=0.2.
poly = np.array([0, 1.0, 0, -1/2, 0, 1/3]) qsvt_angles = qml.poly_to_angles(poly, "QSVT") x = 0.2 # Encode x in the top left of the matrix block_encoding = qml.RX(2 * np.arccos(x), wires=0) projectors = [qml.PCPhase(angle, dim=1, wires=0) for angle in qsvt_angles] @qml.qnode(qml.device("default.qubit")) def circuit_qsvt(): qml.QSVT(block_encoding, projectors) return qml.state() output = qml.matrix(circuit_qsvt, wire_order=[0])()[0, 0] expected = sum(coef * (x**i) for i, coef in enumerate(poly)) print("output qsvt: ", output.real) print("P(x) = ", expected)
output qsvt: 0.19610666666647059 P(x) = 0.19610666666666668