PennyLaneAI / pennylane-lightning

The PennyLane-Lightning plugin provides a fast state-vector simulator written in C++ for use with PennyLane
https://docs.pennylane.ai/projects/lightning
Apache License 2.0
83 stars 35 forks source link

Expval kernels for LightningQubit #557

Open Alex-Preciado opened 10 months ago

Alex-Preciado commented 10 months ago

Important Note

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

Details

The expectation value of a quantum gate $U$ for a circuit in the state $| \psi \rangle$ is $\langle \psi | U | \psi \rangle$. In PennyLane-Lightning this is calculated by first applying $U$ to $| \psi \rangle$ to get $| \psi\' \rangle$ and then take the inner product with $| \psi \rangle$. That is not optimal since one needs to allocate a copy of $| \psi \rangle$.

Implementation

Modify the expval method in MeasurementsLQubit.hpp (only the one with a const std::string &operation argument) to mimic the Lightning-Kokkos implementation, i.e. write specialized kernels that do not rely on applyMatrix/applyOperation+innerProdC but perform all operations at once. That will be done in a loop over the state vector entries (have a look at the PauliX functor in ExpValFunctors.hpp for example). That loop is embarrassingly parallelizable and should be parallelized as such.

Requirements

A PR must satisfy the following:

sbohloul commented 9 months ago

@Alex-Preciado I was wondering if I could directly push a branch to the repo.

Alex-Preciado commented 9 months ago

Hey @sbohloul 👋 , external contributions can only be made through forks. You will need to fork the repo to submit a pull request with your changes. You can find more details here: https://github.com/PennyLaneAI/pennylane-lightning#contributing. Let me know if you any other questions.