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 mpcd initialization for v4 #1580

Merged
merged 27 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2446c16
Refactor mpcd.data.snapshot into hoomd.Snapshot
mphoward Jun 9, 2022
6135bfa
Remove MPCD SystemDataSnapshot
mphoward Jun 10, 2022
eb5af22
fix compile and test error
matthewddo Jun 7, 2023
654de9c
Add resize and replicate tests
matthewddo Jun 21, 2023
d6dd97f
Refactor MPCD SystemData into SystemDefinition
mphoward Jun 24, 2023
8a2704b
Add tests for initializing system, getting and setting from snapshot,…
matthewddo Jul 13, 2023
4def281
Update C++ tests
matthewddo Jul 20, 2023
bb30e18
Add method to set CellList on classes that need it
mphoward Jul 21, 2023
26b25f5
Set CellList on objects that require it
mphoward Jul 24, 2023
af5d268
Try to fix header installation for plugins
mphoward Jul 26, 2023
1e4099e
Address various comments regarding errors and formatting
matthewddo Jul 28, 2023
77bc127
Try to fix link errors with md test fix
mphoward Jul 28, 2023
131f898
Reuse exec confs like in MD communication test
mphoward Jul 31, 2023
eb20f9d
Fix MPI issues in tests
mphoward Jul 31, 2023
c745d98
Fix usage of MD Communicator weak pointer
mphoward Jul 31, 2023
dc4896c
Fix incorrect asserts in Communicator
mphoward Jul 31, 2023
060e3e1
Merge remote-tracking branch 'origin/trunk-major' into mpcd-v4-init
mphoward Jul 31, 2023
50f97bb
Squash warning after merge up
mphoward Jul 31, 2023
901b8f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2023
282b705
Fix conditions to build MPCD in CMake
mphoward Aug 7, 2023
1b85b24
Remove unused initialization files
mphoward Aug 7, 2023
cbce087
Merge branch 'trunk-minor' into mpcd-v4-init
mphoward Aug 7, 2023
a195d81
Run pre-commit
mphoward Aug 7, 2023
95bd247
Add new contributor
mphoward Aug 7, 2023
8a55dc1
Apply suggestions from code review
mphoward Aug 14, 2023
841cbcd
Merge branch 'trunk-minor' into mpcd-v4-init
mphoward Aug 18, 2023
d8ef9a7
Rename MPCD define
mphoward Aug 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions hoomd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ set(_hoomd_cu_sources BondedGroupData.cu
ParticleGroup.cu
SFCPackTunerGPU.cu)

# add the MPCD base parts that should go into _hoomd (i.e., core particle data)
if (BUILD_MPCD AND (NOT ENABLE_HIP OR HIP_PLATFORM STREQUAL "nvcc"))
list(APPEND _hoomd_sources
mpcd/ParticleData.cc
mpcd/ParticleDataSnapshot.cc
)
list(APPEND _hoomd_cu_sources
mpcd/ParticleData.cu
)
# headers will be installed by MPCD itself so they go in the right subdirectory
endif()

if (ENABLE_HIP)
set(_cuda_sources ${_hoomd_cu_sources})
set_source_files_properties(${_hoomd_cu_sources} PROPERTIES LANGUAGE ${HOOMD_DEVICE_LANGUAGE})
Expand Down Expand Up @@ -401,10 +413,9 @@ if (BUILD_METAL AND BUILD_MD)
add_subdirectory(metal)
endif()

if (NOT ENABLE_HIP OR HIP_PLATFORM STREQUAL "nvcc")
if (BUILD_MPCD)
add_subdirectory(mpcd)
endif()
if (BUILD_MPCD AND (NOT ENABLE_HIP OR HIP_PLATFORM STREQUAL "nvcc"))
target_compile_definitions(_hoomd PUBLIC ENABLE_MPCD)
mphoward marked this conversation as resolved.
Show resolved Hide resolved
add_subdirectory(mpcd)
endif()

foreach(entry ${PLUGINS})
Expand Down
19 changes: 19 additions & 0 deletions hoomd/HOOMDMPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifdef ENABLE_MPI

#include "HOOMDMath.h"
#include "VectorMath.h"

#include <mpi.h>

Expand Down Expand Up @@ -90,6 +91,24 @@ template<class Archive> void serialize(Archive& ar, uchar3& u, const unsigned in
ar& u.z;
}

//! Serialization of vec3<Real>
template<class Archive, class Real>
void serialize(Archive& ar, hoomd::vec3<Real>& v, const unsigned int version)
{
ar& v.x;
ar& v.y;
ar& v.z;
}

//! Serialization of quat<Real>
template<class Archive, class Real>
void serialize(Archive& ar, hoomd::quat<Real>& q, const unsigned int version)
{
// serialize both members
ar& q.s;
ar& q.v;
}

#ifdef ENABLE_TBB
//! Serialization for tbb::concurrent_vector
template<class Archive, class T, class A>
Expand Down
23 changes: 0 additions & 23 deletions hoomd/ParticleData.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,6 @@ const unsigned int NOT_LOCAL = 0xffffffff;

} // end namespace hoomd

#ifdef ENABLE_MPI
namespace cereal
{
//! Serialization of vec3<Real>
template<class Archive, class Real>
void serialize(Archive& ar, hoomd::vec3<Real>& v, const unsigned int version)
{
ar& v.x;
ar& v.y;
ar& v.z;
}

//! Serialization of quat<Real>
template<class Archive, class Real>
void serialize(Archive& ar, hoomd::quat<Real>& q, const unsigned int version)
{
// serialize both members
ar& q.s;
ar& q.v;
}
} // namespace cereal
#endif

namespace hoomd
{
namespace detail
Expand Down
30 changes: 30 additions & 0 deletions hoomd/SnapshotSystemData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ void SnapshotSystemData<Real>::replicate(unsigned int nx, unsigned int ny, unsig
improper_data.replicate(n, old_n);
constraint_data.replicate(n, old_n);
pair_data.replicate(n, old_n);
#ifdef ENABLE_MPCD
mpcd_data.replicate(nx, ny, nz, old_box, *global_box);
#endif
}

template<class Real> void SnapshotSystemData<Real>::wrap()
{
// HOOMD particles
for (unsigned int i = 0; i < particle_data.size; i++)
{
auto const frac = global_box->makeFraction(particle_data.pos[i]);
Expand All @@ -54,6 +58,20 @@ template<class Real> void SnapshotSystemData<Real>::wrap()
static_cast<int>(std::floor(frac.z)));
particle_data.image[i] = particle_data.image[i] + img;
}

#ifdef ENABLE_MPCD
// MPCD particles
for (unsigned int i = 0; i < mpcd_data.size; ++i)
{
auto const frac = global_box->makeFraction(mpcd_data.position[i]);
auto modulus_positive = [](Scalar x)
{ return std::fmod(std::fmod(x, Scalar(1.0)) + Scalar(1.0), Scalar(1.0)); };
auto const wrapped = vec3<Scalar>(modulus_positive(static_cast<Scalar>(frac.x)),
modulus_positive(static_cast<Scalar>(frac.y)),
modulus_positive(static_cast<Scalar>(frac.z)));
mpcd_data.position[i] = global_box->makeCoordinates(wrapped);
}
#endif
}

template<class Real>
Expand Down Expand Up @@ -86,6 +104,9 @@ void SnapshotSystemData<Real>::broadcast(unsigned int root,
improper_data.bcast(root, communicator);
constraint_data.bcast(root, communicator);
pair_data.bcast(root, communicator);
#ifdef ENABLE_MPCD
mpcd_data.bcast(root, communicator);
#endif
}
#endif
}
Expand All @@ -108,6 +129,9 @@ void SnapshotSystemData<Real>::broadcast_all(unsigned int root,
improper_data.bcast(root, hoomd_world);
constraint_data.bcast(root, hoomd_world);
pair_data.bcast(root, hoomd_world);
#ifdef ENABLE_MPCD
mpcd_data.bcast(root, hoomd_world);
#endif
}
#endif
}
Expand All @@ -133,6 +157,9 @@ void export_SnapshotSystemData(pybind11::module& m)
.def_readonly("impropers", &SnapshotSystemData<float>::improper_data)
.def_readonly("constraints", &SnapshotSystemData<float>::constraint_data)
.def_readonly("pairs", &SnapshotSystemData<float>::pair_data)
#ifdef ENABLE_MPCD
.def_readonly("mpcd", &SnapshotSystemData<float>::mpcd_data)
#endif
.def("replicate", &SnapshotSystemData<float>::replicate)
.def("wrap", &SnapshotSystemData<float>::wrap)
.def("_broadcast_box", &SnapshotSystemData<float>::broadcast_box)
Expand All @@ -152,6 +179,9 @@ void export_SnapshotSystemData(pybind11::module& m)
.def_readonly("impropers", &SnapshotSystemData<double>::improper_data)
.def_readonly("constraints", &SnapshotSystemData<double>::constraint_data)
.def_readonly("pairs", &SnapshotSystemData<double>::pair_data)
#ifdef ENABLE_MPCD
.def_readonly("mpcd", &SnapshotSystemData<double>::mpcd_data)
#endif
.def("replicate", &SnapshotSystemData<double>::replicate)
.def("wrap", &SnapshotSystemData<double>::wrap)
.def("_broadcast_box", &SnapshotSystemData<double>::broadcast_box)
Expand Down
6 changes: 6 additions & 0 deletions hoomd/SnapshotSystemData.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "BondedGroupData.h"
#include "BoxDim.h"
#include "ParticleData.h"
#ifdef ENABLE_MPCD
#include "hoomd/mpcd/ParticleDataSnapshot.h"
#endif

#ifndef __HIPCC__
#include <pybind11/pybind11.h>
Expand Down Expand Up @@ -50,6 +53,9 @@ template<class Real> struct SnapshotSystemData
ImproperData::Snapshot improper_data; //!< The improper data
ConstraintData::Snapshot constraint_data; //!< The constraint data
PairData::Snapshot pair_data; //!< The pair data
#ifdef ENABLE_MPCD
mpcd::ParticleDataSnapshot mpcd_data; //!< The MPCD particle data
#endif

//! Constructor
SnapshotSystemData() : dimensions(3), global_box(std::make_shared<BoxDim>()) { }
Expand Down
34 changes: 34 additions & 0 deletions hoomd/SystemDefinition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ SystemDefinition::SystemDefinition(std::shared_ptr<SnapshotSystemData<Real>> sna
m_constraint_data = std::shared_ptr<ConstraintData>(
new ConstraintData(m_particle_data, snapshot->constraint_data));
m_pair_data = std::shared_ptr<PairData>(new PairData(m_particle_data, snapshot->pair_data));

#ifdef ENABLE_MPCD
m_mpcd_data = std::make_shared<mpcd::ParticleData>(snapshot->mpcd_data,
snapshot->global_box,
exec_conf,
decomposition);
#endif
}

/*! Sets the dimensionality of the system. When quantities involving the dof of
Expand Down Expand Up @@ -176,6 +183,12 @@ template<class Real> std::shared_ptr<SnapshotSystemData<Real>> SystemDefinition:
m_improper_data->takeSnapshot(snap->improper_data);
m_constraint_data->takeSnapshot(snap->constraint_data);
m_pair_data->takeSnapshot(snap->pair_data);
#ifdef ENABLE_MPCD
if (m_mpcd_data)
{
m_mpcd_data->takeSnapshot(snap->mpcd_data, snap->global_box);
}
#endif

return snap;
}
Expand All @@ -202,6 +215,24 @@ void SystemDefinition::initializeFromSnapshot(std::shared_ptr<SnapshotSystemData
m_improper_data->initializeFromSnapshot(snapshot->improper_data);
m_constraint_data->initializeFromSnapshot(snapshot->constraint_data);
m_pair_data->initializeFromSnapshot(snapshot->pair_data);
#ifdef ENABLE_MPCD
if (!m_mpcd_data)
{
#ifdef ENABLE_MPI
auto decomp = m_particle_data->getDomainDecomposition();
#else
auto decomp = std::shared_ptr<DomainDecomposition>();
#endif
m_mpcd_data = std::make_shared<mpcd::ParticleData>(snapshot->mpcd_data,
snapshot->global_box,
m_particle_data->getExecConf(),
decomp);
}
else
{
m_mpcd_data->initializeFromSnapshot(snapshot->mpcd_data, snapshot->global_box);
}
#endif
}

// instantiate both float and double methods
Expand Down Expand Up @@ -261,6 +292,9 @@ void export_SystemDefinition(pybind11::module& m)
.def("getImproperData", &SystemDefinition::getImproperData)
.def("getConstraintData", &SystemDefinition::getConstraintData)
.def("getPairData", &SystemDefinition::getPairData)
#ifdef ENABLE_MPCD
.def("getMPCDParticleData", &SystemDefinition::getMPCDParticleData)
#endif
.def("takeSnapshot_float", &SystemDefinition::takeSnapshot<float>)
.def("takeSnapshot_double", &SystemDefinition::takeSnapshot<double>)
.def("initializeFromSnapshot", &SystemDefinition::initializeFromSnapshot<float>)
Expand Down
20 changes: 20 additions & 0 deletions hoomd/SystemDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include "BondedGroupData.h"
#include "ParticleData.h"
#ifdef ENABLE_MPCD
#include "hoomd/mpcd/ParticleData.h"
#endif

#include <memory>
#include <pybind11/pybind11.h>
Expand Down Expand Up @@ -199,6 +202,20 @@ class PYBIND11_EXPORT SystemDefinition
return m_pair_data;
}

#ifdef ENABLE_MPCD
//! Get the MPCD particle data
std::shared_ptr<mpcd::ParticleData> getMPCDParticleData() const
{
return m_mpcd_data;
}

//! Set the MPCD particle data
void setMPCDParticleData(std::shared_ptr<mpcd::ParticleData> mpcd_data)
{
m_mpcd_data = mpcd_data;
}
#endif

//! Return a snapshot of the current system data
template<class Real> std::shared_ptr<SnapshotSystemData<Real>> takeSnapshot();

Expand All @@ -216,6 +233,9 @@ class PYBIND11_EXPORT SystemDefinition
std::shared_ptr<ImproperData> m_improper_data; //!< Improper data for the system
std::shared_ptr<ConstraintData> m_constraint_data; //!< Improper data for the system
std::shared_ptr<PairData> m_pair_data; //!< Special pairs data for the system
#ifdef ENABLE_MPCD
std::shared_ptr<mpcd::ParticleData> m_mpcd_data; //!< MPCD particle data
#endif

#ifdef ENABLE_MPI
/// The system communicator
Expand Down
10 changes: 10 additions & 0 deletions hoomd/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
// ParticleFilter objects
#include "filter/export_filters.h"

// optional MPCD classes
#ifdef ENABLE_MPCD
#include "hoomd/mpcd/ParticleData.h"
#include "hoomd/mpcd/ParticleDataSnapshot.h"
#endif

// include GPU classes
#ifdef ENABLE_HIP
#include "BoxResizeUpdaterGPU.h"
Expand Down Expand Up @@ -269,6 +275,10 @@ PYBIND11_MODULE(_hoomd, m)
export_LocalGroupData<HOOMDDeviceBuffer, ConstraintData>(m, "LocalConstraintDataDevice");
export_LocalGroupData<HOOMDDeviceBuffer, PairData>(m, "LocalPairDataDevice");
#endif
#ifdef ENABLE_MPCD
mpcd::detail::export_ParticleData(m);
mpcd::detail::export_ParticleDataSnapshot(m);
#endif

// initializers
export_GSDReader(m);
Expand Down