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

(LK-C-4) Add controlled QubitUnitary support to Lightning Kokkos #955

Merged
merged 114 commits into from
Nov 19, 2024

Conversation

josephleekl
Copy link
Contributor

@josephleekl josephleekl commented Oct 21, 2024

Before submitting

Please complete the following checklist when submitting a PR:

  • All new features must include a unit test.
    If you've fixed a bug or added code that should be tested, add a test to the
    tests directory!

  • All new functions and code must be clearly commented and documented.
    If you do make documentation changes, make sure that the docs build and
    render correctly by running make docs.

  • Ensure that the test suite passes, by running make test.

  • Add a new entry to the .github/CHANGELOG.md file, summarizing the
    change, and including a link back to the PR.

  • Ensure that code is properly formatted by running make format.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


Context:

Description of the Change:
This PR adds support for controlled QubitUnitary for Lightning Kokkos. There are specialized implementations for 1/2/3-qubits (applyNC1/2/3QubitOpFunctor) and a general case implementation (NCMultiQubitOpFunctor). These functors are defined in MatrixGateFunctors.hpp. These are called by applyControlledMatrix or applyOperation/applyNCMultiQubitOp in StateVectorKokkos.hpp

Benefits:
Performance benchmarks for gates are shown here: https://www.notion.so/xanaduai/Lightning-Kokkos-Native-Controlled-Operation-Gate-Benchmarks-12ebc6bd17648017a2dcd237748b24fe

Possible Drawbacks:

Related GitHub Issues:

[sc-76776]

Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@josephleekl josephleekl changed the title Lk control matrix nq Add controlled N-qubit matrix support to Lightning Kokkos Oct 21, 2024
@josephleekl josephleekl force-pushed the lk-control-gate-NQ-multiRZ branch 2 times, most recently from 42f9cd3 to 23f398c Compare October 21, 2024 21:01
@josephleekl josephleekl added ci:build_wheels Activate wheel building. ci:use-gpu-runner Enable usage of GPU runner for this Pull Request urgent Mark a pull request as high priority labels Oct 21, 2024
@josephleekl josephleekl marked this pull request as ready for review October 21, 2024 21:40
Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 99.45055% with 4 lines in your changes missing coverage. Please review.

Project coverage is 96.08%. Comparing base (5ab8064) to head (9d092ae).
Report is 1 commits behind head on lk-control-base.

Files with missing lines Patch % Lines
...nylane_lightning/lightning_kokkos/_state_vector.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           lk-control-base     #955      +/-   ##
===================================================
+ Coverage            94.54%   96.08%   +1.53%     
===================================================
  Files                  231      231              
  Lines                37600    38191     +591     
===================================================
+ Hits                 35550    36695    +1145     
+ Misses                2050     1496     -554     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link
Contributor

@AmintorDusko AmintorDusko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! Thank you, @josephleekl!

@josephleekl
Copy link
Contributor Author

I'm running into some test errors with pennylane and QubitStateVector, I'll merge with the master branch to use the updated version.

@josephleekl
Copy link
Contributor Author

Tests are passing with the merge now

Copy link
Member

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to approve 🥳

@@ -436,6 +436,7 @@ class StateVectorKokkos final
matrix_trans, wires));
break;
default:
// TODO: runtime determine scratch space level
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the optimization on L0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the todo comment to clarify :)

Copy link
Member

@multiphaseCFD multiphaseCFD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @josephleekl !

@josephleekl
Copy link
Contributor Author

Thanks @maliasadi @multiphaseCFD @AmintorDusko !

@josephleekl josephleekl merged commit bde6107 into lk-control-base Nov 19, 2024
62 of 63 checks passed
@josephleekl josephleekl deleted the lk-control-matrix-NQ branch November 19, 2024 20:11
josephleekl added a commit that referenced this pull request Dec 4, 2024
### Before submitting

Please complete the following checklist when submitting a PR:

- [X] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      [`tests`](../tests) directory!

- [X] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [X] Ensure that the test suite passes, by running `make test`.

- [X] Add a new entry to the `.github/CHANGELOG.md` file, summarizing
the
      change, and including a link back to the PR.

- [X] Ensure that code is properly formatted by running `make format`. 

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**
Native arbitrary controlled operations have already been implemented in
Lightning Qubit and Lightning GPU. This PR adds support for controlled
operations to Lightning Kokkos as well. This PR is the base branch of
combination of multiple PRs
([1](#952),
[2](#953),
[3](#954),
[4](#955),
[5](#956),
[6](#958),
[7](#965))

**Description of the Change:**
Controlled named-gates, matrix, generators, and adjoint differentiation
capability is added to Lightning Kokkos C++ layer.

**Benefits:**
Better performance for controlled operations in Lightning Kokkos (CPU +
GPU). Adjoint differentiation now supported in Lightning Kokkos.

**Possible Drawbacks:**

**Related GitHub Issues:**

[sc-78995]

---------

Co-authored-by: ringo-but-quantum <[email protected]>
Co-authored-by: Ali Asadi <[email protected]>
@maliasadi maliasadi mentioned this pull request Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:build_wheels Activate wheel building. ci:use-gpu-runner Enable usage of GPU runner for this Pull Request urgent Mark a pull request as high priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants