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

Support arbitrary controlled operations in lightning.qubit #516

Merged
merged 116 commits into from
Dec 8, 2023

Conversation

vincentmr
Copy link
Contributor

@vincentmr vincentmr commented Oct 11, 2023

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:
Applying a gate such as qml.ControlledQubitUnitary(U, control_wires=range(5), wires=[5]) should be quite fast compared with qml.QubitUnitary(U, wires=range(6)) because the first requires applying a 2x2 matrix to 1/32th of all state vector entries and the second applying a 64x64 matrix to all entries. This also provides less control over the parametrization of U, which can be handy in adjoint-diff implementations.

Description of the Change:
Introduce three new kind of gates: controlled gates, controlled generators and controlled matrix ops. The new gates are analogous to the current gates, generators and matrix ops. The new gates accept arbitrary controls, for example LM::NCMultiQubitOp takes in std::vector<std::size_t> &controlled_wires in addition to the usual input of the other kernels. This extra input required modifying the dispatcher and all related definitions. The adjoint-diff classes also need to carry controlled_wires around. All new gate kernels are implemented in GateImplementationsLM.hpp. The Python layer also differentiate between ControlledQubitUnitary operations and others for now.

Benefits:

  • Easier to add gate kernels in LM.
  • More gate supported in forward/backward mode.
  • Improved multi-controlled ops performance.

Screenshot from 2024-08-08 20-25-57

Possible Drawbacks:
Some gates might be slower, but benchmarks show that this is likely limited. For example, all non-controlled 1-qubit gates have the same performance.

Related GitHub Issues:

@github-actions
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.

@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (d165de1) 99.02% compared to head (7ef3bb7) 99.09%.

Files Patch % Lines
...rc/simulators/lightning_gpu/StateVectorCudaMPI.hpp 50.00% 2 Missing ⚠️
...imulators/lightning_gpu/StateVectorCudaManaged.hpp 50.00% 2 Missing ⚠️
...lators/lightning_qubit/gates/DynamicDispatcher.hpp 94.44% 2 Missing ⚠️
...ylane_lightning/lightning_qubit/lightning_qubit.py 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #516      +/-   ##
==========================================
+ Coverage   99.02%   99.09%   +0.06%     
==========================================
  Files         168      201      +33     
  Lines       23235    29202    +5967     
==========================================
+ Hits        23009    28937    +5928     
- Misses        226      265      +39     

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

@vincentmr vincentmr marked this pull request as ready for review October 12, 2023 14:08
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.

Nice job here! I left some comments and suggestions, but I think this is in very good shape.

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.

Looks good to me! Thanks @vincentmr for the nice work!

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.

Nothing more to add! Great work!

@vincentmr vincentmr merged commit a248328 into master Dec 8, 2023
83 checks passed
@vincentmr vincentmr deleted the sc-39665-support-arbitrary-controlled-operations-in branch December 8, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:use-multi-gpu-runner Enable usage of Multi-GPU runner for this Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants