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

Feature/lkokkos mpi #747

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
20bffe2
Add lightning bin.
vincentmr Mar 20, 2024
86d1af0
Add LKMPI class.
vincentmr Mar 20, 2024
a952e74
WIP try to init SVMPI.
vincentmr Mar 20, 2024
7e2d146
Make SVK attr of SVKMPI.
vincentmr Mar 20, 2024
c9d0946
getDataVector deals with mpi_gather.
vincentmr Mar 20, 2024
d0d79d6
Add is_wires_local.
vincentmr Mar 21, 2024
67b3032
Check that local H works.
vincentmr Mar 21, 2024
125e852
Validate global H gate.
vincentmr Mar 21, 2024
e691581
Add support for all 1q-gates and tests.
vincentmr Mar 22, 2024
eae8d6a
Add Rot and 1q-matrix tests.
vincentmr Mar 22, 2024
c9adc34
Add transpose (optionally conjugated) in UtilLinearAlg.hpp
vincentmr Mar 22, 2024
521571d
mpi_requests are function arguments; WIP CNOT.
vincentmr Mar 22, 2024
8811f2d
Test 2q-global gates.
vincentmr Mar 25, 2024
b6bd5c7
Fix global2q gates.
vincentmr Mar 25, 2024
a48b281
Merge remote-tracking branch 'origin/feature/generic_gate_functor' in…
vincentmr Mar 25, 2024
4c09d99
applySemiLocal2QOperation WIP
vincentmr Mar 25, 2024
f5d42b8
2q gates work.
vincentmr Mar 25, 2024
578ae03
Make recvbuf_ an SV and add doc.
vincentmr Mar 25, 2024
7d470ca
Add setStateVector implementation.
vincentmr Mar 25, 2024
388ae4c
Remove SV dep on LKObs/Meas.
vincentmr Mar 25, 2024
60ea15c
Add 1q obs support and tests.
vincentmr Mar 25, 2024
c954670
Add bindings WIP.
vincentmr Mar 25, 2024
4f9501b
Add bindings for HostToDevice.
vincentmr Mar 26, 2024
bce6d40
Add MPI var implementations and bindings.
vincentmr Mar 26, 2024
b8f4911
Add GPU support WIP.
vincentmr Mar 26, 2024
73c619e
Make std::unique_ptr<SVK> sendbuf_ and use aux view in isend for GPU …
vincentmr Mar 26, 2024
8ff4bea
Add bench scripts.
vincentmr Mar 26, 2024
7732c74
Mod make_plot and add OpenMP data.
vincentmr Mar 26, 2024
36191b3
Add OpenMP data.
vincentmr Mar 26, 2024
2416b00
Add hybrid data.
vincentmr Mar 26, 2024
3478c8f
Add cuda data
vincentmr Mar 26, 2024
79ecac9
Add generator support for SVKMPI.
vincentmr Mar 27, 2024
bbb869b
Add adjoint support.
vincentmr Mar 27, 2024
fb7adcc
Add USE_MPI switch in basic_circuit to compare jacobian results.
vincentmr Mar 27, 2024
c4b49ff
Minor basic_circuit mod.
vincentmr Mar 27, 2024
80cb08e
Simplify macro usage.
vincentmr Mar 27, 2024
659f1ff
Simplify initzeros/setbasisstate
vincentmr Mar 27, 2024
f09dc17
Skip few ops if matrix == 0.
vincentmr Mar 28, 2024
26cd65c
Move function.
vincentmr Mar 28, 2024
dc2da0e
Refactor setStateVector.
vincentmr Mar 28, 2024
2359274
Update basic_circuit
vincentmr Mar 28, 2024
cc15f3d
Fix setBasisState.
vincentmr Apr 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/support_kokkos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Include this file only once
include_guard()

set(KOKKOS_VERSION 4.2.00)
set(KOKKOS_VERSION 4.2.01)

# Macro to aid in finding Kokkos with 3 potential install options:
# 1. Fully integrated Kokkos packages and CMake module files
Expand Down
8 changes: 2 additions & 6 deletions mpitests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -1396,9 +1396,7 @@ def test_qubit_unitary(dev, n_targets):

np.random.seed(1337)
par = 2 * np.pi * np.random.rand(n_wires)
U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand(
2**n_targets, 2**n_targets
)
U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand(2**n_targets, 2**n_targets)
U, _ = np.linalg.qr(U)
init_state = np.random.rand(2**n_wires) + 1j * np.random.rand(2**n_wires)
init_state /= np.sqrt(np.dot(np.conj(init_state), init_state))
Expand Down Expand Up @@ -1446,9 +1444,7 @@ def test_diff_qubit_unitary(dev, n_targets):

np.random.seed(1337)
par = 2 * np.pi * np.random.rand(n_wires)
U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand(
2**n_targets, 2**n_targets
)
U = np.random.rand(2**n_targets, 2**n_targets) + 1j * np.random.rand(2**n_targets, 2**n_targets)
U, _ = np.linalg.qr(U)
init_state = np.random.rand(2**n_wires) + 1j * np.random.rand(2**n_wires)
init_state /= np.sqrt(np.dot(np.conj(init_state), init_state))
Expand Down
4 changes: 1 addition & 3 deletions pennylane_lightning/core/_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ def serialize_observables(self, tape: QuantumTape, wires_map: dict = None) -> Li
offset_indices.append(offset_indices[-1] + 1)
return serialized_obs, offset_indices

def serialize_ops(
self, tape: QuantumTape, wires_map: dict = None
) -> Tuple[
def serialize_ops(self, tape: QuantumTape, wires_map: dict = None) -> Tuple[
List[List[str]],
List[np.ndarray],
List[List[int]],
Expand Down
10 changes: 10 additions & 0 deletions pennylane_lightning/core/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ if (BUILD_TESTS)
FetchAndIncludeCatch()

include(CTest)
endif()

##########################
## Create project target #
##########################

if (ENABLE_MPI)
add_executable(lightning lightning.cpp)
target_link_libraries(lightning pennylane_lightning)
set_property(TARGET lightning PROPERTY CXX_STANDARD 20)
endif()
73 changes: 42 additions & 31 deletions pennylane_lightning/core/src/bindings/Bindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ using namespace Pennylane::LightningQubit::Measures;

#include "AdjointJacobianKokkos.hpp"
#include "LKokkosBindings.hpp" // StateVectorBackends, registerBackendClassSpecificBindings, registerBackendSpecificMeasurements, registerBackendSpecificAlgorithms
#include "MeasurementsKokkos.hpp"
#include "ObservablesKokkos.hpp"
#if _ENABLE_MPI == 1
#include "MeasurementsKokkosMPI.hpp"
#else
#include "MeasurementsKokkos.hpp"
#endif

/// @cond DEV
namespace {
Expand Down Expand Up @@ -97,6 +101,11 @@ namespace {
using Pennylane::Util::bestCPUMemoryModel;
using Pennylane::Util::CPUMemoryModel;
using Pennylane::Util::getMemoryModel;
#if _ENABLE_PLKOKKOS == 1 && _ENABLE_MPI == 1
template <class T> using measure = MeasurementsMPI<T>;
#else
template <class T> using measure = Measurements<T>;
#endif
} // namespace
/// @endcond

Expand Down Expand Up @@ -426,48 +435,50 @@ void registerBackendAgnosticMeasurements(PyClass &pyclass) {
using PrecisionT =
typename StateVectorT::PrecisionT; // Statevector's precision.
using ParamT = PrecisionT; // Parameter's data precision

using measureT = measure<StateVectorT>;
pyclass
.def("probs",
[](Measurements<StateVectorT> &M,
const std::vector<size_t> &wires) {
return py::array_t<ParamT>(py::cast(M.probs(wires)));
})
.def("probs",
[](Measurements<StateVectorT> &M) {
return py::array_t<ParamT>(py::cast(M.probs()));
})
.def(
"expval",
[](Measurements<StateVectorT> &M,
[](measureT &M,
const std::shared_ptr<Observable<StateVectorT>> &ob) {
return M.expval(*ob);
},
"Expected value of an observable object.")
.def(
"var",
[](Measurements<StateVectorT> &M,
[](measureT &M,
const std::shared_ptr<Observable<StateVectorT>> &ob) {
return M.var(*ob);
},
"Variance of an observable object.")
.def("generate_samples", [](Measurements<StateVectorT> &M,
size_t num_wires, size_t num_shots) {
auto &&result = M.generate_samples(num_shots);
const size_t ndim = 2;
const std::vector<size_t> shape{num_shots, num_wires};
constexpr auto sz = sizeof(size_t);
const std::vector<size_t> strides{sz * num_wires, sz};
// return 2-D NumPy array
return py::array(py::buffer_info(
result.data(), /* data as contiguous array */
sz, /* size of one scalar */
py::format_descriptor<size_t>::format(), /* data type */
ndim, /* number of dimensions */
shape, /* shape of the matrix */
strides /* strides for each axis */
));
});
#if _ENABLE_MPI != 1 || _ENABLE_PLKOKKOS != 1
.def("probs",
[](measureT &M, const std::vector<size_t> &wires) {
return py::array_t<ParamT>(py::cast(M.probs(wires)));
})
.def("probs",
[](measureT &M) {
return py::array_t<ParamT>(py::cast(M.probs()));
})
.def("generate_samples",
[](measureT &M, size_t num_wires, size_t num_shots) {
auto &&result = M.generate_samples(num_shots);
const size_t ndim = 2;
const std::vector<size_t> shape{num_shots, num_wires};
constexpr auto sz = sizeof(size_t);
const std::vector<size_t> strides{sz * num_wires, sz};
// return 2-D NumPy array
return py::array(py::buffer_info(
result.data(), /* data as contiguous array */
sz, /* size of one scalar */
py::format_descriptor<size_t>::format(), /* data type */
ndim, /* number of dimensions */
shape, /* shape of the matrix */
strides /* strides for each axis */
));
})
#endif
;
}

/**
Expand Down Expand Up @@ -659,7 +670,7 @@ template <class StateVectorT> void lightningClassBindings(py::module_ &m) {
// Measurements
//***********************************************************************//
class_name = "MeasurementsC" + bitsize;
auto pyclass_measurements = py::class_<Measurements<StateVectorT>>(
auto pyclass_measurements = py::class_<measure<StateVectorT>>(
m, class_name.c_str(), py::module_local());

#ifdef _ENABLE_PLGPU
Expand Down
Loading
Loading