From 5dbb659f60705e9daa477e18a043337c7fdc35c1 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Tue, 22 Aug 2023 16:06:14 -0400 Subject: [PATCH 1/8] Update interface link libs --- CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8047cca61f..d0303b433a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,8 +89,21 @@ add_subdirectory(pennylane_lightning/core/src) ##################################################### add_library(pennylane_lightning INTERFACE) +target_link_libraries(pennylane_lightning INTERFACE lightning_observables + lightning_utils + lightning_algorithms + ) + +target_link_libraries(pennylane_lightning INTERFACE ${PL_BACKEND} #simulator + "${PL_BACKEND}_algorithms" + "${PL_BACKEND}_observables" + "${PL_BACKEND}_bindings" + "${PL_BACKEND}_measurements" +) + target_include_directories(pennylane_lightning INTERFACE "$") +##################################################### if(ENABLE_PYTHON) message(STATUS "ENABLE_PYTHON is ON.") pybind11_add_module("${PL_BACKEND}_ops" "pennylane_lightning/core/src/bindings/Bindings.cpp") From a7fcf1dafe848417c8d535b2c838af709e732a98 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Thu, 7 Sep 2023 09:53:55 -0400 Subject: [PATCH 2/8] Fix the include dir path --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0303b433a..45d1b41ee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ target_link_libraries(pennylane_lightning INTERFACE ${PL_BACKEND} #simulator "${PL_BACKEND}_measurements" ) -target_include_directories(pennylane_lightning INTERFACE "$") +target_include_directories(pennylane_lightning INTERFACE "$") ##################################################### if(ENABLE_PYTHON) From fbcd579aa1682fa3b25d4c755ed763998b9b2a9d Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Thu, 7 Sep 2023 13:55:31 +0000 Subject: [PATCH 3/8] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 57254db4dd..22113c5ec6 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.33.0-dev3" +__version__ = "0.33.0-dev4" From a60b5cb64af0f8051bdbf25e088fe85b2cc20d32 Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Thu, 7 Sep 2023 14:54:15 +0000 Subject: [PATCH 4/8] Auto update version --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 22113c5ec6..6bdc5af6c6 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.33.0-dev4" +__version__ = "0.33.0-dev5" From 2d747bd959781ef65de1f2975e123b6857193768 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Thu, 7 Sep 2023 12:21:32 -0400 Subject: [PATCH 5/8] Update the accessibility of num_qubits_ --- .../core/src/simulators/base/StateVectorBase.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/src/simulators/base/StateVectorBase.hpp b/pennylane_lightning/core/src/simulators/base/StateVectorBase.hpp index 10704386d2..727447f8e6 100644 --- a/pennylane_lightning/core/src/simulators/base/StateVectorBase.hpp +++ b/pennylane_lightning/core/src/simulators/base/StateVectorBase.hpp @@ -41,7 +41,7 @@ namespace Pennylane { * @tparam Derived Type of a derived class */ template class StateVectorBase { - private: + protected: size_t num_qubits_{0}; public: From 5856aa85c7ecdc1194ef947041c7a51404ce9bba Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Thu, 7 Sep 2023 12:32:52 -0400 Subject: [PATCH 6/8] Update memory loc dispatch with LQ classes --- .../measurements/MeasurementsLQubit.hpp | 26 +++++++++++++------ .../observables/ObservablesLQubit.hpp | 13 +++++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp b/pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp index 91b6f44f48..534e00d112 100644 --- a/pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp @@ -247,17 +247,22 @@ class Measurements final auto expval(const Observable &ob) -> PrecisionT { PrecisionT result{}; - if constexpr (std::is_same_v, - StateVectorT>) { + if constexpr (std::is_same_v) { StateVectorT sv(this->_statevector); result = calculateObsExpval(sv, ob, this->_statevector); - } else if constexpr (std::is_same_v, - StateVectorT>) { + } else if constexpr (std::is_same_v< + typename StateVectorT::MemoryStorageT, + MemoryStorageLocation::External>) { std::vector data_storage( this->_statevector.getData(), this->_statevector.getData() + this->_statevector.getLength()); StateVectorT sv(data_storage.data(), data_storage.size()); result = calculateObsExpval(sv, ob, this->_statevector); + } else { + /// LCOV_EXCL_START + PL_ABORT("Undefined memory storage location for StateVectorT."); + /// LCOV_EXCL_STOP } return result; @@ -271,18 +276,23 @@ class Measurements final */ auto var(const Observable &ob) -> PrecisionT { PrecisionT result{}; - if constexpr (std::is_same_v, - StateVectorT>) { + if constexpr (std::is_same_v) { StateVectorT sv(this->_statevector); result = calculateObsVar(sv, ob, this->_statevector); - } else if constexpr (std::is_same_v, - StateVectorT>) { + } else if constexpr (std::is_same_v< + typename StateVectorT::MemoryStorageT, + MemoryStorageLocation::External>) { std::vector data_storage( this->_statevector.getData(), this->_statevector.getData() + this->_statevector.getLength()); StateVectorT sv(data_storage.data(), data_storage.size()); result = calculateObsVar(sv, ob, this->_statevector); + } else { + /// LCOV_EXCL_START + PL_ABORT("Undefined memory storage location for StateVectorT."); + /// LCOV_EXCL_STOP } return result; } diff --git a/pennylane_lightning/core/src/simulators/lightning_qubit/observables/ObservablesLQubit.hpp b/pennylane_lightning/core/src/simulators/lightning_qubit/observables/ObservablesLQubit.hpp index 2aac1282db..3433a3fcc3 100644 --- a/pennylane_lightning/core/src/simulators/lightning_qubit/observables/ObservablesLQubit.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_qubit/observables/ObservablesLQubit.hpp @@ -159,8 +159,8 @@ template struct HamiltonianApplyInPlace { run(const std::vector &coeffs, const std::vector>> &terms, StateVectorT &sv) { - if constexpr (std::is_same_v, - StateVectorT>) { + if constexpr (std::is_same_v) { auto allocator = sv.allocator(); std::vector res( sv.getLength(), ComplexT{0.0, 0.0}, allocator); @@ -171,8 +171,9 @@ template struct HamiltonianApplyInPlace { tmp.getData(), res.data()); } sv.updateData(res); - } else if constexpr (std::is_same_v, - StateVectorT>) { + } else if constexpr (std::is_same_v< + typename StateVectorT::MemoryStorageT, + MemoryStorageLocation::External>) { std::vector res(sv.getLength(), ComplexT{0.0, 0.0}); for (size_t term_idx = 0; term_idx < coeffs.size(); term_idx++) { std::vector tmp_data_storage( @@ -184,6 +185,10 @@ template struct HamiltonianApplyInPlace { tmp.getData(), res.data()); } sv.updateData(res); + } else { + /// LCOV_EXCL_START + PL_ABORT("Undefined memory storage location for StateVectorT."); + /// LCOV_EXCL_STOP } } }; From bf910040a39f3c68ca7541dff5af1be5d738a3ac Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Thu, 7 Sep 2023 13:20:26 -0400 Subject: [PATCH 7/8] Update changelog --- .github/CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index b165f9e656..1d6e76922b 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -20,6 +20,11 @@ * Add memory locality tag reporting and adjoint diff dispatch for `lightning.qubit` statevector classes. [(#492)](https://github.com/PennyLaneAI/pennylane-lightning/pull/492) + [(#482)](https://github.com/PennyLaneAI/pennylane-lightning/pull/482) + +* Add support for dependent external packages to C++ core. + [(#482)](https://github.com/PennyLaneAI/pennylane-lightning/pull/482) + ### Documentation @@ -32,7 +37,7 @@ This release contains contributions from (in alphabetical order): -Vincent Michaud-Rioux, Lee J. O'Riordan +Ali Asadi, Vincent Michaud-Rioux, Lee J. O'Riordan --- From 60aad8b807c7e9fdc23e0d0a340b122a470c4828 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Thu, 7 Sep 2023 13:26:06 -0400 Subject: [PATCH 8/8] Update changelog --- .github/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 1d6e76922b..f772718e86 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -20,7 +20,6 @@ * Add memory locality tag reporting and adjoint diff dispatch for `lightning.qubit` statevector classes. [(#492)](https://github.com/PennyLaneAI/pennylane-lightning/pull/492) - [(#482)](https://github.com/PennyLaneAI/pennylane-lightning/pull/482) * Add support for dependent external packages to C++ core. [(#482)](https://github.com/PennyLaneAI/pennylane-lightning/pull/482)