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

Fix applyMatrix in lightning.gpu #932

Merged
merged 4 commits into from
Oct 3, 2024
Merged

Conversation

multiphaseCFD
Copy link
Member

@multiphaseCFD multiphaseCFD commented Oct 3, 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:

[SC-74899]

lightning.gpu stores gate data to a unordered_map object. The gate data can be accessed with a key (opsName, Param) . This design can avoid the excessive data copy between the device and host. However, the way a matrix gate is stored causes the bug since lightning.gpu will only add first matrix data to the cache since the keys of all matrix will be the same ({},{}) pair. Following applyMatrix calls will just result in getting data from the cache and the matrix used for operation will be always the first matrix. This bug will cause errors at least when applying TensorProd with multiple Hermitian obs.

To fix it, we will not store the matrix data to the gate cache and just copy it from host to device on-the-fly.

Description of the Change:

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@multiphaseCFD multiphaseCFD marked this pull request as ready for review October 3, 2024 13:56
@multiphaseCFD multiphaseCFD added bug-fix Indicates this fixes a known bug ci:use-gpu-runner Enable usage of GPU runner for this Pull Request ci:use-multi-gpu-runner Enable usage of Multi-GPU runner for this Pull Request ci:build_wheels Activate wheel building. labels Oct 3, 2024
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.98%. Comparing base (133ab15) to head (27fbec0).
Report is 60 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #932      +/-   ##
==========================================
+ Coverage   96.41%   96.98%   +0.56%     
==========================================
  Files         215      132      -83     
  Lines       28165    17055   -11110     
==========================================
- Hits        27155    16540   -10615     
+ Misses       1010      515     -495     

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

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.

LGTM, only a few questions.
Thank you @multiphaseCFD

@josephleekl
Copy link
Contributor

Looks good to me! Thanks @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 @multiphaseCFD
Nice work finding the 🐛

@multiphaseCFD multiphaseCFD merged commit fdf09bc into master Oct 3, 2024
91 checks passed
@multiphaseCFD multiphaseCFD deleted the fix_apply_matrix_lgpu branch October 3, 2024 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix Indicates this fixes a known bug ci:build_wheels Activate wheel building. ci:use-gpu-runner Enable usage of GPU runner for this Pull Request 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