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

Update the unification work required for the external package development #482

Merged
merged 10 commits into from
Sep 7, 2023
6 changes: 5 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

---

Expand Down
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,21 @@ add_subdirectory(pennylane_lightning/core/src)
#####################################################
add_library(pennylane_lightning INTERFACE)

target_include_directories(pennylane_lightning INTERFACE "$<INSTALL_INTERFACE:${PROJECT_SOURCE_DIR}/pennylane_lightning/src;include>")
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 "$<INSTALL_INTERFACE:${PROJECT_SOURCE_DIR}/pennylane_lightning/core/src;include>")

#####################################################
if(ENABLE_PYTHON)
message(STATUS "ENABLE_PYTHON is ON.")
pybind11_add_module("${PL_BACKEND}_ops" "pennylane_lightning/core/src/bindings/Bindings.cpp")
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.33.0-dev4"
__version__ = "0.33.0-dev5"
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Pennylane {
* @tparam Derived Type of a derived class
*/
template <class PrecisionT, class Derived> class StateVectorBase {
private:
protected:
size_t num_qubits_{0};

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,22 @@ class Measurements final
auto expval(const Observable<StateVectorT> &ob) -> PrecisionT {
PrecisionT result{};

if constexpr (std::is_same_v<StateVectorLQubitManaged<PrecisionT>,
StateVectorT>) {
if constexpr (std::is_same_v<typename StateVectorT::MemoryStorageT,
MemoryStorageLocation::Internal>) {
StateVectorT sv(this->_statevector);
result = calculateObsExpval(sv, ob, this->_statevector);
} else if constexpr (std::is_same_v<StateVectorLQubitRaw<PrecisionT>,
StateVectorT>) {
} else if constexpr (std::is_same_v<
typename StateVectorT::MemoryStorageT,
MemoryStorageLocation::External>) {
std::vector<ComplexT> 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;
Expand All @@ -271,18 +276,23 @@ class Measurements final
*/
auto var(const Observable<StateVectorT> &ob) -> PrecisionT {
PrecisionT result{};
if constexpr (std::is_same_v<StateVectorLQubitManaged<PrecisionT>,
StateVectorT>) {
if constexpr (std::is_same_v<typename StateVectorT::MemoryStorageT,
MemoryStorageLocation::Internal>) {
StateVectorT sv(this->_statevector);
result = calculateObsVar(sv, ob, this->_statevector);

} else if constexpr (std::is_same_v<StateVectorLQubitRaw<PrecisionT>,
StateVectorT>) {
} else if constexpr (std::is_same_v<
typename StateVectorT::MemoryStorageT,
MemoryStorageLocation::External>) {
std::vector<ComplexT> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ template <class StateVectorT, bool use_openmp> struct HamiltonianApplyInPlace {
run(const std::vector<PrecisionT> &coeffs,
const std::vector<std::shared_ptr<Observable<StateVectorT>>> &terms,
StateVectorT &sv) {
if constexpr (std::is_same_v<StateVectorLQubitManaged<PrecisionT>,
StateVectorT>) {
if constexpr (std::is_same_v<typename StateVectorT::MemoryStorageT,
MemoryStorageLocation::Internal>) {
auto allocator = sv.allocator();
std::vector<ComplexT, decltype(allocator)> res(
sv.getLength(), ComplexT{0.0, 0.0}, allocator);
Expand All @@ -171,8 +171,9 @@ template <class StateVectorT, bool use_openmp> struct HamiltonianApplyInPlace {
tmp.getData(), res.data());
}
sv.updateData(res);
} else if constexpr (std::is_same_v<StateVectorLQubitRaw<PrecisionT>,
StateVectorT>) {
} else if constexpr (std::is_same_v<
typename StateVectorT::MemoryStorageT,
MemoryStorageLocation::External>) {
std::vector<ComplexT> res(sv.getLength(), ComplexT{0.0, 0.0});
for (size_t term_idx = 0; term_idx < coeffs.size(); term_idx++) {
std::vector<ComplexT> tmp_data_storage(
Expand All @@ -184,6 +185,10 @@ template <class StateVectorT, bool use_openmp> struct HamiltonianApplyInPlace {
tmp.getData(), res.data());
}
sv.updateData(res);
} else {
/// LCOV_EXCL_START
PL_ABORT("Undefined memory storage location for StateVectorT.");
/// LCOV_EXCL_STOP
}
}
};
Expand Down
Loading