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), quantum singular value transformation (QSVT) or generalized quantum signal processing (GQSP).
The polynomial \(P(x) = \sum_n a_n x^n\) must satisfy \(|P(x)| \leq 1\) for \(x \in [-1, 1]\). In QSP and QSVT, the coefficients \(a_n\) 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"
,"QSVT"
or"GQSP"
.angle_solver (str) –
Specifies the method used to calculate the angles. Options include:
"root-finding"
: effective for polynomials of degree up to \(\sim 1000\)"iterative"
: effective for polynomials of degree higher than \(\sim 1000\) for the"QSP"
and"QSVT"
routines.
- 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 - \frac{x^3}{2} + \frac{x^5}{3}\).>>> 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 - \frac{x^3}{2} + \frac{x^5}{3}\) 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