Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expval kernels for LightningQubit #557

Open
Alex-Preciado opened this issue Nov 10, 2023 · 2 comments · May be fixed by #565
Open

Expval kernels for LightningQubit #557

Alex-Preciado opened this issue Nov 10, 2023 · 2 comments · May be fixed by #565

Comments

@Alex-Preciado
Copy link

Alex-Preciado commented Nov 10, 2023

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:

  • Write expval kernels for the Identity, PauliX, PauliY, PauliZ, Hadamard observables.
  • Parallelize the kernels with C++ threads or OpenMP.
  • Validate the implementation with C++ & Python tests (you may reuse existing tests, but add some if coverage requires it).
  • Pass clang-tidy, black and pylint checks.
  • Include a changelog entry under "Improvements".
  • Gather benchmark data using the Python interface of PennyLane (old versus new implementation & time versus number of threads for different qubits count) and discuss the performance trends. Put the benchmarking scripts in a Github gist and share the gist in the PR comments.
@multiphaseCFD multiphaseCFD changed the title In place expval kernels for LightningQubit Expval kernels for LightningQubit Nov 10, 2023
@sbohloul
Copy link

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

@Alex-Preciado
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants