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

Add vector-valued variants #1685

Merged
merged 40 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8cde22d
Add VectorVariant class
tcmoore3 Dec 15, 2023
a615776
Add a linear density ramp box variant
tcmoore3 Dec 18, 2023
91acbe9
First bit of sphinx docs for box variants
tcmoore3 Dec 18, 2023
4dceea3
More sphinx documentation
tcmoore3 Dec 19, 2023
f5bd904
Run pre-commit
tcmoore3 Dec 19, 2023
152459a
Fix references in sphinx-doc
tcmoore3 Dec 19, 2023
19d17a8
Apply suggestions from code review
tcmoore3 Jan 4, 2024
366a98a
Get rid of m_value in constant box variant
tcmoore3 Jan 4, 2024
ca60602
Replace t_start/t_ramp with a vaiant in VectorVariantBoxLinear
tcmoore3 Jan 4, 2024
7701e30
Fix imports
tcmoore3 Jan 4, 2024
e114e20
Attempt to fix imports
tcmoore3 Jan 4, 2024
31d55e3
Move scalar variants to new module
tcmoore3 Jan 10, 2024
5991e76
Use internal variant for inverse volume box ramp
tcmoore3 Jan 11, 2024
60eb93a
Call box_preprocessing on correct boxes
tcmoore3 Jan 11, 2024
14719e3
Fix box references in python docstrings
tcmoore3 Jan 11, 2024
1baa52d
Fix order of imports
tcmoore3 Jan 11, 2024
42a5de5
Import variant.box
tcmoore3 Jan 11, 2024
27ae047
Update docstring
tcmoore3 Jan 11, 2024
0ba47f3
Format
tcmoore3 Jan 11, 2024
72238ea
Add docstring to variant/scalar.py
tcmoore3 Jan 11, 2024
31fd15e
Rename LinearInverseVolume to InverseVolumeRamp
tcmoore3 Jan 12, 2024
53ee85d
Start implementing tests
tcmoore3 Jan 16, 2024
944fb61
Add more tests
tcmoore3 Jan 16, 2024
6569e65
Actually add test file
tcmoore3 Jan 16, 2024
0386557
Test custom box variant
tcmoore3 Jan 17, 2024
776ed3a
formatting
tcmoore3 Jan 17, 2024
4c7a5ee
formatting
tcmoore3 Jan 17, 2024
2b933b4
Fix error in docs and formatting hack
tcmoore3 Jan 17, 2024
db878a9
Remove pybind11 pickle code
tcmoore3 Jan 17, 2024
98eefb0
Merge remote-tracking branch 'origin/trunk-minor' into feature/vector…
tcmoore3 Jan 17, 2024
9708374
Merge remote-tracking branch 'origin/trunk-minor' into feature/vector…
tcmoore3 Feb 10, 2024
f0617dd
Address reviews
tcmoore3 Feb 13, 2024
8b5facd
formatting
tcmoore3 Feb 13, 2024
4c926c8
flake8
tcmoore3 Feb 13, 2024
75659e7
Apply suggestions from code review
joaander Feb 28, 2024
78d3402
Merge branch 'trunk-minor' into feature/vector-variant
joaander Feb 28, 2024
00d0090
Apply changes from code review.
joaander Feb 28, 2024
75c7de3
Revise docs.
joaander Feb 28, 2024
4679d2c
Run pre-commit.
joaander Feb 28, 2024
7f123a5
Explicitly document length of return type.
joaander Feb 28, 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
4 changes: 3 additions & 1 deletion hoomd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ set(_hoomd_sources Action.cc
Tuner.cc
Updater.cc
Variant.cc
VectorVariant.cc
extern/BVLSSolver.cc
extern/gsd.c
extern/kiss_fft.cc
Expand Down Expand Up @@ -187,6 +188,7 @@ set(_hoomd_headers
TextureTools.h
Updater.h
Variant.h
VectorVariant.h
VectorMath.h
WarpTools.cuh
)
Expand Down Expand Up @@ -352,7 +354,6 @@ set(files box.py
operations.py
pytest_plugin_validate.py
util.py
variant.py
simulation.py
state.py
trigger.py
Expand Down Expand Up @@ -384,6 +385,7 @@ add_subdirectory(write)
add_subdirectory(pytest)
add_subdirectory(tune)
add_subdirectory(update)
add_subdirectory(variant)

if (BUILD_TESTING)
# add_subdirectory(test-py)
Expand Down
6 changes: 3 additions & 3 deletions hoomd/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace hoomd
{
/** Defines quantities that vary with time steps.
/** Defines scalar quantities that vary with time steps.

Variant provides an interface to define quanties (such as kT) that vary over time. The base
class provides a callable interface. Derived classes implement specific kinds of varying
Variant provides an interface to define scalar quanties (such as kT) that vary over time. The
base class provides a callable interface. Derived classes implement specific kinds of varying
quantities.
*/
class PYBIND11_EXPORT Variant
Expand Down
106 changes: 106 additions & 0 deletions hoomd/VectorVariant.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) 2009-2023 The Regents of the University of Michigan.
// Part of HOOMD-blue, released under the BSD 3-Clause License.

#include "VectorVariant.h"
#include <pybind11/stl.h>

namespace hoomd
{
//* Trampoline for classes inherited in python
class VectorVariantBoxPy : public VectorVariantBox
{
public:
// Inherit the constructors
using VectorVariantBox::VectorVariantBox;

// trampoline method
array_type operator()(uint64_t timestep) override
{
PYBIND11_OVERLOAD_NAME(array_type, // Return type
VectorVariantBox, // Parent class
"__call__", // name of function in python
operator(), // Name of function in C++
timestep // Argument(s)
);
}
};

namespace detail
{

void export_VectorVariantBox(pybind11::module& m)
joaander marked this conversation as resolved.
Show resolved Hide resolved
{
pybind11::class_<VectorVariantBox, VectorVariantBoxPy, std::shared_ptr<VectorVariantBox>>(
m,
"VectorVariantBox")
.def(pybind11::init<>())
.def("__call__", &VectorVariantBox::operator());

pybind11::class_<VectorVariantBoxConstant,
VectorVariantBox,
std::shared_ptr<VectorVariantBoxConstant>>(m, "VectorVariantBoxConstant")
.def(pybind11::init<std::shared_ptr<BoxDim>>())
.def_property("box", &VectorVariantBoxConstant::getBox, &VectorVariantBoxConstant::setBox)
/*
.def(
pybind11::pickle(
[](VectorVariantBoxConstant& variant)
{
std::shared_ptr<BoxDim> box = variant.getBox();
std::array<Scalar, 6> arr = {box->getL().x,
box->getL().y,
box->getL().z,
box->getTiltFactorXY(),
box->getTiltFactorXZ(),
box->getTiltFactorYZ()};
return pybind11::make_tuple(arr);
},
[](pybind11::tuple params)
{
Scalar Lx = params[0][0].cast<Scalar>();
Scalar Ly = params[0][1].cast<Scalar>();
Scalar Lz = params[0][2].cast<Scalar>();
Scalar xy = params[0][3].cast<Scalar>();
Scalar xz = params[0][4].cast<Scalar>();
Scalar yz = params[0][5].cast<Scalar>();
std::shared_ptr<BoxDim> box(Lx, Ly, Lz);
box->setTiltFactors(xy, xz, yz);
return VectorVariantBoxConstant(box);
}));
*/
;

pybind11::class_<VectorVariantBoxLinear,
VectorVariantBox,
std::shared_ptr<VectorVariantBoxLinear>>(m, "VectorVariantBoxLinear")
.def(pybind11::init<std::shared_ptr<BoxDim>, std::shared_ptr<BoxDim>, std::shared_ptr<Variant>>())
.def_property("initial_box",
&VectorVariantBoxLinear::getBox1,
&VectorVariantBoxLinear::setBox1)
.def_property("final_box",
&VectorVariantBoxLinear::getBox2,
&VectorVariantBoxLinear::setBox2)
.def_property("variant",
&VectorVariantBoxLinear::getVariant,
&VectorVariantBoxLinear::setVariant);

pybind11::class_<VectorVariantBoxInverseVolumeRamp,
VectorVariantBox,
std::shared_ptr<VectorVariantBoxInverseVolumeRamp>>(
m,
"VectorVariantBoxInverseVolumeRamp")
.def(pybind11::init<std::shared_ptr<BoxDim>, Scalar, uint64_t, uint64_t>())
.def_property("box1",
&VectorVariantBoxInverseVolumeRamp::getBox1,
&VectorVariantBoxInverseVolumeRamp::setBox1)
.def_property("t_start",
&VectorVariantBoxInverseVolumeRamp::getTStart,
&VectorVariantBoxInverseVolumeRamp::setTStart)
.def_property("t_ramp",
&VectorVariantBoxInverseVolumeRamp::getTRamp,
&VectorVariantBoxInverseVolumeRamp::setTRamp);
}

} // end namespace detail

} // end namespace hoomd
Loading
Loading