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 shot measurement support to lightning.tensor #852

Merged
merged 329 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
329 commits
Select commit Hold shift + click to select a range
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
893db62
init commit
multiphaseCFD Aug 13, 2024
61206fc
enable cmake 3.24
multiphaseCFD Aug 13, 2024
d8baf39
disable cuda20 options
multiphaseCFD Aug 14, 2024
4c2e3ef
ensure target modes arranged in a correct order
multiphaseCFD Aug 14, 2024
0198b1a
add unit tests
multiphaseCFD Aug 14, 2024
381bb70
Auto update version from '0.38.0-dev32' to '0.38.0-dev33'
ringo-but-quantum Aug 14, 2024
e01ac31
add support to subset sampling
multiphaseCFD Aug 14, 2024
f90f174
python layer tests
multiphaseCFD Aug 14, 2024
f0cb5c0
make format
multiphaseCFD Aug 14, 2024
a9bb807
fix python layer unit tests failures
multiphaseCFD Aug 14, 2024
611921f
Further tidy up
multiphaseCFD Aug 14, 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
1a8dad4
Merge branch 'add_stateprep_ltensor' into add_sample_ltensor
multiphaseCFD Aug 21, 2024
e79bbb3
tidy up code
multiphaseCFD Aug 21, 2024
0b215c3
add changelog and tidy up code
multiphaseCFD Aug 21, 2024
503b6dc
update `stopping_condition_shots`
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
a94692d
Merge branch 'add_stateprep_ltensor' into add_sample_ltensor
multiphaseCFD Aug 22, 2024
c19ae82
fix typo
multiphaseCFD Aug 22, 2024
0d73d9a
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Aug 23, 2024
a3b536b
Auto update version from '0.38.0-dev45' to '0.38.0-dev46'
ringo-but-quantum Aug 23, 2024
eeff190
update cpp layer
multiphaseCFD Aug 28, 2024
5b4f530
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Aug 28, 2024
35e639c
Auto update version from '0.38.0-dev51' to '0.38.0-dev52'
ringo-but-quantum Aug 28, 2024
f804724
add more measurement tests
multiphaseCFD Aug 28, 2024
74c4d88
more unit tests
multiphaseCFD Aug 28, 2024
3bbec62
make format
multiphaseCFD Aug 28, 2024
6fdd8a8
add more unit tests in py layer
multiphaseCFD Aug 28, 2024
d8a5379
remove uneccessary py code
multiphaseCFD Aug 28, 2024
7416d7e
remove uneccessary checks
multiphaseCFD Aug 28, 2024
d85f40d
add more pytests
multiphaseCFD Aug 28, 2024
91cede0
fix codeFactor
multiphaseCFD Aug 28, 2024
0c31ac5
revert some changes
multiphaseCFD Aug 29, 2024
cb244e0
set a larger tolerance for fp32 computation
multiphaseCFD Aug 29, 2024
671f196
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Aug 30, 2024
aee9223
Auto update version from '0.38.0-dev52' to '0.38.0-dev53'
ringo-but-quantum Aug 30, 2024
0664ada
Optimize gate cache recording for `lightning.tensor` (#879)
multiphaseCFD Aug 30, 2024
8491e1f
Version Bump (#884)
github-actions[bot] Sep 3, 2024
ea55422
Migration of LightningKokkos to the new device API (#810)
LuisAlfredoNu Sep 4, 2024
f403f70
Update/actions (#887)
AmintorDusko Sep 4, 2024
3b0a4c5
Correctly querying wire IDs for `SetState` and `SetBasisState` in L-K…
vincentmr Sep 5, 2024
b07f00a
Auto update version from '0.39.0-dev3' to '0.39.0-dev4'
ringo-but-quantum Sep 5, 2024
d611c77
quick update
multiphaseCFD Sep 5, 2024
f62e08c
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Sep 6, 2024
b7d05ac
tidy up changlog
multiphaseCFD Sep 6, 2024
b8512c4
fix merge errors
multiphaseCFD Sep 6, 2024
b9e42a0
add samples_to_decimal to testhelpers
multiphaseCFD Sep 6, 2024
c994a40
update python unit tests
multiphaseCFD Sep 7, 2024
83f5ca8
Auto update version from '0.39.0-dev5' to '0.39.0-dev7'
ringo-but-quantum Sep 7, 2024
3534e5b
set all control_values identical
multiphaseCFD Sep 7, 2024
fe7beae
tidy up tests
multiphaseCFD Sep 7, 2024
e167f73
fix codefactor
multiphaseCFD Sep 7, 2024
316ffea
fix version conflicts
multiphaseCFD Sep 7, 2024
0914e65
Auto update version from '0.39.0-dev6' to '0.39.0-dev7'
ringo-but-quantum Sep 7, 2024
59ca3d3
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Sep 7, 2024
81f0e65
update measurements class
multiphaseCFD Sep 9, 2024
14c06cc
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Sep 9, 2024
cdfa141
Auto update version from '0.39.0-dev7' to '0.39.0-dev8'
ringo-but-quantum Sep 9, 2024
f666a99
remove _measurement_ham
multiphaseCFD Sep 9, 2024
566c6dd
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Sep 9, 2024
a03d962
Auto update version from '0.39.0-dev8' to '0.39.0-dev9'
ringo-but-quantum Sep 9, 2024
8c2f0a9
make format
multiphaseCFD Sep 9, 2024
8f0dbf6
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Sep 9, 2024
545e802
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Sep 10, 2024
1b774c1
apply Ali's suggestions
multiphaseCFD Sep 10, 2024
f5135ff
Auto update version from '0.39.0-dev13' to '0.39.0-dev16'
ringo-but-quantum Sep 10, 2024
caefc15
tidy up python layer unit tests
multiphaseCFD Sep 10, 2024
72aab04
Auto update version from '0.39.0-dev16' to '0.39.0-dev17'
ringo-but-quantum Sep 10, 2024
3073213
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Sep 10, 2024
700a78e
Auto update version from '0.39.0-dev16' to '0.39.0-dev17'
ringo-but-quantum Sep 10, 2024
9fb0f11
tidy up code & make format
multiphaseCFD Sep 10, 2024
df21991
fix typos
multiphaseCFD Sep 11, 2024
0bc73b6
Auto update version from '0.39.0-dev17' to '0.39.0-dev18'
ringo-but-quantum Sep 11, 2024
ec79928
Merge branch 'master' into add_sample_ltensor
multiphaseCFD Sep 11, 2024
70fd413
Auto update version from '0.39.0-dev17' to '0.39.0-dev18'
ringo-but-quantum Sep 11, 2024
2e6e70a
Update pennylane_lightning/core/src/utils/TestHelpers.hpp
multiphaseCFD Sep 11, 2024
a440d86
update py unit tests
multiphaseCFD Sep 11, 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 shot measurement support to `lightning.tensor`.
[(#852)](https://github.com/PennyLaneAI/pennylane-lightning/pull/852)

* Build and upload Lightning-Tensor wheels (x86_64, AARCH64) to PyPI.
[(#862)](https://github.com/PennyLaneAI/pennylane-lightning/pull/862)

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.39.0-dev17"
__version__ = "0.39.0-dev18"
21 changes: 20 additions & 1 deletion pennylane_lightning/core/src/bindings/Bindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,26 @@ void registerLightningTensorBackendAgnosticMeasurements(PyClass &pyclass) {
[](MeasurementsT &M, const std::shared_ptr<ObservableT> &ob) {
return M.var(*ob);
},
"Variance of an observable object.");
"Variance of an observable object.")
.def("generate_samples", [](MeasurementsT &M,
const std::vector<std::size_t> &wires,
const std::size_t num_shots) {
const std::size_t num_wires = wires.size();
auto &&result = M.generate_samples(wires, num_shots);
const std::size_t ndim = 2;
const std::vector<std::size_t> shape{num_shots, num_wires};
constexpr auto sz = sizeof(std::size_t);
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
const std::vector<std::size_t> strides{sz * num_wires, sz};
// return 2-D NumPy array
return py::array(py::buffer_info(
result.data(), /* data as contiguous array */
sz, /* size of one scalar */
py::format_descriptor<std::size_t>::format(), /* data type */
ndim, /* number of dimensions */
shape, /* shape of the matrix */
strides /* strides for each axis */
));
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#pragma once

#include <algorithm>
#include <complex>
#include <cuComplex.h>
#include <cutensornet.h>
Expand Down Expand Up @@ -164,6 +165,97 @@ template <class TensorNetT> class MeasurementsTNCuda {
return h_res;
}

/**
* @brief Utility method for samples.
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
*
* @param wires Wires can be a subset or the full system.
* @param num_samples Number of samples
* @param numHyperSamples Number of hyper samples to use in the calculation
* and is default as 1.
*
* @return std::vector<std::size_t> A 1-d array storing the samples.
* Each sample has a length equal to the number of wires. Each sample can
* be accessed using the stride `sample_id * num_wires`, where `sample_id`
* is a number between `0` and `num_samples - 1`.
*/
auto generate_samples(const std::vector<std::size_t> &wires,
const std::size_t num_samples,
const int32_t numHyperSamples = 1)
-> std::vector<std::size_t> {
std::vector<int64_t> samples(num_samples * wires.size());
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved

const std::vector<int32_t> modesToSample =
cuUtil::NormalizeCastIndices<std::size_t, int32_t>(
wires, tensor_network_.getNumQubits());

cutensornetStateSampler_t sampler;

PL_CUTENSORNET_IS_SUCCESS(cutensornetCreateSampler(
/* const cutensornetHandle_t */ tensor_network_.getTNCudaHandle(),
/* cutensornetState_t */ tensor_network_.getQuantumState(),
/* int32_t numModesToSample */ modesToSample.size(),
/* const int32_t *modesToSample */ modesToSample.data(),
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
/* cutensornetStateSampler_t * */ &sampler));

// Configure the quantum circuit sampler
const cutensornetSamplerAttributes_t samplerAttributes =
CUTENSORNET_SAMPLER_CONFIG_NUM_HYPER_SAMPLES;

PL_CUTENSORNET_IS_SUCCESS(cutensornetSamplerConfigure(
/* const cutensornetHandle_t */ tensor_network_.getTNCudaHandle(),
/* cutensornetStateSampler_t */ sampler,
/* cutensornetSamplerAttributes_t */ samplerAttributes,
/* const void *attributeValue */ &numHyperSamples,
/* size_t attributeSize */ sizeof(numHyperSamples)));

cutensornetWorkspaceDescriptor_t workDesc;
PL_CUTENSORNET_IS_SUCCESS(cutensornetCreateWorkspaceDescriptor(
/* const cutensornetHandle_t */ tensor_network_.getTNCudaHandle(),
/* cutensornetWorkspaceDescriptor_t * */ &workDesc));

const std::size_t scratchSize = cuUtil::getFreeMemorySize() / 2;

// Prepare the quantum circuit sampler for sampling
PL_CUTENSORNET_IS_SUCCESS(cutensornetSamplerPrepare(
/* const cutensornetHandle_t */ tensor_network_.getTNCudaHandle(),
/* cutensornetStateSampler_t */ sampler,
/* size_t maxWorkspaceSizeDevice */ scratchSize,
/* cutensornetWorkspaceDescriptor_t */ workDesc,
/* cudaStream_t unused as of v24.08 */ 0x0));

std::size_t worksize =
getWorkSpaceMemorySize(tensor_network_.getTNCudaHandle(), workDesc);

PL_ABORT_IF(worksize > scratchSize,
"Insufficient workspace size on Device.\n");

const std::size_t d_scratch_length = worksize / sizeof(size_t) + 1;
DataBuffer<std::size_t> d_scratch(d_scratch_length,
tensor_network_.getDevTag(), true);

setWorkSpaceMemory(tensor_network_.getTNCudaHandle(), workDesc,
reinterpret_cast<void *>(d_scratch.getData()),
worksize);

PL_CUTENSORNET_IS_SUCCESS(cutensornetSamplerSample(
/* const cutensornetHandle_t */ tensor_network_.getTNCudaHandle(),
/* cutensornetStateSampler_t */ sampler,
/* int64_t numShots */ num_samples,
/* cutensornetWorkspaceDescriptor_t */ workDesc,
/* int64_t * */ samples.data(),
/* cudaStream_t unused as of v24.08 */ 0x0));
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved

PL_CUTENSORNET_IS_SUCCESS(
cutensornetDestroyWorkspaceDescriptor(workDesc));
PL_CUTENSORNET_IS_SUCCESS(cutensornetDestroySampler(sampler));

std::vector<std::size_t> samples_size_t(samples.size());

std::transform(samples.begin(), samples.end(), samples_size_t.begin(),
[](int64_t x) { return static_cast<std::size_t>(x); });
return samples_size_t;
}

/**
* @brief Calculate var value for a general ObservableTNCuda Observable.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
#include "MPSTNCuda.hpp"
#include "MeasurementsTNCuda.hpp"
#include "TNCudaGateCache.hpp"
#include "TestHelpers.hpp"
#include "cuda_helpers.hpp"

/// @cond DEV
namespace {
using namespace Pennylane::LightningTensor::TNCuda::Measures;
using namespace Pennylane::LightningTensor::TNCuda::Observables;
using namespace Pennylane::LightningTensor::TNCuda;
using namespace Pennylane::Util;
} // namespace
/// @endcond

Expand Down Expand Up @@ -92,3 +94,47 @@ TEMPLATE_TEST_CASE("Probabilities", "[Measures]", float, double) {
REQUIRE_THROWS_AS(measure.probs({2, 1}), LightningException);
}
}

TEMPLATE_TEST_CASE("Samples", "[Measures]", float, double) {
using TensorNetT = MPSTNCuda<TestType>;

SECTION("Looping over different wire configurations:") {
// Probabilities calculated with Pennylane default.qubit:
std::vector<TestType> expected_probabilities = {
0.67078706, 0.03062806, 0.0870997, 0.00397696,
0.17564072, 0.00801973, 0.02280642, 0.00104134};

// Defining the State Vector that will be measured.
std::size_t bondDim = GENERATE(4, 5);
std::size_t num_qubits = 3;
std::size_t maxBondDim = bondDim;

TensorNetT mps_state{num_qubits, maxBondDim};

mps_state.applyOperations(
{{"RX"}, {"RX"}, {"RY"}, {"RY"}, {"RX"}, {"RY"}},
{{0}, {0}, {1}, {1}, {2}, {2}},
{{false}, {false}, {false}, {false}, {false}, {false}},
{{0.5}, {0.5}, {0.2}, {0.2}, {0.5}, {0.5}});
mps_state.append_mps_final_state();

auto measure = MeasurementsTNCuda<TensorNetT>(mps_state);

std::size_t num_samples = 100000;
const std::vector<std::size_t> wires = {0, 1, 2};
auto samples = measure.generate_samples(wires, num_samples);
auto counts = samples_to_decimal(samples, num_qubits, num_samples);

// compute estimated probabilities from histogram
std::vector<TestType> probabilities(counts.size());
for (std::size_t i = 0; i < counts.size(); i++) {
probabilities[i] = counts[i] / static_cast<TestType>(num_samples);
}

// compare estimated probabilities to real probabilities
SECTION("No wires provided:") {
REQUIRE_THAT(probabilities,
Catch::Approx(expected_probabilities).margin(.1));
}
}
}
29 changes: 29 additions & 0 deletions pennylane_lightning/core/src/utils/TestHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,35 @@ auto randomUnitary(RandomEngine &re, std::size_t num_qubits)
return res;
}

inline auto samples_to_decimal(const std::vector<std::size_t> &samples,
const std::size_t num_qubits,
const std::size_t num_samples)
-> std::vector<std::size_t> {
constexpr uint32_t twos[] = {
1U << 0U, 1U << 1U, 1U << 2U, 1U << 3U, 1U << 4U, 1U << 5U,
1U << 6U, 1U << 7U, 1U << 8U, 1U << 9U, 1U << 10U, 1U << 11U,
1U << 12U, 1U << 13U, 1U << 14U, 1U << 15U, 1U << 16U, 1U << 17U,
1U << 18U, 1U << 19U, 1U << 20U, 1U << 21U, 1U << 22U, 1U << 23U,
1U << 24U, 1U << 25U, 1U << 26U, 1U << 27U, 1U << 28U, 1U << 29U,
1U << 30U, 1U << 31U};

std::size_t N = std::pow(2, num_qubits);
std::vector<std::size_t> counts(N, 0);
std::vector<std::size_t> samples_decimal(num_samples, 0);

// convert samples to decimal and then bin them in counts
for (std::size_t i = 0; i < num_samples; i++) {
for (std::size_t j = 0; j < num_qubits; j++) {
if (samples[i * num_qubits + j] != 0) {
samples_decimal[i] += twos[(num_qubits - 1 - j)];
multiphaseCFD marked this conversation as resolved.
Show resolved Hide resolved
}
}
counts[samples_decimal[i]] += 1;
}

return counts;
}

#define PL_REQUIRE_THROWS_MATCHES(expr, type, message_match) \
REQUIRE_THROWS_AS(expr, type); \
REQUIRE_THROWS_WITH(expr, Catch::Matchers::Contains(message_match));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20)

project(lightning_gpu_utils_tests)
project(cuda_utils_tests)

# Default build type for test code is Debug
if(NOT CMAKE_BUILD_TYPE)
Expand Down
Loading
Loading