qml.transform_angles

transform_angles(angles, routine1, routine2)[source]

Converts angles for quantum signal processing (QSP) and quantum singular value transformation (QSVT) routines.

The transformation is based on Appendix A.2 of arXiv:2105.02859. Note that QSVT is equivalent to taking the reflection convention of QSP.

Parameters
  • angles (tensor-like) – angles to be transformed

  • routine1 (str) – the current routine for which the angles are obtained, must be either "QSP" or "QSVT"

  • routine2 (str) – the target routine for which the angles should be transformed, must be either "QSP" or "QSVT"

Returns

the transformed angles as an array

Return type

tensor-like

Example

>>> qsp_angles = np.array([0.2, 0.3, 0.5])
>>> qsvt_angles = qml.transform_angles(qsp_angles, "QSP", "QSVT")
>>> print(qsvt_angles)
[-6.86858347  1.87079633 -0.28539816]

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 = [0, 1.0, 0, -1/2, 0, 1/3]

qsp_angles = qml.poly_to_angles(poly, "QSP")
qsvt_angles = qml.transform_angles(qsp_angles, "QSP", "QSVT")

x = 0.2

# Encodes 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

Contents

Using PennyLane

Release news

Development

API

Internals