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-2) Add controlled named 2/4-qubit gate (e.g. NCIsingXX) support to Lightning Kokkos #953

Merged
merged 61 commits into from
Nov 12, 2024

Conversation

josephleekl
Copy link
Contributor

@josephleekl josephleekl commented Oct 18, 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 named controlled 2/4-qubit gates (e.g. Swap / IsingXX / SingleExcitation / Double Excitation). These are defined in BasicGateFunctor.hpp, and are applied through applyNC2Functor and applyNC4Functor defined in the same file.

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-76774]

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 add native 2/3 qubit controlled gate support to Lightning Kokkos add native 2/3/4 qubit controlled gate support to Lightning Kokkos Oct 19, 2024
@josephleekl josephleekl added ci:build_wheels Activate wheel building. ci:use-gpu-runner Enable usage of GPU runner for this Pull Request labels Oct 21, 2024
@josephleekl josephleekl marked this pull request as ready for review October 21, 2024 16:08
Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 99.90431% with 1 line in your changes missing coverage. Please review.

Please upload report for BASE (lk-control-base@e89065f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...nylane_lightning/lightning_kokkos/_state_vector.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             lk-control-base     #953   +/-   ##
==================================================
  Coverage                   ?   97.00%           
==================================================
  Files                      ?      221           
  Lines                      ?    34366           
  Branches                   ?        0           
==================================================
  Hits                       ?    33338           
  Misses                     ?     1028           
  Partials                   ?        0           

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

@josephleekl josephleekl changed the title add native 2/3/4 qubit controlled gate support to Lightning Kokkos Add controlled 2/3/4-qubit gate support to Lightning Kokkos Oct 21, 2024
@josephleekl josephleekl marked this pull request as draft October 21, 2024 19:50
@josephleekl josephleekl marked this pull request as ready for review October 21, 2024 21:03
@josephleekl josephleekl added the urgent Mark a pull request as high priority label Oct 21, 2024
Base automatically changed from lk-control-gate-1Q to lk-control-base November 8, 2024 23:32
@josephleekl josephleekl changed the base branch from lk-control-base to lk-control-gate-NQ-multiRZ November 9, 2024 01:00
@josephleekl josephleekl changed the base branch from lk-control-gate-NQ-multiRZ to lk-control-base November 9, 2024 01:00
Copy link
Contributor

@LuisAlfredoNu LuisAlfredoNu left a comment

Choose a reason for hiding this comment

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

Thank you @josephleekl
Only a few questions before to move forward 😄

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.

Nice work @josephleekl! Happy to approve once the last comments have been addressed.

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.

Nice work @josephleekl ! Just a few questions.

@@ -600,7 +651,7 @@ template <class PrecisionT, class FuncT> class applyNC2Functor {
template <class ExecutionSpace>
applyNC2Functor([[maybe_unused]] ExecutionSpace exec,
Kokkos::View<Kokkos::complex<PrecisionT> *> arr_,
std::size_t num_qubits,
const std::size_t num_qubits,
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to set num_qubits as const for the argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will keep consistent with the original file that e.g. applyNC2Functor applyNC1Functor etc. does not use const, just std::size_t num_qubits, but I will keep the const std::size_t num_qubits in specific functions applyPauliY. This could be revisited in a later PR.

@josephleekl
Copy link
Contributor Author

I have addressed the comments above, please have a look and approve if ready, thanks! @maliasadi @LuisAlfredoNu @multiphaseCFD

Copy link
Contributor

@LuisAlfredoNu LuisAlfredoNu left a comment

Choose a reason for hiding this comment

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

Thank you @josephleekl
Nice work!

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.

LGTM 🥳

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.

Thanks @josephleekl ! Nice work

@josephleekl josephleekl merged commit 1979bd7 into lk-control-base Nov 12, 2024
64 of 65 checks passed
@josephleekl josephleekl deleted the lk-control-gate-23Q branch November 12, 2024 18:21
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.

5 participants