diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index b165f9e656..f772718e86 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -21,6 +21,10 @@ * Add memory locality tag reporting and adjoint diff dispatch for `lightning.qubit` statevector classes. [(#492)](https://github.com/PennyLaneAI/pennylane-lightning/pull/492) +* Add support for dependent external packages to C++ core. + [(#482)](https://github.com/PennyLaneAI/pennylane-lightning/pull/482) + + ### Documentation ### Bug fixes @@ -32,7 +36,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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8047cca61f..45d1b41ee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,8 +89,21 @@ add_subdirectory(pennylane_lightning/core/src) ##################################################### add_library(pennylane_lightning INTERFACE) -target_include_directories(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") 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" 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: 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 } } };