PennyLaneAI / pennylane

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
https://pennylane.ai
Apache License 2.0
2.26k stars 585 forks source link

Add `PrepSelPrep` block encoding template #5739

Open soranjh opened 3 months ago

soranjh commented 3 months ago

Feature details

⚠️ This issue is part of an internal assignment and not meant for external contributors.

A linear combination of unitaries (LCU) can be block-encoded using Prepare and Select operators. Adding an operation to PennyLane that implements this algorithm will facilitate block-encoding LCU operators. The operation can be used in a quantum circuit as

lcu = qml.dot([0.25, 0.75], [qml.Z(1), qml.X(0) @ qml.X(1)])

dev = qml.device('default.qubit')

@qml.qnode(dev)
def circuit():
    qml.PrepSelPrep(lcu, control = 0)  
    return qml.state()

Implementation

This demo provides details to construct the block encoding circuit.

The qml.PrepSelPrep operation should be implemented as a template and added to the subroutines module.

Requirements

  1. The qml.PrepSelPrep operation should correctly block-encode an LCU operation with positive and negative coefficients. Supporting imaginary coefficients is desired but not mandatory.

  2. The differentiability of the workflow should be tested with respect to the LCU elements with autograd and JAX. Optionally, the template should work with jax.jit.

willjmax commented 3 months ago

I've implemented qml.PrepSelPrep as a template, and set up some tests inspired by the tests for qml.Select. It appears to be working correctly except for the differentiability tests.

I'd like some clarification. The function should be differentiable with respect to the LCU elements. In your example the LCU is built from qml.dot which returns a type pennylane.ops.op_math.sum.Sum, but autograd raises a type error saying that this type cannot be differentiated. Should qml.PrepSelPrep take some other type as input? or am I misunderstanding the requirement?

soranjh commented 3 months ago

@willjmax Thanks for working on this. Could you please open your PR and ask the question there. Please tag me as reviewer so I can see the PR as soon as it is open.

willjmax commented 3 months ago

See PR #5756

soranjh commented 3 months ago

Thanks.