Skip to content

Commit 5448c8a

Browse files
multiphaseCFDringo-but-quantumLuisAlfredoNumaliasadi
authored
Add exact tensor network C++ backend to LT (#977)
### 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`](../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`. - [x] Add a new entry to the `.github/CHANGELOG.md` file, 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:** [sc-72879] **Description of the Change:** **Benefits:** **Possible Drawbacks:** **Related GitHub Issues:** --------- Co-authored-by: ringo-but-quantum <[email protected]> Co-authored-by: Luis Alfredo Nuñez Meneses <[email protected]> Co-authored-by: Ali Asadi <[email protected]>
1 parent 17bf594 commit 5448c8a

30 files changed

+3516
-2726
lines changed

.github/CHANGELOG.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
### New features since last release
44

5-
* Add native N-controlled gate/matrix operations and adjoint support to `lightning.kokkos`.
6-
[(#950)](https://github.com/PennyLaneAI/pennylane-lightning/pull/950)
5+
* Add Exact Tensor Network C++ backend to `lightning.tensor`.
6+
[(#977)](https://github.com/PennyLaneAI/pennylane-lightning/pull/977)
77

88
* Add native N-controlled generators and adjoint support to `lightning.gpu`'s single-GPU backend.
99
[(#970)](https://github.com/PennyLaneAI/pennylane-lightning/pull/970)
@@ -12,6 +12,9 @@
1212
[(#960)](https://github.com/PennyLaneAI/pennylane-lightning/pull/960)
1313
[(#999)](https://github.com/PennyLaneAI/pennylane-lightning/pull/999)
1414

15+
* Add native N-controlled gate/matrix operations and adjoint support to `lightning.kokkos`.
16+
[(#950)](https://github.com/PennyLaneAI/pennylane-lightning/pull/950)
17+
1518
* Add native N-controlled gates support to `lightning.gpu`'s single-GPU backend.
1619
[(#938)](https://github.com/PennyLaneAI/pennylane-lightning/pull/938)
1720

@@ -55,6 +58,9 @@
5558
* Update Kokkos version support to 4.4.1 and enable Lightning-Kokkos[CUDA] C++ tests on CI.
5659
[(#1000)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1000)
5760

61+
* Add C++ unit tests for Exact Tensor Network backends.
62+
[(#998)](https://github.com/PennyLaneAI/pennylane-lightning/pull/998)
63+
5864
* Add native BLAS support to the C++ layer via dynamic `scipy-openblas32` loading.
5965
[(#995)](https://github.com/PennyLaneAI/pennylane-lightning/pull/995)
6066

CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ endif()
7272
foreach(BACKEND ${PL_BACKEND})
7373
message(STATUS "PL_BACKEND: ${BACKEND}")
7474
if("${BACKEND}" STREQUAL "lightning_tensor")
75-
set(PL_TENSOR_METHOD "mps" CACHE STRING "PennyLane LightningTensor MPS simulator.")
7675
set(PL_TENSOR_BACKEND "cutensornet" CACHE STRING "PennyLane LightningTensor backed by cutensornet")
77-
set(PL_TENSOR "${PL_BACKEND}_${PL_TENSOR_METHOD}_${PL_TENSOR_BACKEND}")
76+
set(PL_TENSOR "${PL_BACKEND}_${PL_TENSOR_BACKEND}")
7877
endif()
7978
endforeach()
8079

pennylane_lightning/core/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.40.0-dev30"
19+
__version__ = "0.40.0-dev31"

pennylane_lightning/core/src/simulators/lightning_tensor/tncuda/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ include("${pennylane_lightning_SOURCE_DIR}/cmake/support_pltensortncuda.cmake")
1717
findCUDATK(lightning_external_libs)
1818
findCutensornet(lightning_external_libs)
1919

20-
set(LTENSOR_MPS_FILES MPSTNCuda.cpp CACHE INTERNAL "" FORCE)
20+
set(LTENSOR_MPS_FILES MPSTNCuda.cpp ExactTNCuda.cpp MPOTNCuda.cpp CACHE INTERNAL "" FORCE)
2121

2222
add_library(${PL_BACKEND} STATIC ${LTENSOR_MPS_FILES})
2323

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2024 Xanadu Quantum Technologies Inc.
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "ExactTNCuda.hpp"
16+
17+
// explicit instantiation
18+
template class Pennylane::LightningTensor::TNCuda::ExactTNCuda<float>;
19+
template class Pennylane::LightningTensor::TNCuda::ExactTNCuda<double>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2024 Xanadu Quantum Technologies Inc.
2+
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file ExactTNCuda.hpp
17+
* ExactTN class with cuTensorNet backend. Note that current implementation only
18+
* support the open boundary condition.
19+
*/
20+
21+
#pragma once
22+
23+
#include <vector>
24+
25+
#include "DevTag.hpp"
26+
#include "TNCuda.hpp"
27+
#include "TNCudaBase.hpp"
28+
#include "TensorCuda.hpp"
29+
#include "Util.hpp"
30+
31+
/// @cond DEV
32+
namespace {
33+
using namespace Pennylane::LightningGPU;
34+
using namespace Pennylane::LightningTensor::TNCuda;
35+
using namespace Pennylane::LightningTensor::TNCuda::Util;
36+
} // namespace
37+
/// @endcond
38+
39+
namespace Pennylane::LightningTensor::TNCuda {
40+
41+
/**
42+
* @brief Managed memory Exact Tensor Network class using cutensornet high-level
43+
* APIs.
44+
*
45+
* @tparam Precision Floating-point precision type.
46+
*/
47+
48+
template <class Precision>
49+
class ExactTNCuda final : public TNCuda<Precision, ExactTNCuda<Precision>> {
50+
private:
51+
using BaseType = TNCuda<Precision, ExactTNCuda>;
52+
53+
public:
54+
constexpr static auto method = "exacttn";
55+
56+
using CFP_t = decltype(cuUtil::getCudaType(Precision{}));
57+
using ComplexT = std::complex<Precision>;
58+
using PrecisionT = Precision;
59+
60+
public:
61+
ExactTNCuda() = delete;
62+
63+
explicit ExactTNCuda(std::size_t numQubits) : BaseType(numQubits) {}
64+
65+
explicit ExactTNCuda(std::size_t numQubits, DevTag<int> dev_tag)
66+
: BaseType(numQubits, dev_tag) {}
67+
68+
~ExactTNCuda() = default;
69+
};
70+
} // namespace Pennylane::LightningTensor::TNCuda

0 commit comments

Comments
 (0)