Skip to content

Commit 44c3c0e

Browse files
authored
Update the unification work required for the external package development (#482)
* Update interface link libs * Fix the include dir path * Auto update version * Update the accessibility of num_qubits_ * Update memory loc dispatch with LQ classes * Update changelog
1 parent e96a53f commit 44c3c0e

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

.github/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
* Add memory locality tag reporting and adjoint diff dispatch for `lightning.qubit` statevector classes.
2222
[(#492)](https://github.com/PennyLaneAI/pennylane-lightning/pull/492)
2323

24+
* Add support for dependent external packages to C++ core.
25+
[(#482)](https://github.com/PennyLaneAI/pennylane-lightning/pull/482)
26+
27+
2428
### Documentation
2529

2630
### Bug fixes
@@ -32,7 +36,7 @@
3236

3337
This release contains contributions from (in alphabetical order):
3438

35-
Vincent Michaud-Rioux, Lee J. O'Riordan
39+
Ali Asadi, Vincent Michaud-Rioux, Lee J. O'Riordan
3640

3741
---
3842

CMakeLists.txt

+14-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,21 @@ add_subdirectory(pennylane_lightning/core/src)
8989
#####################################################
9090
add_library(pennylane_lightning INTERFACE)
9191

92-
target_include_directories(pennylane_lightning INTERFACE "$<INSTALL_INTERFACE:${PROJECT_SOURCE_DIR}/pennylane_lightning/src;include>")
92+
target_link_libraries(pennylane_lightning INTERFACE lightning_observables
93+
lightning_utils
94+
lightning_algorithms
95+
)
96+
97+
target_link_libraries(pennylane_lightning INTERFACE ${PL_BACKEND} #simulator
98+
"${PL_BACKEND}_algorithms"
99+
"${PL_BACKEND}_observables"
100+
"${PL_BACKEND}_bindings"
101+
"${PL_BACKEND}_measurements"
102+
)
103+
104+
target_include_directories(pennylane_lightning INTERFACE "$<INSTALL_INTERFACE:${PROJECT_SOURCE_DIR}/pennylane_lightning/core/src;include>")
93105

106+
#####################################################
94107
if(ENABLE_PYTHON)
95108
message(STATUS "ENABLE_PYTHON is ON.")
96109
pybind11_add_module("${PL_BACKEND}_ops" "pennylane_lightning/core/src/bindings/Bindings.cpp")

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.33.0-dev4"
19+
__version__ = "0.33.0-dev5"

pennylane_lightning/core/src/simulators/base/StateVectorBase.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace Pennylane {
4141
* @tparam Derived Type of a derived class
4242
*/
4343
template <class PrecisionT, class Derived> class StateVectorBase {
44-
private:
44+
protected:
4545
size_t num_qubits_{0};
4646

4747
public:

pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp

+18-8
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,22 @@ class Measurements final
247247
auto expval(const Observable<StateVectorT> &ob) -> PrecisionT {
248248
PrecisionT result{};
249249

250-
if constexpr (std::is_same_v<StateVectorLQubitManaged<PrecisionT>,
251-
StateVectorT>) {
250+
if constexpr (std::is_same_v<typename StateVectorT::MemoryStorageT,
251+
MemoryStorageLocation::Internal>) {
252252
StateVectorT sv(this->_statevector);
253253
result = calculateObsExpval(sv, ob, this->_statevector);
254-
} else if constexpr (std::is_same_v<StateVectorLQubitRaw<PrecisionT>,
255-
StateVectorT>) {
254+
} else if constexpr (std::is_same_v<
255+
typename StateVectorT::MemoryStorageT,
256+
MemoryStorageLocation::External>) {
256257
std::vector<ComplexT> data_storage(
257258
this->_statevector.getData(),
258259
this->_statevector.getData() + this->_statevector.getLength());
259260
StateVectorT sv(data_storage.data(), data_storage.size());
260261
result = calculateObsExpval(sv, ob, this->_statevector);
262+
} else {
263+
/// LCOV_EXCL_START
264+
PL_ABORT("Undefined memory storage location for StateVectorT.");
265+
/// LCOV_EXCL_STOP
261266
}
262267

263268
return result;
@@ -271,18 +276,23 @@ class Measurements final
271276
*/
272277
auto var(const Observable<StateVectorT> &ob) -> PrecisionT {
273278
PrecisionT result{};
274-
if constexpr (std::is_same_v<StateVectorLQubitManaged<PrecisionT>,
275-
StateVectorT>) {
279+
if constexpr (std::is_same_v<typename StateVectorT::MemoryStorageT,
280+
MemoryStorageLocation::Internal>) {
276281
StateVectorT sv(this->_statevector);
277282
result = calculateObsVar(sv, ob, this->_statevector);
278283

279-
} else if constexpr (std::is_same_v<StateVectorLQubitRaw<PrecisionT>,
280-
StateVectorT>) {
284+
} else if constexpr (std::is_same_v<
285+
typename StateVectorT::MemoryStorageT,
286+
MemoryStorageLocation::External>) {
281287
std::vector<ComplexT> data_storage(
282288
this->_statevector.getData(),
283289
this->_statevector.getData() + this->_statevector.getLength());
284290
StateVectorT sv(data_storage.data(), data_storage.size());
285291
result = calculateObsVar(sv, ob, this->_statevector);
292+
} else {
293+
/// LCOV_EXCL_START
294+
PL_ABORT("Undefined memory storage location for StateVectorT.");
295+
/// LCOV_EXCL_STOP
286296
}
287297
return result;
288298
}

pennylane_lightning/core/src/simulators/lightning_qubit/observables/ObservablesLQubit.hpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ template <class StateVectorT, bool use_openmp> struct HamiltonianApplyInPlace {
159159
run(const std::vector<PrecisionT> &coeffs,
160160
const std::vector<std::shared_ptr<Observable<StateVectorT>>> &terms,
161161
StateVectorT &sv) {
162-
if constexpr (std::is_same_v<StateVectorLQubitManaged<PrecisionT>,
163-
StateVectorT>) {
162+
if constexpr (std::is_same_v<typename StateVectorT::MemoryStorageT,
163+
MemoryStorageLocation::Internal>) {
164164
auto allocator = sv.allocator();
165165
std::vector<ComplexT, decltype(allocator)> res(
166166
sv.getLength(), ComplexT{0.0, 0.0}, allocator);
@@ -171,8 +171,9 @@ template <class StateVectorT, bool use_openmp> struct HamiltonianApplyInPlace {
171171
tmp.getData(), res.data());
172172
}
173173
sv.updateData(res);
174-
} else if constexpr (std::is_same_v<StateVectorLQubitRaw<PrecisionT>,
175-
StateVectorT>) {
174+
} else if constexpr (std::is_same_v<
175+
typename StateVectorT::MemoryStorageT,
176+
MemoryStorageLocation::External>) {
176177
std::vector<ComplexT> res(sv.getLength(), ComplexT{0.0, 0.0});
177178
for (size_t term_idx = 0; term_idx < coeffs.size(); term_idx++) {
178179
std::vector<ComplexT> tmp_data_storage(
@@ -184,6 +185,10 @@ template <class StateVectorT, bool use_openmp> struct HamiltonianApplyInPlace {
184185
tmp.getData(), res.data());
185186
}
186187
sv.updateData(res);
188+
} else {
189+
/// LCOV_EXCL_START
190+
PL_ABORT("Undefined memory storage location for StateVectorT.");
191+
/// LCOV_EXCL_STOP
187192
}
188193
}
189194
};

0 commit comments

Comments
 (0)