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-Base) Add native controlled operation support for Lightning Kokkos #950

Merged
merged 65 commits into from
Dec 4, 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:
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, 2, 3, 4, 5, 6, 7)

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]

@josephleekl josephleekl added the WIP Work-in-progress issue. Not for general fixing. label Oct 18, 2024
@josephleekl josephleekl changed the title Add native controlled operation support for Lightning Kokkos (Base) (LK-C-Base) Add native controlled operation support for Lightning Kokkos Oct 23, 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 24, 2024
@josephleekl josephleekl marked this pull request as ready for review October 24, 2024 00:57
Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 99.53235% with 12 lines in your changes missing coverage. Please review.

Project coverage is 95.85%. Comparing base (74ad9a3) to head (9582e93).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...nylane_lightning/lightning_kokkos/_state_vector.py 0.00% 10 Missing ⚠️
...c/simulators/lightning_kokkos/utils/UtilKokkos.hpp 96.15% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #950      +/-   ##
==========================================
- Coverage   97.29%   95.85%   -1.44%     
==========================================
  Files         229      229              
  Lines       36908    38841    +1933     
==========================================
+ Hits        35909    37232    +1323     
- Misses        999     1609     +610     

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

@josephleekl josephleekl added the urgent Mark a pull request as high priority label Oct 24, 2024
josephleekl and others added 16 commits November 8, 2024 14:47
… Lightning Kokkos (#952)

### 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`](../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 1-qubit gates (e.g. PauliX /
RX / PhaseShift / Hadamard / Rot / GlobalPhase). These are defined in
`BasicGateFunctors.hpp`, and are applied through `applyNC1Functor`
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-76773]
… to Lightning Kokkos (#953)

### 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`](../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]
### 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`](../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 multiRZ for Lightning Kokkos. This
is defined in `BasicGateFunctor.hpp`, and is applied through
`applyNCNFunctor` 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-76775]
### 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`](../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]
@josephleekl josephleekl marked this pull request as ready for review November 29, 2024 17:04
@multiphaseCFD
Copy link
Member

multiphaseCFD commented Dec 2, 2024

Is ControlledGlobalPhase supported?

Yes Controlled(GlobalPhase) is supported, I have removed the old branch for controlled global phase which is no longer used. Good catch and thanks!

Thanks @josephleekl . Nice one! It only needs 1 param passed to the device for the C(GlobalPhase), which could improve the performance at large.

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 @josh146 ! LGTM. Will approve after this final round.

@josephleekl josephleekl marked this pull request as draft December 2, 2024 19:34
@josephleekl josephleekl marked this pull request as ready for review December 2, 2024 20:13
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.

Great work @josephleekl! Happy to approve 🥳

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! Happy to approve.

@josephleekl josephleekl merged commit 158d393 into master Dec 4, 2024
116 of 118 checks passed
@josephleekl josephleekl deleted the lk-control-base branch December 4, 2024 14:11
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.

7 participants