pennylane-lightning
pennylane-lightning copied to clipboard
Add `MPSTNCuda` class
Before submitting
Please complete the following checklist when submitting a PR:
-
[x] 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
testsdirectory! -
[ ] 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. -
[x] Ensure that the test suite passes, by running
make test. -
[x] Add a new entry to the
.github/CHANGELOG.mdfile, summarizing the change, and including a link back to the PR. -
[x] 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:
This PR adds MPSCutn C++ class which manages cutensornet high-level C++ APIs.
Description of the Change:
MPSCutn class:
- Current design allows user to set the
maxBondDimfor the MPS representation. More controls option on the MPS representation, likecutoffofSVD configures, will be added when introducingcutensornetStateConfigure()API, once theapplyGates()orcircuit_build()is done. setBasisState(std::vector<size_t>& basisState)initializes/sets the MPS quantum state. Please note thatsetBasisState()can be only called once. This is the reason why there is protectedMPSInitialized_flag in theCutnBaseclass. Note that current implementation onsetBasisState(std::vector<size_t>& basisState)only works for qubit systems, which means the dimension of physical site is2, like ourstatevectorbackends.reset()will update the MPS quantum state tozeroState. We can call eitherreset()orsetBasisState()once, sincereset()will callsetBasisState()under the hood. IMPORTANT: this intrinsic feature could impact the design of theMeasurementclass.getDataVector()will return the full state vector. This is a feature only for C++ unit tests.cutensornetHandle,cutensornetState_tare managed by theCutnBaseclass. Methods, likecircuit_buildmaybe, that can be shared by bothMPSandExact Tensor Networkmethods will live in theCutnBaseclass.
Tensor classes:
TensorBaseclass wraps basic information likerank,length,modesandextentsof a tensor.CudaTensorinherits fromTensorBaseclass and wraps aDataBufferobject that manages the tensor data on device.
Benefits:
Possible Drawbacks:
Related GitHub Issues:
Codecov Report
Attention: Patch coverage is 99.64158% with 1 lines in your changes are missing coverage. Please review.
Project coverage is 97.97%. Comparing base (
29fa26c) to head (a653027).
| Files | Patch % | Lines |
|---|---|---|
| .../simulators/lightning_tensor/tncuda/TNCudaBase.hpp | 97.67% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #704 +/- ##
==========================================
+ Coverage 95.68% 97.97% +2.28%
==========================================
Files 72 134 +62
Lines 8815 19348 +10533
==========================================
+ Hits 8435 18956 +10521
- Misses 380 392 +12
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Thanks for the hard work @multiphaseCFD . I'm leaving comments, questions and suggestions in places, but there is one design issue I would like to address. It seems the current PR implements tensor classes and simulators classes which will also act as tensor network classes. I think we should have tensor, tensor network and simulator classes, where tensor networks keep track of tensors and simulators keep track of circuit execution. This may not be a 100% clear from the ADR, but it is implied. This is also how the old prototypes, the Python device and Quimb circuit classes work. Ok, maybe I read that wrong and this is where we are going, but I just want to make sure.
As discussed, we will stick to the current implementation since cuTensorNet lib unify the implementation of exact tensor network and matrix product state simulation.
Will update the cutn to CudaTN and move this PR to v0.37 in the changelog once all reviewers give green lights for other comments @mlxd @vincentmr @maliasadi
[sc-61945]
Thanks @AmintorDusko ! Good question! I plan to add those branch with the progress of the project since it's still not clear how can we deal with the measurement module to make it compatible for both sv and tensor backend at least cutensornet backend. Per cutensornet backend, we can build both mps and exatn at the same time.
Hey @multiphaseCFD! Nice work! Quick non-blocking general question. I see that along the building procedure you branched out the Lightning non-tensor libraries. Any special reason for that? Will LightningTensor still build if we add the Lightning libraries? I'm wondering if we would be able to build both backends at the same time (LightningQubit and LightningTensor). Also, do you see as possible to install LightningTensor with more than one backend at the same time?
Thanks @AmintorDusko ! Good question! I plan to add those branch with the progress of the project since it's still not clear how can we deal with the measurement module to make it compatible for both sv and tensor backend at least
cutensornetbackend. Percutensornetbackend, we can build bothmpsandexatnat the same time.Hey @multiphaseCFD! Nice work! Quick non-blocking general question. I see that along the building procedure you branched out the Lightning non-tensor libraries. Any special reason for that? Will LightningTensor still build if we add the Lightning libraries? I'm wondering if we would be able to build both backends at the same time (LightningQubit and LightningTensor). Also, do you see as possible to install LightningTensor with more than one backend at the same time?
Thank you very much!