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

Add stateprep support to lightning.tensor - MPS #849

Merged
merged 257 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 244 commits
Commits
Show all changes
257 commits
Select commit Hold shift + click to select a range
99c3b9e
Add GPU device compute capability check for LTensor (#803)
multiphaseCFD Jul 17, 2024
6da1e25
Auto update version from '0.38.0-dev10' to '0.38.0-dev11'
ringo-but-quantum Jul 17, 2024
9046199
Merge branch 'master' into add_var_tensornet
multiphaseCFD Jul 18, 2024
3877ebf
Auto update version from '0.38.0-dev11' to '0.38.0-dev12'
ringo-but-quantum Jul 18, 2024
1b12733
make format
multiphaseCFD Jul 18, 2024
afa67c9
add more complex Hermitian matrix
multiphaseCFD Jul 18, 2024
49e529f
add python and pybind layer
multiphaseCFD Jul 18, 2024
e97107e
add more py unit tests
multiphaseCFD Jul 18, 2024
85a9bd5
add more unit tests
multiphaseCFD Jul 18, 2024
93ff20f
add changelog
multiphaseCFD Jul 18, 2024
fa2c8fb
tidy up C++
multiphaseCFD Jul 18, 2024
0cdc3d0
further clean C++ layer
multiphaseCFD Jul 18, 2024
fca24d3
switch on more python unit tests
multiphaseCFD Jul 18, 2024
19dbedc
tidy up python layer
multiphaseCFD Jul 18, 2024
2737df1
tidy up linaralg and add more unit tests
multiphaseCFD Jul 18, 2024
976da4d
Add var support to multi-terms Hamiltionian
multiphaseCFD Jul 20, 2024
ad8d9bd
tidy up code
multiphaseCFD Jul 22, 2024
3ac6211
Auto update version from '0.38.0-dev12' to '0.38.0-dev13'
ringo-but-quantum Jul 22, 2024
255e341
remove square_matrix_cuda_device
multiphaseCFD Jul 22, 2024
7b44e8a
further tidy up
multiphaseCFD Jul 22, 2024
00beafa
fix typo
multiphaseCFD Jul 22, 2024
48f74b5
initial commit
multiphaseCFD Jul 15, 2024
cdb4606
Merge branch 'master' into add_var_tensornet
multiphaseCFD Jul 22, 2024
6afbc37
quick fix
multiphaseCFD Jul 22, 2024
8a588e6
Auto update version from '0.38.0-dev12' to '0.38.0-dev13'
ringo-but-quantum Jul 22, 2024
2103fa0
add more docstrings
multiphaseCFD Jul 22, 2024
bb85c54
typo fix
multiphaseCFD Jul 22, 2024
20113a0
add more unit tests
multiphaseCFD Jul 26, 2024
3f24ca2
Auto update version from '0.38.0-dev13' to '0.38.0-dev18'
ringo-but-quantum Jul 26, 2024
646e2e1
initial commit
multiphaseCFD Jul 15, 2024
635b469
Merge branch 'master' into add_var_tensornet
multiphaseCFD Jul 26, 2024
208e679
add more unit tests
multiphaseCFD Jul 26, 2024
194d87f
tidy up
multiphaseCFD Jul 26, 2024
6aeb802
initial commit
multiphaseCFD Jul 15, 2024
59b1ade
Merge branch 'master' into add_var_tensornet
multiphaseCFD Jul 26, 2024
408dcb2
revert changes
multiphaseCFD Jul 26, 2024
83c1316
Auto update version from '0.38.0-dev18' to '0.38.0-dev19'
ringo-but-quantum Jul 26, 2024
c83fa7a
remove some unit tests
multiphaseCFD Jul 26, 2024
afb2831
set ref result with 8 significant figures
multiphaseCFD Jul 26, 2024
1cdb538
update `ObservableTNCudaOperator`
multiphaseCFD Jul 29, 2024
c9d430e
Auto update version from '0.38.0-dev19' to '0.38.0-dev20'
ringo-but-quantum Jul 29, 2024
ea68235
unify private data for ObservableTNCudaOperator
multiphaseCFD Jul 29, 2024
03c2628
initial commit
multiphaseCFD Jul 15, 2024
2ea72e1
Merge branch 'master' into add_var_tensornet
multiphaseCFD Jul 29, 2024
b1aea01
revert some changes
multiphaseCFD Jul 29, 2024
89deb72
Auto update version from '0.38.0-dev20' to '0.38.0-dev21'
ringo-but-quantum Jul 29, 2024
7d1d669
initial commit
multiphaseCFD Jul 30, 2024
b893ac8
free resource
multiphaseCFD Jul 30, 2024
f770bdc
add prob support
multiphaseCFD Jul 31, 2024
e260a57
Auto update version from '0.38.0-dev21' to '0.38.0-dev22'
ringo-but-quantum Jul 31, 2024
e30ff89
update C++ unit tests and changelog
multiphaseCFD Jul 31, 2024
28f0b47
Auto update version from '0.38.0-dev21' to '0.38.0-dev22'
ringo-but-quantum Jul 31, 2024
fea0770
further tidy up the code
multiphaseCFD Jul 31, 2024
c69f0ba
update getPauliPauli with rotation of one Pauli
multiphaseCFD Jul 31, 2024
b283480
Merge branch 'master' into add_var_tensornet
multiphaseCFD Jul 31, 2024
42fe47e
Auto update version from '0.38.0-dev21' to '0.38.0-dev22'
ringo-but-quantum Jul 31, 2024
2e48869
Merge branch 'add_var_tensornet' into add_accessor_ltensor
multiphaseCFD Jul 31, 2024
7054b9c
update C++ unit tests and changelog
multiphaseCFD Jul 31, 2024
200c879
further tidy up the code
multiphaseCFD Jul 31, 2024
79af327
update getPauliPauli with rotation of one Pauli
multiphaseCFD Jul 31, 2024
d696534
Default `ENABLE_LAPACK` as `OFF` (#825)
multiphaseCFD Jul 30, 2024
012a545
Add paper to readme (#818)
mlxd Jul 31, 2024
bf838ee
make format
multiphaseCFD Jul 31, 2024
8f06f14
Merge branch 'add_accessor_ltensor' into add_probs_ltensor
multiphaseCFD Jul 31, 2024
4c031da
separate probs support from qml.state support
multiphaseCFD Jul 31, 2024
6b32079
revert more changes
multiphaseCFD Jul 31, 2024
15d0ae2
Trigger CIs
multiphaseCFD Jul 31, 2024
1944b36
update pybind11
multiphaseCFD Jul 31, 2024
2f9662b
update pybind11
multiphaseCFD Jul 31, 2024
b7ff938
enable test_comparison
multiphaseCFD Jul 31, 2024
4fba502
resolve more comments
multiphaseCFD Aug 1, 2024
4f62281
resolve more comments
multiphaseCFD Aug 1, 2024
b2c8c2b
further tidy up code
multiphaseCFD Aug 1, 2024
63cd387
refactor ObservableTNCudaOperator ctor
multiphaseCFD Aug 1, 2024
bf670fc
update python layer
multiphaseCFD Aug 1, 2024
cbb0d8d
mark pauli_map_ as static
multiphaseCFD Aug 1, 2024
7c35f9c
move two paulis obskey construction to helper methods as well
multiphaseCFD Aug 1, 2024
fb1d7bc
add unit tests to cover exceptions
multiphaseCFD Aug 1, 2024
aed4b48
Merge branch 'add_var_tensornet' into add_accessor_ltensor
multiphaseCFD Aug 1, 2024
6862e12
update python layer for qml.state support
multiphaseCFD Aug 1, 2024
90f9dc9
update python unit tests
multiphaseCFD Aug 1, 2024
8b2d7c0
make format
multiphaseCFD Aug 1, 2024
a67d7ed
Merge branch 'add_accessor_ltensor' into add_probs_ltensor
multiphaseCFD Aug 1, 2024
f462cd4
revert some changes
multiphaseCFD Aug 1, 2024
cdba823
limit scope of the implementation
multiphaseCFD Aug 1, 2024
f660c9a
update docs
multiphaseCFD Aug 1, 2024
b4c195e
add changelog entry
multiphaseCFD Aug 2, 2024
2d40477
remove _tensor_network from lighntningtensor device
multiphaseCFD Aug 2, 2024
aa1c72c
update `state_diagonalizing_gates`
multiphaseCFD Aug 2, 2024
7816085
Merge branch 'master' into add_accessor_ltensor
multiphaseCFD Aug 2, 2024
d34f4f1
Auto update version from '0.38.0-dev23' to '0.38.0-dev24'
ringo-but-quantum Aug 2, 2024
96af3aa
initial commit
multiphaseCFD Aug 2, 2024
ce99a1c
Merge branch 'refactor_mpstncuda_class' into add_accessor_ltensor
multiphaseCFD Aug 2, 2024
a181304
Revert "TOML files update (#826)"
multiphaseCFD Aug 2, 2024
799bfe2
Revert "initial commit"
multiphaseCFD Aug 2, 2024
b3d076e
Auto update version from '0.38.0-dev23' to '0.38.0-dev25'
ringo-but-quantum Aug 2, 2024
1a1e14f
turn on more pytests
multiphaseCFD Aug 2, 2024
86e41f0
revert some changes in test_execute.py
multiphaseCFD Aug 2, 2024
c21ee4e
revert some removers
multiphaseCFD Aug 2, 2024
d0f8e16
tidy up
multiphaseCFD Aug 2, 2024
2c8d1da
add memory check
multiphaseCFD Aug 2, 2024
29c1acd
Trigger CIs
multiphaseCFD Aug 2, 2024
708e680
update pytests
multiphaseCFD Aug 2, 2024
5d2aae4
make format
multiphaseCFD Aug 2, 2024
31d1e35
Auto update version from '0.38.0-dev25' to '0.38.0-dev26'
ringo-but-quantum Aug 2, 2024
ab04912
Fix sync issues with calls to CUSV APIs on aarch64 (#823)
mlxd Aug 2, 2024
daeb0e4
Auto update version from '0.38.0-dev25' to '0.38.0-dev26'
ringo-but-quantum Aug 2, 2024
eb49cdb
Merge branch 'master' into add_accessor_ltensor
multiphaseCFD Aug 2, 2024
ba4c216
Auto update version from '0.38.0-dev25' to '0.38.0-dev26'
ringo-but-quantum Aug 2, 2024
5f84ab6
tidy up code
multiphaseCFD Aug 2, 2024
48e7e37
add C++ unit tests
multiphaseCFD Aug 5, 2024
1a6a927
Auto update version from '0.38.0-dev22' to '0.38.0-dev26'
ringo-but-quantum Aug 5, 2024
f2c9a4b
Adding semantic-version to workflow reqs (#835)
PietropaoloFrisoni Aug 2, 2024
eca7f28
Add var support to LTensor (#804)
multiphaseCFD Aug 2, 2024
b72fd22
TOML files update (#826)
erick-xanadu Aug 2, 2024
044ece8
Fix sync issues with calls to CUSV APIs on aarch64 (#823)
mlxd Aug 2, 2024
740556f
Merge branch 'master' into add_probs_ltensor
multiphaseCFD Aug 5, 2024
2290fdb
Auto update version from '0.38.0-dev25' to '0.38.0-dev26'
ringo-but-quantum Aug 5, 2024
671b5c4
move cuda kernerls to measurements dir
multiphaseCFD Aug 5, 2024
7535284
add subset probs support
multiphaseCFD Aug 5, 2024
1f156db
add python layer
multiphaseCFD Aug 5, 2024
cb41d59
update python layer tests
multiphaseCFD Aug 5, 2024
51be722
Trigger CIs
multiphaseCFD Aug 5, 2024
3f8564f
fix typo
multiphaseCFD Aug 5, 2024
4e227f1
make format
multiphaseCFD Aug 5, 2024
02b8c9b
update C++ unit tests
multiphaseCFD Aug 6, 2024
36be238
add more docs
multiphaseCFD Aug 6, 2024
153cfdc
add docs
multiphaseCFD Aug 6, 2024
aa75832
update py layer unit tests
multiphaseCFD Aug 6, 2024
600e11b
make format
multiphaseCFD Aug 6, 2024
e2cc361
Trigger CIs
multiphaseCFD Aug 6, 2024
18b22c0
fix projectedModesvalue in C++
multiphaseCFD Aug 7, 2024
b8331dc
get prob by sum over all projected values
multiphaseCFD Aug 7, 2024
c551afe
udpate py layer unit tests
multiphaseCFD Aug 7, 2024
2968201
tidy up c++ layer
multiphaseCFD Aug 7, 2024
1181d5f
make format
multiphaseCFD Aug 7, 2024
41ff262
update python layer
multiphaseCFD Aug 7, 2024
48df242
move cublascaller to tncudabase class
multiphaseCFD Aug 7, 2024
f96d4d9
Merge branch 'add_accessor_ltensor' into add_probs_ltensor
multiphaseCFD Aug 7, 2024
75fa671
add `qml.prob(obs)` support
multiphaseCFD Aug 7, 2024
b8e1bb0
initial commit
multiphaseCFD Aug 8, 2024
bd13ad8
Merge branch 'master' into add_accessor_ltensor
multiphaseCFD Aug 8, 2024
29c43c3
Auto update version from '0.38.0-dev26' to '0.38.0-dev27'
ringo-but-quantum Aug 8, 2024
1c69f8f
revert some changes
multiphaseCFD Aug 8, 2024
486d5f2
resolve python layer comments
multiphaseCFD Aug 9, 2024
c7a27c5
update frontend
multiphaseCFD Aug 9, 2024
2ef61c1
add cudaStreamSynchronize()
multiphaseCFD Aug 9, 2024
a84a5c8
add more unit tests for 0,1 qubit circuit
multiphaseCFD Aug 9, 2024
377b6de
update docstring
multiphaseCFD Aug 9, 2024
4938835
add more py unit tests and avoid data copy in the pybind layer
multiphaseCFD Aug 9, 2024
4ab9999
remove cudaStreamSync
multiphaseCFD Aug 9, 2024
e95456b
decprecate `getDataVector()`
multiphaseCFD Aug 9, 2024
cb82ca5
update changelog entry
multiphaseCFD Aug 9, 2024
6477f0c
add more C+ layer tests
multiphaseCFD Aug 9, 2024
48d60d9
Merge branch 'master' into add_accessor_ltensor
multiphaseCFD Aug 9, 2024
733b97a
Auto update version from '0.38.0-dev28' to '0.38.0-dev29'
ringo-but-quantum Aug 9, 2024
11de2cf
revert getDataVector deprecation
multiphaseCFD Aug 12, 2024
27490e3
Merge branch 'add_accessor_ltensor' into add_probs_ltensor
multiphaseCFD Aug 12, 2024
841f8f1
update dummy_tensor_update()
multiphaseCFD Aug 12, 2024
9048b10
update methods in gate_cache
multiphaseCFD Aug 12, 2024
220082f
enable prob tests
multiphaseCFD Aug 12, 2024
7cbd065
initial commit
multiphaseCFD Aug 12, 2024
20fe756
init C++ commit
multiphaseCFD Aug 13, 2024
c7175cd
fix for _preprocess_state_vector
multiphaseCFD Aug 13, 2024
7eab726
tidy up code
multiphaseCFD Aug 13, 2024
e5cdbb6
move appendInitialMPSState_ to ctor to ensure one call only & make fo…
multiphaseCFD Aug 13, 2024
9e4d005
Trigger CI
multiphaseCFD Aug 13, 2024
14061f7
Auto update version from '0.38.0-dev29' to '0.38.0-dev31'
ringo-but-quantum Aug 13, 2024
dc687f0
Merge branch 'master' into add_probs_ltensor
multiphaseCFD Aug 13, 2024
59fe1b0
tidy up code
multiphaseCFD Aug 13, 2024
bced445
Auto update version from '0.38.0-dev31' to '0.38.0-dev32'
ringo-but-quantum Aug 13, 2024
87ac938
tidy up python layer
multiphaseCFD Aug 13, 2024
f8e5f48
add docstring
multiphaseCFD Aug 13, 2024
48db9a0
add changelog
multiphaseCFD Aug 13, 2024
5b4810b
fix typo
multiphaseCFD Aug 13, 2024
2085931
further tidy up the code
multiphaseCFD Aug 13, 2024
bcc41a1
fix typo
multiphaseCFD Aug 13, 2024
e104919
update docstring
multiphaseCFD Aug 13, 2024
f99b94e
add todo
multiphaseCFD Aug 13, 2024
d9fb3a3
Use `decomposition` instead of `Operator.expand` (#846)
astralcai Aug 12, 2024
36550e3
Update Lightning packaging to follow the PEP 517/518/621/660 standard…
AmintorDusko Aug 12, 2024
23eae79
Add `qml.state()` support to `lightning.tensor` (#827)
multiphaseCFD Aug 13, 2024
2e44739
tidy up code
multiphaseCFD Aug 13, 2024
3168eef
Auto update version from '0.38.0-dev31' to '0.38.0-dev32'
ringo-but-quantum Aug 13, 2024
2ba023f
tidy up python layer
multiphaseCFD Aug 13, 2024
9a51c7f
add docstring
multiphaseCFD Aug 13, 2024
d62cb9a
add changelog
multiphaseCFD Aug 13, 2024
64db2e7
fix typo
multiphaseCFD Aug 13, 2024
a9c2682
further tidy up the code
multiphaseCFD Aug 13, 2024
e8bbdf8
fix typo
multiphaseCFD Aug 13, 2024
2511d85
update docstring
multiphaseCFD Aug 13, 2024
7f27cfe
Merge branch 'add_probs_ltensor' into add_stateprep_ltensor
multiphaseCFD Aug 13, 2024
38b0db2
add more docstrings
multiphaseCFD Aug 13, 2024
3ebf1a0
tidy up code
multiphaseCFD Aug 13, 2024
5620b9e
tidy up code & turn on more python unit tests
multiphaseCFD Aug 13, 2024
18e311c
test
multiphaseCFD Aug 13, 2024
b84db90
update C++ unit tests
multiphaseCFD Aug 13, 2024
4e9c9fe
add changelog
multiphaseCFD Aug 13, 2024
3d873f0
update python docstring and make format
multiphaseCFD Aug 13, 2024
bac26ac
required cmake version to 3.26
multiphaseCFD Aug 13, 2024
9dc2ffb
change cmake version from 3.24 to 3.26
multiphaseCFD Aug 13, 2024
4a97ad9
revert some changes in py tests
multiphaseCFD Aug 13, 2024
f8834f4
Merge branch 'master' into add_probs_ltensor
multiphaseCFD Aug 13, 2024
e8f05a6
cmake 3.26->3.24
multiphaseCFD Aug 13, 2024
491d067
revert cmake 3.26 to 3.24
multiphaseCFD Aug 13, 2024
761450c
Auto update version from '0.38.0-dev32' to '0.38.0-dev33'
ringo-but-quantum Aug 13, 2024
464aba7
cmake 3.24
multiphaseCFD Aug 13, 2024
61206fc
enable cmake 3.24
multiphaseCFD Aug 13, 2024
4ae83ac
apply some Vincent's comments
multiphaseCFD Aug 19, 2024
c95bf1d
Auto update version from '0.38.0-dev33' to '0.38.0-dev36'
ringo-but-quantum Aug 19, 2024
052f215
apply more suggestions
multiphaseCFD Aug 19, 2024
e3b45ec
Auto update version from '0.38.0-dev36' to '0.38.0-dev37'
ringo-but-quantum Aug 19, 2024
b022021
Merge branch 'master' into add_probs_ltensor
multiphaseCFD Aug 19, 2024
73ba4a8
Auto update version from '0.38.0-dev36' to '0.38.0-dev37'
ringo-but-quantum Aug 19, 2024
87d1939
is_cache_empty->is_empty
multiphaseCFD Aug 19, 2024
d86fa35
update
multiphaseCFD Aug 19, 2024
1092fad
apply Vincent's comments
multiphaseCFD Aug 19, 2024
c337dc3
wrap update MPS sites into C++ layer
multiphaseCFD Aug 19, 2024
617acee
Update .github/CHANGELOG.md
multiphaseCFD Aug 20, 2024
c914297
Auto update version from '0.38.0-dev37' to '0.38.0-dev39'
ringo-but-quantum Aug 20, 2024
a6db6af
apply some Ali's suggestions
multiphaseCFD Aug 20, 2024
89a3815
run some calculations on cpu when the suset is small
multiphaseCFD Aug 20, 2024
b7706f2
add TODOs
multiphaseCFD Aug 20, 2024
23dc927
Merge branch 'master' into add_probs_ltensor
multiphaseCFD Aug 20, 2024
2aaaf65
Auto update version from '0.38.0-dev38' to '0.38.0-dev39'
ringo-but-quantum Aug 20, 2024
b014fbe
add unit tests for asum_CUDA_device
multiphaseCFD Aug 20, 2024
36546a5
update docstring
multiphaseCFD Aug 21, 2024
882cc77
Auto update version from '0.38.0-dev39' to '0.38.0-dev40'
ringo-but-quantum Aug 21, 2024
145c6d7
Update generate_samples in LK and LGPU to support qml.measurements.Sh…
maliasadi Aug 21, 2024
bce32f8
Auto update version from '0.38.0-dev39' to '0.38.0-dev40'
ringo-but-quantum Aug 21, 2024
6cfbe52
fix conflicts
multiphaseCFD Aug 21, 2024
2c4a0a7
Merge branch 'add_probs_ltensor' into add_stateprep_ltensor
multiphaseCFD Aug 21, 2024
fa1d08b
Merge branch 'master' into add_stateprep_ltensor
multiphaseCFD Aug 21, 2024
6308d6d
Auto update version from '0.38.0-dev40' to '0.38.0-dev41'
ringo-but-quantum Aug 21, 2024
2de2f26
fix codefactor complains
multiphaseCFD Aug 21, 2024
285e1c9
apply Vincent's comments
multiphaseCFD Aug 21, 2024
ff01e3e
Merge branch 'master' into add_stateprep_ltensor
multiphaseCFD Aug 21, 2024
6a92681
apply Ali's comments
multiphaseCFD Aug 21, 2024
0275d68
Auto update version from '0.38.0-dev41' to '0.38.0-dev42'
ringo-but-quantum Aug 21, 2024
4d5b690
pre-allocate Ms
multiphaseCFD Aug 21, 2024
1be48eb
Trigger CIs
multiphaseCFD Aug 21, 2024
96e65b2
add essential headers to unit tests
multiphaseCFD Aug 22, 2024
07ef802
Auto update version from '0.38.0-dev42' to '0.38.0-dev43'
ringo-but-quantum Aug 22, 2024
befbb0a
Bugfix Dockerfile + new build system (#863)
vincentmr Aug 22, 2024
be3fd9c
Auto update version from '0.38.0-dev42' to '0.38.0-dev43'
ringo-but-quantum Aug 22, 2024
3c94a01
Merge branch 'master' into add_stateprep_ltensor
multiphaseCFD Aug 22, 2024
737ca5b
Auto update version from '0.38.0-dev42' to '0.38.0-dev43'
ringo-but-quantum Aug 22, 2024
8ce797b
fix typo
multiphaseCFD Aug 22, 2024
8d7011e
Merge branch 'master' into add_stateprep_ltensor
multiphaseCFD Aug 22, 2024
86c1b82
Auto update version from '0.38.0-dev43' to '0.38.0-dev44'
ringo-but-quantum Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### New features since last release

* Add `qml.StatePrep()` and `qml.QubitStateVector()` support to `lightning.tensor`.
[(#849)](https://github.com/PennyLaneAI/pennylane-lightning/pull/849)

* Add LightningGPU Linux (aarch64+GraceHopper) wheels to PyPI.
[(#815)](https://github.com/PennyLaneAI/pennylane-lightning/pull/815)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MPSTNCuda final : public TNCudaBase<Precision, MPSTNCuda<Precision>> {
MPSStatus MPSInitialized_ = MPSStatus::MPSInitNotSet;

const std::size_t maxBondDim_;

const std::vector<std::size_t> bondDims_;
const std::vector<std::vector<std::size_t>> sitesModes_;
const std::vector<std::vector<std::size_t>> sitesExtents_;
const std::vector<std::vector<int64_t>> sitesExtents_int64_;
Expand All @@ -86,19 +86,25 @@ class MPSTNCuda final : public TNCudaBase<Precision, MPSTNCuda<Precision>> {
explicit MPSTNCuda(const std::size_t numQubits,
const std::size_t maxBondDim)
: BaseType(numQubits), maxBondDim_(maxBondDim),
sitesModes_(setSitesModes_()), sitesExtents_(setSitesExtents_()),
bondDims_(setBondDims_()), sitesModes_(setSitesModes_()),
sitesExtents_(setSitesExtents_()),
sitesExtents_int64_(setSitesExtents_int64_()) {
initTensors_();
reset();
appendInitialMPSState_();
}

// TODO: Add method to the constructor to allow users to select methods at
// runtime in the C++ layer
explicit MPSTNCuda(const std::size_t numQubits,
const std::size_t maxBondDim, DevTag<int> dev_tag)
: BaseType(numQubits, dev_tag), maxBondDim_(maxBondDim),
sitesModes_(setSitesModes_()), sitesExtents_(setSitesExtents_()),
bondDims_(setBondDims_()), sitesModes_(setSitesModes_()),
sitesExtents_(setSitesExtents_()),
sitesExtents_int64_(setSitesExtents_int64_()) {
initTensors_();
reset();
appendInitialMPSState_();
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
}

~MPSTNCuda() = default;
Expand Down Expand Up @@ -162,6 +168,31 @@ class MPSTNCuda final : public TNCudaBase<Precision, MPSTNCuda<Precision>> {
setBasisState(zeroState);
}

/**
* @brief Update the ith MPS site data.
*
* @param site_idx Index of the MPS site.
* @param host_data Pointer to the data on host.
* @param host_data_size Length of the data.
*/
void updateIthMPSSiteData(const std::size_t site_idx,
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
const ComplexT *host_data,
std::size_t host_data_size) {
PL_ABORT_IF_NOT(
site_idx < BaseType::getNumQubits(),
"The site index should be less than the number of qubits.");

const std::size_t idx = BaseType::getNumQubits() - site_idx - 1;
PL_ABORT_IF_NOT(
host_data_size == tensors_[idx].getDataBuffer().getLength(),
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
"The length of the host data should match its copy on the device.");

tensors_[idx].getDataBuffer().zeroInit();

tensors_[idx].getDataBuffer().CopyHostDataToGpu(host_data,
host_data_size);
}

/**
* @brief Update quantum state with a basis state.
* NOTE: This API assumes the bond vector is a standard basis vector
Expand Down Expand Up @@ -192,18 +223,13 @@ class MPSTNCuda final : public TNCudaBase<Precision, MPSTNCuda<Precision>> {
if (i == 0) {
target = basisState[idx];
} else {
target = basisState[idx] == 0 ? 0 : maxBondDim_;
target = basisState[idx] == 0 ? 0 : bondDims_[i - 1];
}

PL_CUDA_IS_SUCCESS(
cudaMemcpy(&tensors_[i].getDataBuffer().getData()[target],
&value_cu, sizeof(CFP_t), cudaMemcpyHostToDevice));
}

if (MPSInitialized_ == MPSStatus::MPSInitNotSet) {
MPSInitialized_ = MPSStatus::MPSInitSet;
updateQuantumStateMPS_();
}
};

/**
Expand Down Expand Up @@ -307,6 +333,27 @@ class MPSTNCuda final : public TNCudaBase<Precision, MPSTNCuda<Precision>> {
}

private:
/**
* @brief Return bondDims to the member initializer
* NOTE: This method only works for the open boundary condition
* @return std::vector<std::size_t>
*/
std::vector<std::size_t> setBondDims_() {
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
std::vector<std::size_t> localBondDims(BaseType::getNumQubits() - 1,
maxBondDim_);
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved

const std::size_t ubDim = log2(maxBondDim_);
for (std::size_t i = 0; i < localBondDims.size(); i++) {
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
const std::size_t bondDim =
std::min(i + 1, BaseType::getNumQubits() - i - 1);

if (bondDim <= ubDim) {
localBondDims[i] = std::size_t{1} << bondDim;
}
}
return localBondDims;
}

/**
* @brief Return siteModes to the member initializer
* NOTE: This method only works for the open boundary condition
Expand Down Expand Up @@ -348,15 +395,16 @@ class MPSTNCuda final : public TNCudaBase<Precision, MPSTNCuda<Precision>> {
if (i == 0) {
// Leftmost site (state mode, shared mode)
localSiteExtents = std::vector<std::size_t>(
{BaseType::getQubitDims()[i], maxBondDim_});
{BaseType::getQubitDims()[i], bondDims_[i]});
} else if (i == BaseType::getNumQubits() - 1) {
// Rightmost site (shared mode, state mode)
localSiteExtents = std::vector<std::size_t>(
{maxBondDim_, BaseType::getQubitDims()[i]});
{bondDims_[i - 1], BaseType::getQubitDims()[i]});
} else {
// Interior sites (state mode, state mode, shared mode)
localSiteExtents = std::vector<std::size_t>(
{maxBondDim_, BaseType::getQubitDims()[i], maxBondDim_});
{bondDims_[i - 1], BaseType::getQubitDims()[i],
bondDims_[i]});
}
localSitesExtents.push_back(std::move(localSiteExtents));
}
Expand Down Expand Up @@ -394,11 +442,11 @@ class MPSTNCuda final : public TNCudaBase<Precision, MPSTNCuda<Precision>> {
}

/**
* @brief Update quantumState (cutensornetState_t) with data provided by a
* user
* @brief Append initial MPS sites to the compute graph with data provided
* by a user
*
*/
void updateQuantumStateMPS_() {
void appendInitialMPSState_() {
PL_CUTENSORNET_IS_SUCCESS(cutensornetStateInitializeMPS(
/*const cutensornetHandle_t */ BaseType::getTNCudaHandle(),
/*cutensornetState_t*/ BaseType::getQuantumState(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ void registerBackendClassSpecificBindings(PyClass &pyclass) {
tensor_network.getData(data_ptr, state.size());
},
"Copy StateVector data into a Numpy array.")
.def(
"updateMPSSitesData",
[](TensorNet &tensor_network, std::vector<np_arr_c> &tensors) {
for (std::size_t idx = 0; idx < tensors.size(); idx++) {
py::buffer_info numpyArrayInfo = tensors[idx].request();
auto *data_ptr = static_cast<std::complex<PrecisionT> *>(
numpyArrayInfo.ptr);
tensor_network.updateIthMPSSiteData(idx, data_ptr,
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
tensors[idx].size());
}
},
"Pass MPS site data to the C++ backend")
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
.def(
"setBasisState",
[](TensorNet &tensor_network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ TEMPLATE_TEST_CASE("[PauliZ]", "[MPSTNCuda_Expval]", float, double) {
PrecisionT ref = -0.2115276040475712;

REQUIRE_THAT(res, Catch::Matchers::WithinRel(
ref, static_cast<PrecisionT>(cutoff)));
ref, static_cast<PrecisionT>(0.1)));
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,67 @@ TEMPLATE_PRODUCT_TEST_CASE("MPSTNCuda::Constructibility",
}
}

TEMPLATE_TEST_CASE("MPSTNCuda::setIthMPSSite", "[MPSTNCuda]", float, double) {
SECTION("Set MPS site with wrong site index") {
const std::size_t num_qubits = 3;
const std::size_t maxBondDim = 3;
const std::size_t siteIdx = 3;

MPSTNCuda<TestType> mps_state{num_qubits, maxBondDim};

std::vector<std::complex<TestType>> site_data(1, {0.0, 0.0});

REQUIRE_THROWS_WITH(
mps_state.updateIthMPSSiteData(siteIdx, site_data.data(),
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
site_data.size()),
Catch::Matchers::Contains(
"The site index should be less than the number of qubits."));
}

SECTION("Set MPS site with wrong site data size") {
const std::size_t num_qubits = 3;
const std::size_t maxBondDim = 3;
const std::size_t siteIdx = 0;

MPSTNCuda<TestType> mps_state{num_qubits, maxBondDim};

std::vector<std::complex<TestType>> site_data(1, {0.0, 0.0});

REQUIRE_THROWS_WITH(
mps_state.updateIthMPSSiteData(siteIdx, site_data.data(),
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
site_data.size()),
Catch::Matchers::Contains("The length of the host data should "
"match its copy on the device."));
}

SECTION("Set MPS sites") {
const std::size_t num_qubits = 2;
const std::size_t maxBondDim = 3;

MPSTNCuda<TestType> mps_state{num_qubits, maxBondDim};

mps_state.reset(); // Reset the state to zero state

std::vector<std::complex<TestType>> site0_data(4, {0.0, 0.0}); // MSB
std::vector<std::complex<TestType>> site1_data(4, {0.0, 0.0}); // LSB

site0_data[2] = {1.0, 0.0};
site1_data[1] = {1.0, 0.0};

mps_state.updateIthMPSSiteData(0, site0_data.data(), site0_data.size());
mps_state.updateIthMPSSiteData(1, site1_data.data(), site1_data.size());
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved

auto results = mps_state.getDataVector();

std::vector<std::complex<TestType>> expected_state(
std::size_t{1} << num_qubits, std::complex<TestType>({0.0, 0.0}));

expected_state[3] = {1.0, 0.0};

CHECK(expected_state == Pennylane::Util::approx(results));
}
}

TEMPLATE_TEST_CASE("MPSTNCuda::SetBasisStates() & reset()", "[MPSTNCuda]",
float, double) {
std::vector<std::vector<std::size_t>> basisStates = {
Expand Down
95 changes: 91 additions & 4 deletions pennylane_lightning/lightning_tensor/_tensornet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,52 @@
except ImportError:
pass

from itertools import product

import numpy as np
import pennylane as qml
from pennylane import BasisState, DeviceError, StatePrep
from pennylane.ops.op_math import Adjoint
from pennylane.tape import QuantumScript
from pennylane.wires import Wires


def svd_split(M, bond_dim):
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
"""SVD split a matrix into a matrix product state via numpy linalg. Note that this function is to be moved to the C++ layer."""
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
U, S, Vd = np.linalg.svd(M, full_matrices=False)
U = U @ np.diag(S) # Append singular values to U
bonds = len(S)
Vd = Vd.reshape(bonds, 2, -1)
U = U.reshape((-1, 2, bonds))

# keep only chi bonds
chi = np.min([bonds, bond_dim])
U, S, Vd = U[:, :, :chi], S[:chi], Vd[:chi]
return U, Vd


def dense_to_mps(psi, n_wires, bond_dim):
"""Convert a dense state vector to a matrix product state."""
Ms = []
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved

psi = np.reshape(psi, (2, -1)) # split psi[2, 2, 2, 2..] = psi[2, (2x2x2...)]
U, Vd = svd_split(psi, bond_dim) # psi[2, (2x2x..)] = U[2, mu] Vd[mu, (2x2x2x..)]

Ms.append(U)
bondL = Vd.shape[0]
psi = Vd

for _ in range(n_wires - 2):
psi = np.reshape(psi, (2 * bondL, -1)) # reshape psi[2 * bondL, (2x2x2...)]
U, Vd = svd_split(psi, bond_dim) # psi[2, (2x2x..)] = U[2, mu] Vd[mu, (2x2x2x..)]
Ms.append(U)

psi = Vd
bondL = Vd.shape[0]

Ms.append(Vd)

return Ms


# pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -112,6 +152,54 @@ def reset_state(self):
# init the quantum state to |00..0>
self._tensornet.reset()

def _preprocess_state_vector(self, state, device_wires):
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
"""Convert a specified state to a full internal state vector.

Args:
state (array[complex]): normalized input state of length ``2**len(wires)``
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
device_wires (Wires): wires that get initialized in the state

Returns:
array[complex]: normalized input state of length ``2**len(wires)``
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
"""
output_shape = [2] * self._num_wires
# special case for integral types
if state.dtype.kind == "i":
state = np.array(state, dtype=self.dtype)

if len(device_wires) == self._num_wires and Wires(sorted(device_wires)) == device_wires:
return np.reshape(state, output_shape).ravel(order="C")

# generate basis states on subset of qubits via the cartesian product
basis_states = np.array(list(product([0, 1], repeat=len(device_wires))))

# get basis states to alter on full set of qubits
unravelled_indices = np.zeros((2 ** len(device_wires), self._num_wires), dtype=int)
unravelled_indices[:, device_wires] = basis_states

# get indices for which the state is changed to input state vector elements
ravelled_indices = np.ravel_multi_index(unravelled_indices.T, [2] * self._num_wires)

# get full state vector to be factorized into MPS
full_state = np.zeros(2**self._num_wires, dtype=self.dtype)
for i, value in enumerate(state):
full_state[ravelled_indices[i]] = value
return np.reshape(full_state, output_shape).ravel(order="C")

def _apply_state_vector(self, state, device_wires: Wires):
"""Convert a specified state to MPS sites.
Args:
state (array[complex]): normalized input state of length ``2**len(wires)``
or broadcasted state of shape ``(batch_size, 2**len(wires))``
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
device_wires (Wires): wires that get initialized in the state
"""

state = self._preprocess_state_vector(state, device_wires)

M = dense_to_mps(state, self._num_wires, self._max_bond_dim)

self._tensornet.updateMPSSitesData(M)

def _apply_basis_state(self, state, wires):
"""Initialize the quantum state in a specified computational basis state.

Expand Down Expand Up @@ -177,10 +265,9 @@ def apply_operations(self, operations):
# State preparation is currently done in Python
if operations: # make sure operations[0] exists
if isinstance(operations[0], StatePrep):
raise DeviceError(
"lightning.tensor does not support initialization with a state vector."
)
if isinstance(operations[0], BasisState):
self._apply_state_vector(operations[0].parameters[0].copy(), operations[0].wires)
operations = operations[1:]
elif isinstance(operations[0], BasisState):
self._apply_basis_state(operations[0].parameters[0], operations[0].wires)
operations = operations[1:]

Expand Down
Loading
Loading