-
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
Conversation
Adds a VectorVariant class. Adds VectorVariantBox as a subclass of VectorVariant. Implements VectorVariantBoxConstant and VectorVariantBoxLinear. Moves variant from a module to a package. The code compiles and I am able to get the expected boxes as a function of time for both VectorVariantBoxConstant and VectorVariantBoxLinear objects. More to come before I open a PR.
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.
Thanks! Here are some suggestions to improve this.
As you already noted, we also need to add unit tests.
Moves the scalar variant classes to a separate module, but imports them in hoomd/variant/__init__.py so that they still live in the hoomd.variant namespace. I did this as a workaround for python's import behavior since I kept getting circular import errors when keeping the scalar variant classes in the package's __init__.py file.
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.
Thanks! I have some more suggestions to improve this.
Also, I plan to merge this after the 4.5.0 release with the expectation that we can add code using box variants (BoxResize, QuickCompress) in the same release that we introduce the variants.
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.
We should either rename variant_like
to scalar_varient_like
or make very clear it is for scalar variants.
The code looks good generally. Just left a few comments and probably won't be able to get back to this.
/// 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); |
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.
Co-authored-by: Brandon Butler <[email protected]>
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.
Thanks!
I implemented a few minor suggestions directly on the branch. This is good to merge now.
Description
This PR implements a
VectorVariant
that returns array values as a function of time step, in contrast to theVariant
classes that return scalar values as a function of the time step.VectorVariant
is templated on the length of the array to take advantage of C++'s strong typing. This PR also implements aVectorVariantBox
and a handful of subclasses ofVectorVariantBox
that return length-6 arrays for use with functions that take box arguments.The new
VectorVariant*
C++ classes are implemented inVectorVariant.[h,cc]
. In Python, I created a newvariant
package. The existing (scalar-valued)Variant
s are defined in the package's__init__.py
file, and the box vector variant python classes are inhoomd/variant/box.py
.Motivation and context
This functionality is a first step towards fixing several issues, #1640 and #1641. It will also allow us to replace the arguments
box1
,box2
, andvariant
with a singlehoomd.variant.box.*
argument to make the use ofupdate.BoxResize
more intuitive.How has this been tested?
Existing unit tests pass, and my ad-hoc tests of the new box vector variant classes are passing. I still need to add proper unit tests for the vector variants.
Change log
Checklist:
sphinx-doc/credits.rst
) in the pull request source branch.