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

Refactor gate operations and add a new kernel for single qubit gates #202

Merged
merged 172 commits into from
Jan 21, 2022

Conversation

chaeyeunpark
Copy link
Contributor

@chaeyeunpark chaeyeunpark commented Dec 28, 2021

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: Previous implementation of gate operations is not well-performing. Thus it has been discussed to add an alternative implementation. This PR proposes a possible way to do it.

Description of the Change: Now, one can add an alternative kernel (gate implementations) relatively easily. I have also added a kernel with less memory bandwidth, which is faster for most gates.

Benefits: Faster gates. One can also add alternative kernels rather easily.

Possible Drawbacks: Some parts of the code get a bit complicated. Especially, template metaprogramming was unavoidable at some points. I hope to replace some of them in C++20.

Related GitHub Issues:

Sorry for making this giant PR...

@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 Dec 28, 2021

Codecov Report

Merging #202 (d729a74) into master (7515848) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head d729a74 differs from pull request most recent head baf81a0. Consider uploading reports for the commit baf81a0 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #202      +/-   ##
==========================================
+ Coverage   99.64%   99.65%   +0.01%     
==========================================
  Files           4        4              
  Lines         278      293      +15     
==========================================
+ Hits          277      292      +15     
  Misses          1        1              
Impacted Files Coverage Δ
pennylane_lightning/_serialize.py 100.00% <100.00%> (ø)
pennylane_lightning/lightning_qubit.py 99.51% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7515848...baf81a0. Read the comment docs.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 28, 2021

Test Report (C++) on Ubuntu

       1 files  ±    0         1 suites  ±0   0s ⏱️ ±0s
   294 tests  -   94     294 ✔️  -   94  0 💤 ±0  0 ±0 
2 677 runs  +430  2 677 ✔️ +430  0 💤 ±0  0 ±0 

Results for commit baf81a0. ± Comparison against base commit 7515848.

This pull request removes 287 and adds 193 tests. Note that renamed tests count towards both.
runner.global ‑ StateVector::StateVector - double/StateVector
runner.global ‑ StateVector::StateVector - double/StateVector<TestType> cross types
runner.global ‑ StateVector::StateVector - double/StateVector<TestType> {std::complex<TestType>, size_t}
runner.global ‑ StateVector::StateVector - double/StateVector<TestType> {}
runner.global ‑ StateVector::StateVector - float/StateVector
runner.global ‑ StateVector::StateVector - float/StateVector<TestType> cross types
runner.global ‑ StateVector::StateVector - float/StateVector<TestType> {std::complex<TestType>, size_t}
runner.global ‑ StateVector::StateVector - float/StateVector<TestType> {}
runner.global ‑ StateVector::applyCNOT - double/Apply directly
runner.global ‑ StateVector::applyCNOT - double/Apply using dispatcher
…
runner.global ‑ DynamicDispatcher::applyOperation - double
runner.global ‑ DynamicDispatcher::applyOperation - float
runner.global ‑ GateOperations::applyCNOT - GateOperationsLM<double>
runner.global ‑ GateOperations::applyCNOT - GateOperationsLM<float>
runner.global ‑ GateOperations::applyCNOT - GateOperationsPI<double>
runner.global ‑ GateOperations::applyCNOT - GateOperationsPI<float>
runner.global ‑ GateOperations::applyCRot - GateOperationsPI<double>/CRot0,1 |000> -> |000>
runner.global ‑ GateOperations::applyCRot - GateOperationsPI<double>/CRot0,1 |100> -> |1>(a|0>+b|1>)|0>
runner.global ‑ GateOperations::applyCRot - GateOperationsPI<float>/CRot0,1 |000> -> |000>
runner.global ‑ GateOperations::applyCRot - GateOperationsPI<float>/CRot0,1 |100> -> |1>(a|0>+b|1>)|0>
…

♻️ This comment has been updated with latest results.

@chaeyeunpark chaeyeunpark changed the title [WIP] Refactored gate operations andd added a new kernel for single qubit gates [WIP] Refactored gate operations and added a new kernel for single qubit gates Dec 28, 2021
@chaeyeunpark
Copy link
Contributor Author

Hi all, I applied most of the changes from the code review. For a few remaining issues, check my comments.

Copy link
Member

@mlxd mlxd 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 again @chaeyeunpark

I'd love to see a graph dropped here with the performance comparison of this PR against the current master using the kernel tests, as well as some workflow tests.

I think this is pretty much ready to approve (given the above, and the last few comments I made). I reckon it will be worth updating the architecture images and discussion on the docs in a following PR to account for the new structure.

.github/workflows/wheel_win_x86_64.yml Show resolved Hide resolved
.github/workflows/wheel_win_x86_64.yml Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
doc/add_kernel.rst Show resolved Hide resolved
doc/benchmark.rst Outdated Show resolved Hide resolved
pennylane_lightning/src/tests/TestHelpers.hpp Outdated Show resolved Hide resolved
pennylane_lightning/src/tests/TestHelpers.hpp Outdated Show resolved Hide resolved
pennylane_lightning/src/util/Util.hpp Show resolved Hide resolved
setup.py Show resolved Hide resolved
test.py Outdated Show resolved Hide resolved
@mlxd
Copy link
Member

mlxd commented Jan 18, 2022

For some reason, the docs do not generate the inheritance diagram https://pennylane-lightning--202.org.readthedocs.build/en/202/code/__init__.html#class-inheritance-diagram

I wonder if we need to explicitly install graphviz/dot or make some changes to the documentation build for this.

@mlxd mlxd requested a review from maliasadi January 18, 2022 10:07
@chaeyeunpark chaeyeunpark mentioned this pull request Jan 18, 2022
5 tasks
@chaeyeunpark
Copy link
Contributor Author

chaeyeunpark commented Jan 18, 2022

Hi @mlxd, I added graphviz dependency explicitly in requirements.txt and confs.py, but nothing changed. In fact, this is a problem from v0.20.0 (https://pennylane-lightning.readthedocs.io/en/v0.20.0/code/__init__.html). It is wiered as the only change was the header (qhack to carnival). Moreover, it just works well locally...

@chaeyeunpark
Copy link
Contributor Author

Aha. It was .readthedocs problem. I now fixed it.

@mlxd
Copy link
Member

mlxd commented Jan 18, 2022

Aha. It was .readthedocs problem. I now fixed it.

Great work on finding this! Happy to see this merged from my side.

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.

85 files reviewed 😄 nothing else to be added. Great job!

@mlxd
Copy link
Member

mlxd commented Jan 21, 2022

Once again, great work on this @chaeyeunpark
I may request we hold off the merge until we have a chat at our meeting today.

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 this pull request may close these issues.

3 participants