Skip to content

Commit

Permalink
Add exact tensor network C++ backend to LT (#977)
Browse files Browse the repository at this point in the history
### 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]>
  • Loading branch information
4 people authored Dec 5, 2024
1 parent 17bf594 commit 5448c8a
Show file tree
Hide file tree
Showing 30 changed files with 3,516 additions and 2,726 deletions.
10 changes: 8 additions & 2 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

### New features since last release

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

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

* Add native N-controlled gate/matrix operations and adjoint support to `lightning.kokkos`.
[(#950)](https://github.com/PennyLaneAI/pennylane-lightning/pull/950)

* Add native N-controlled gates support to `lightning.gpu`'s single-GPU backend.
[(#938)](https://github.com/PennyLaneAI/pennylane-lightning/pull/938)

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

* Add C++ unit tests for Exact Tensor Network backends.
[(#998)](https://github.com/PennyLaneAI/pennylane-lightning/pull/998)

* Add native BLAS support to the C++ layer via dynamic `scipy-openblas32` loading.
[(#995)](https://github.com/PennyLaneAI/pennylane-lightning/pull/995)

Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ endif()
foreach(BACKEND ${PL_BACKEND})
message(STATUS "PL_BACKEND: ${BACKEND}")
if("${BACKEND}" STREQUAL "lightning_tensor")
set(PL_TENSOR_METHOD "mps" CACHE STRING "PennyLane LightningTensor MPS simulator.")
set(PL_TENSOR_BACKEND "cutensornet" CACHE STRING "PennyLane LightningTensor backed by cutensornet")
set(PL_TENSOR "${PL_BACKEND}_${PL_TENSOR_METHOD}_${PL_TENSOR_BACKEND}")
set(PL_TENSOR "${PL_BACKEND}_${PL_TENSOR_BACKEND}")
endif()
endforeach()

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.40.0-dev30"
__version__ = "0.40.0-dev31"
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include("${pennylane_lightning_SOURCE_DIR}/cmake/support_pltensortncuda.cmake")
findCUDATK(lightning_external_libs)
findCutensornet(lightning_external_libs)

set(LTENSOR_MPS_FILES MPSTNCuda.cpp CACHE INTERNAL "" FORCE)
set(LTENSOR_MPS_FILES MPSTNCuda.cpp ExactTNCuda.cpp MPOTNCuda.cpp CACHE INTERNAL "" FORCE)

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2024 Xanadu Quantum Technologies Inc.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "ExactTNCuda.hpp"

// explicit instantiation
template class Pennylane::LightningTensor::TNCuda::ExactTNCuda<float>;
template class Pennylane::LightningTensor::TNCuda::ExactTNCuda<double>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2024 Xanadu Quantum Technologies Inc.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file ExactTNCuda.hpp
* ExactTN class with cuTensorNet backend. Note that current implementation only
* support the open boundary condition.
*/

#pragma once

#include <vector>

#include "DevTag.hpp"
#include "TNCuda.hpp"
#include "TNCudaBase.hpp"
#include "TensorCuda.hpp"
#include "Util.hpp"

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

namespace Pennylane::LightningTensor::TNCuda {

/**
* @brief Managed memory Exact Tensor Network class using cutensornet high-level
* APIs.
*
* @tparam Precision Floating-point precision type.
*/

template <class Precision>
class ExactTNCuda final : public TNCuda<Precision, ExactTNCuda<Precision>> {
private:
using BaseType = TNCuda<Precision, ExactTNCuda>;

public:
constexpr static auto method = "exacttn";

using CFP_t = decltype(cuUtil::getCudaType(Precision{}));
using ComplexT = std::complex<Precision>;
using PrecisionT = Precision;

public:
ExactTNCuda() = delete;

explicit ExactTNCuda(std::size_t numQubits) : BaseType(numQubits) {}

explicit ExactTNCuda(std::size_t numQubits, DevTag<int> dev_tag)
: BaseType(numQubits, dev_tag) {}

~ExactTNCuda() = default;
};
} // namespace Pennylane::LightningTensor::TNCuda
Loading

0 comments on commit 5448c8a

Please sign in to comment.