-
Notifications
You must be signed in to change notification settings - Fork 127
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 expanded gaussian pair for hpmc #1817
Conversation
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
pre-commit.ci autofix |
In an offline conversation, @SchoeniPhlippsn and I were discussing some revisions to the pre-computed values in I pointed out that in I left the code this way because it's how it's structured in the HPMC LJ Pair Potential, and I wanted to keep things consistent. But moving the computation to the header file would make things more efficient. What do others think? |
Yes, you can precompute additional constant terms and store them in the And this is a good observation on |
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.
This looks good, nice work.
Regarding whether to precompute quantities or not, I have no strong opinions, so my vote would be to keep as consistent as possible with the other HPMC pair potentials.
1.5, 2.0, 1.0, 1.0), | ||
rel=1e-5) | ||
assert simulation.operations.integrator.pair_energy == pytest.approx( | ||
expected=eg(1.5, 1.0, 1.0, 1.0) + eg(1.5, 2.0, 1.0, 1.0), rel=1e-5) |
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.
You could save the expected results into variables. That would help with readability, especially the last line, which becomes
assert simulation.operations.integrator.pair_energy == pytest.approx(expected_1 + expected_2)
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.
Apologies, I just noticed this feedback. I've just implemented your suggested changes and pushed to this branch.
We can make an issue and plan to refactor the precomputing in a future PR. On the GPU, memory is expensive and floating point operations are cheap. This is why the HOOMD MD code does not precompute these quantities. That behavior was copied into HPMC. However, these HPMC potentials are CPU only where the balance is different. I expect a small (but measurable) performance gain by precomputing these on the CPU (especially when sqrt is required). This is another reason to wait a bit on refactoring common isotropic pair methods into a HPMC base class. We have not yet recognized all of the common elements (e.g. precomputation) that could be combined. |
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! Merge in trunk-minor
and this is done.
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.
One more small tweak: we should ensure that sigma is positive as in #1810.
Description
I have created a new expanded gaussian pair potential for HPMC. The implementation of this potential closely follows the implementation of the lennard-jones pair potential for HPMC, which has led to some minor code duplication that may warrant later refactoring. The mathematical definition of the new pair potential should be equivalent to that of the expanded gaussian in the MD module. As part of this change, the following files were created:
hoomd/hpmc/PairPotentialExpandedGaussian.h
- templated off ofPairPotentialLennardJones.h
hoomd/hpmc/PairPotentialExpandedGaussian.cc
- templated off ofPairPotentialLennardJones.cc
hoomd/hpmc/pair/expanded_gaussian.py
- templated off oflennard_jones.py
hoomd/hpmc/pair/pytest/test_pair_expanded_gaussian.py
- templated off oftest_pair_lennard_jones.py
Motivation and context
Adding this pair potential will allow users to stochastically simulate systems with interactions that are defined by gaussian models, which previously has only been possible in MD. This may provide benefits, for example, in very large systems.
How has this been tested?
Change log
Checklist:
sphinx-doc/credits.rst
) in the pull request source branch.