Adding Chebyshev anisotropic pair potential#121
Adding Chebyshev anisotropic pair potential#121mzf0069 wants to merge 5 commits intomphowardlab:mainfrom
Conversation
mphoward
left a comment
There was a problem hiding this comment.
This is a good start! Here are some comments, let me know what questions you have.
mphoward
left a comment
There was a problem hiding this comment.
This is going in a good direction. Let's finalize the interface, especially the constructor, then start to implement that.
| const std::vector<Scalar>& r0_data, | ||
| const std::vector<unsigned int>& terms, | ||
| const std::vector<Scalar>& coeffs); | ||
|
|
There was a problem hiding this comment.
r0_data should be a raw pointer to Scalar so that we can copy the data in-place from a NumPy array. You will need a second raw pointer or a std::vector that stores the dimensionality of r0_data along each of the 5 dimensions.
terms and coeffs also need to be raw pointers, and you'll need one more variable that is the number of terms.
Last, domain should probably also be a raw pointer to a regular Scalar so you can accept a NumPy array that is (6,2) in shape. Otherwise, it can be a std::vector<Scalar2>, and you can copy into it.
| } | ||
|
|
||
| /// r0 data (theta, phi, alpha, beta, gamma) (N x 6) | ||
| const GPUArray<Scalar>& getR0Data() const |
There was a problem hiding this comment.
Do you want to be expose the R0Data data directly after you construct the class? Same questions go for some of the members below that return GPUArray. You have to decide whether you are OK with the user modifying their contents or not.
| /// Allocate storage for term list and coefficients. | ||
| void resizeTerms(unsigned int Nterms); |
There was a problem hiding this comment.
Is this something we want the user to be able to do? It seems like you wouldn't want them to do that themselves, most likely. If it's a method the class needs to trigger, though, it can be protected.
| protected: | ||
| void computeForces(uint64_t timestep) override; | ||
|
|
||
| private: |
There was a problem hiding this comment.
Most of the members in this section will need to be protected not private if the GPU version of the class is going to access them.
mphoward
left a comment
There was a problem hiding this comment.
Looks good to me, let's start on the implementation!
| unsigned int Nterms, | ||
| const unsigned int* terms, | ||
| const Scalar* coeffs); |
There was a problem hiding this comment.
I like to follow the convention that the number of items comes after the pointers
| unsigned int Nterms, | |
| const unsigned int* terms, | |
| const Scalar* coeffs); | |
| const unsigned int* terms, | |
| const Scalar* coeffs, | |
| unsigned int Nterms); |
| const Scalar* r0_data, | ||
| const unsigned int* r0_shape, |
There was a problem hiding this comment.
Logically, should these come before the things related to the potential approximation or after? It doesn't really matter, beyond which way it makes more sense for you to read them.
| // neighbor list object | ||
| std::shared_ptr<hoomd::md::NeighborList> m_nlist; |
There was a problem hiding this comment.
Member variables should be documented like this in doxygen style
| // neighbor list object | |
| std::shared_ptr<hoomd::md::NeighborList> m_nlist; | |
| std::shared_ptr<hoomd::md::NeighborList> m_nlist; //!< Neighbor list |
| // intenal r0 linear interpolator | ||
| std::unique_ptr<LinearInterpolator5D> m_r0_interp; | ||
|
|
||
| // r0_data | ||
| GPUArray<Scalar> m_r0_data; | ||
|
|
||
| std::array<unsigned int, 5> m_r0_shape; |
There was a problem hiding this comment.
We should discuss how the linear interpolator will work. It may not be necessary to store a separate variable for it, and instead just construct it each time it is needed because it will be a lightweight wrapper around the data and the shape.
Noting: if the shape is stored in an array, it will need to be copied into the interpolator to pass it to the GPU.
| GPUArray<Scalar> m_coeffs; | ||
|
|
||
| // number of terms | ||
| unsigned int m_Nterms = 0; |
There was a problem hiding this comment.
This doesn't need a default value assigned to it
| unsigned int m_Nterms = 0; | |
| unsigned int m_Nterms; |
mphoward
left a comment
There was a problem hiding this comment.
This is moving in a good direction! Please see my comments and let me know what questions you have.
src/pytest/test_chebyshev.py
Outdated
| domain = numpy.zeros((5, 2), dtype=numpy.float64) | ||
| terms = numpy.zeros((2, 6), dtype=numpy.uint32) |
There was a problem hiding this comment.
I would suggest giving the domain and terms some real values, not just zeros, as it may cause problems later once we start implementing things.
src/pytest/test_chebyshev.py
Outdated
| assert pot._cpp_obj.n_terms == 2 | ||
| assert numpy.isclose(pot._cpp_obj.r_cut, r_cut) |
There was a problem hiding this comment.
_cpp_obj is an implementation detail, so we should not test it in detail. The check above that it exists and is not None is OK though.
| assert pot._cpp_obj.n_terms == 2 | |
| assert numpy.isclose(pot._cpp_obj.r_cut, r_cut) |
src/pair.py
Outdated
| @property | ||
| def r_cut(self): | ||
| """Cut-off distance in approximation domain""" | ||
| return self._r_cut |
There was a problem hiding this comment.
You shouldn't need a property for the ones coming from C++, but you need to use the ParameterDict correctly for those.
| @property | |
| def r_cut(self): | |
| """Cut-off distance in approximation domain""" | |
| return self._r_cut |
src/pair.py
Outdated
| @property | ||
| def n_terms(self): | ||
| """Number of terms.""" | ||
| return int(self._terms.shape[0]) |
There was a problem hiding this comment.
Same here, this should come from C++ automatically.
| @property | |
| def n_terms(self): | |
| """Number of terms.""" | |
| return int(self._terms.shape[0]) |
src/pair.py
Outdated
| @property | ||
| def r0_shape(self): | ||
| """r0 table shape.""" | ||
| return tuple(int(x) for x in self._r0_data.shape) |
There was a problem hiding this comment.
We will want to discuss how to expose the array quantities later on. However, I note for now that we don't want to have a special shape property for r0. It should be a NumPy inside this class, so it should work like r0.shape.
No description provided.