-
Notifications
You must be signed in to change notification settings - Fork 132
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
Changes from 30 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
8cde22d
Add VectorVariant class
tcmoore3 a615776
Add a linear density ramp box variant
tcmoore3 91acbe9
First bit of sphinx docs for box variants
tcmoore3 4dceea3
More sphinx documentation
tcmoore3 f5bd904
Run pre-commit
tcmoore3 152459a
Fix references in sphinx-doc
tcmoore3 19d17a8
Apply suggestions from code review
tcmoore3 366a98a
Get rid of m_value in constant box variant
tcmoore3 ca60602
Replace t_start/t_ramp with a vaiant in VectorVariantBoxLinear
tcmoore3 7701e30
Fix imports
tcmoore3 e114e20
Attempt to fix imports
tcmoore3 31d55e3
Move scalar variants to new module
tcmoore3 5991e76
Use internal variant for inverse volume box ramp
tcmoore3 60eb93a
Call box_preprocessing on correct boxes
tcmoore3 14719e3
Fix box references in python docstrings
tcmoore3 1baa52d
Fix order of imports
tcmoore3 42a5de5
Import variant.box
tcmoore3 27ae047
Update docstring
tcmoore3 0ba47f3
Format
tcmoore3 72238ea
Add docstring to variant/scalar.py
tcmoore3 31fd15e
Rename LinearInverseVolume to InverseVolumeRamp
tcmoore3 53ee85d
Start implementing tests
tcmoore3 944fb61
Add more tests
tcmoore3 6569e65
Actually add test file
tcmoore3 0386557
Test custom box variant
tcmoore3 776ed3a
formatting
tcmoore3 4c7a5ee
formatting
tcmoore3 2b933b4
Fix error in docs and formatting hack
tcmoore3 db878a9
Remove pybind11 pickle code
tcmoore3 98eefb0
Merge remote-tracking branch 'origin/trunk-minor' into feature/vector…
tcmoore3 9708374
Merge remote-tracking branch 'origin/trunk-minor' into feature/vector…
tcmoore3 f0617dd
Address reviews
tcmoore3 8b5facd
formatting
tcmoore3 4c926c8
flake8
tcmoore3 75659e7
Apply suggestions from code review
joaander 78d3402
Merge branch 'trunk-minor' into feature/vector-variant
joaander 00d0090
Apply changes from code review.
joaander 75c7de3
Revise docs.
joaander 4679d2c
Run pre-commit.
joaander 7f123a5
Explicitly document length of return type.
joaander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// 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 | ||
{ | ||
|
||
// This testVariantCall function allows us to test that Python custom vector | ||
// variants work properly in C++. This ensures we can test that the function | ||
// itself can be called in C++ when defined in Python. | ||
|
||
/// Method to enable unit testing of C++ variant calls from pytest | ||
std::array<Scalar, 6> testVectorVariantBoxCall(std::shared_ptr<VectorVariantBox> t, uint64_t step) | ||
{ | ||
return (*t)(step); | ||
} | ||
|
||
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); | ||
|
||
pybind11::class_<VectorVariantBoxInterpolate, | ||
VectorVariantBox, | ||
std::shared_ptr<VectorVariantBoxInterpolate>>(m, "VectorVariantBoxInterpolate") | ||
.def(pybind11:: | ||
init<std::shared_ptr<BoxDim>, std::shared_ptr<BoxDim>, std::shared_ptr<Variant>>()) | ||
.def_property("_initial_box", | ||
&VectorVariantBoxInterpolate::getBox1, | ||
&VectorVariantBoxInterpolate::setBox1) | ||
.def_property("_final_box", | ||
&VectorVariantBoxInterpolate::getBox2, | ||
&VectorVariantBoxInterpolate::setBox2) | ||
.def_property("variant", | ||
&VectorVariantBoxInterpolate::getVariant, | ||
&VectorVariantBoxInterpolate::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("_initial_box", | ||
&VectorVariantBoxInverseVolumeRamp::getInitialBox, | ||
&VectorVariantBoxInverseVolumeRamp::setInitialBox) | ||
.def_property("t_start", | ||
&VectorVariantBoxInverseVolumeRamp::getTStart, | ||
&VectorVariantBoxInverseVolumeRamp::setTStart) | ||
.def_property("t_ramp", | ||
&VectorVariantBoxInverseVolumeRamp::getTRamp, | ||
&VectorVariantBoxInverseVolumeRamp::setTRamp) | ||
.def_property("final_volume", | ||
&VectorVariantBoxInverseVolumeRamp::getFinalVolume, | ||
&VectorVariantBoxInverseVolumeRamp::setFinalVolume); | ||
|
||
m.def("_test_vector_variant_box_call", &testVectorVariantBoxCall); | ||
} | ||
|
||
} // end namespace detail | ||
|
||
} // end namespace hoomd |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer
t->operator()(step)
, but feel free to leave alone.