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

Implement new HPMC pair potential framework #1676

Merged
merged 45 commits into from
Jan 22, 2024
Merged

Conversation

joaander
Copy link
Member

@joaander joaander commented Dec 12, 2023

Description

  • Implement a new framework for multiple HPMC pair potentials: HPMCIntegrator.pair_potentials on the CPU.
  • Provide LennardJones as the first example using the new framework.

The new framework allows:

  1. Multiple pair potentials in a list.
  2. Potentials have proper type parameters.
  3. Uses ShortReal appropriately for mixed precision builds.
  4. Allows users to write custom potentials that are built at compile time.
  5. Names the class PairPotential to match the pair_potentials name used in the documentation.

Motivation and context

This is the first step toward implementing #1652. Future pull requests will add multi-site pair potentials (based on the CPPPotentialUnion code), anisotropic potentials (e.g. Kern-Frenkel) and provide an example component.

How has this been tested?

TODO:

  • Add unit tests.
  • Fix ComputeSDF.
  • Fix UpdaterClusters.
  • Fix UpdaterMuVT.
  • Apply deprecations.
  • Validate LennardJones pair potential in hoomd-validation.
  • Validate ComputeSDF in hoomd-validation.

Change log

Added:

* HPMC compile time pair potential framework (CPU only). Allows potential energy in HPMC simulations without `CPPPotential`.
  * ``hoomd.hpmc.pair.LennardJones`` - Evaluate Lennard Jones energy between particles
    (`#1676 <https://github.com/glotzerlab/hoomd-blue/pull/1676>`__).
  * ``HPMCIntegrator.pair_potentials`` - Set a list of pair potentials to evaluate
    (`#1676 <https://github.com/glotzerlab/hoomd-blue/pull/1676>`__). 
  * ``HPMCIntegrator.pair_energy`` (loggable) - Total pair energy from all pair potentials.
    (`#1676 <https://github.com/glotzerlab/hoomd-blue/pull/1676>`__).

Deprecated:

* ``hoomd.hpmc.pair.user.CPPPotentialBase`` 
  (`#1676 <https://github.com/glotzerlab/hoomd-blue/pull/1676>`__).
* ``hoomd.hpmc.pair.user.CPPPotential`` - Use a built-in potential or compile your code in a component 
  (`#1676 <https://github.com/glotzerlab/hoomd-blue/pull/1676>`__).
* ``hoomd.hpmc.pair.user.CPPPotentialUnion`` - Use a built-in potential or compile your code in a component
  (`#1676 <https://github.com/glotzerlab/hoomd-blue/pull/1676>`__).
* ``HPMCIntegrator.pair_potential`` - Use compiled potentials with ``pair_potentials`` 
  (`#1676 <https://github.com/glotzerlab/hoomd-blue/pull/1676>`__).

Changed:

* Refactored the C++ API for ``PatchEnergy`` potentials.

Checklist:

@joaander joaander added the enhancement New feature or request label Dec 12, 2023
Refactor existing code to use computeTotalPairEnergy.
Individual pair potentials can convert to ShortReal when warranted. This improves
performance by avoiding costly double->float conversions all the time.
This allows computeOnePairEnergy to apply type-specific r_cut checks before
calling energy() to avoid the virtual function call overhead.
@joaander joaander requested review from a team, SchoeniPhlippsn, b-butler, seoulfood and tcmoore3 and removed request for a team January 10, 2024 18:47
Copy link
Member

@b-butler b-butler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good. I only have a few comments. Also, if possible we should document the expected changes between potentials in MC and MD.

hoomd/hpmc/pair/__init__.py Show resolved Hide resolved
hoomd/hpmc/pair/__init__.py Outdated Show resolved Hide resolved
hoomd/hpmc/pytest/CMakeLists.txt Show resolved Hide resolved
hoomd/hpmc/UpdaterMuVT.h Outdated Show resolved Hide resolved
hoomd/hpmc/pytest/test_pair_lennard_jones.py Outdated Show resolved Hide resolved
hoomd/hpmc/pytest/test_pair_lennard_jones.py Outdated Show resolved Hide resolved
hoomd/hpmc/IntegratorHPMC.cc Show resolved Hide resolved
hoomd/hpmc/PairPotentialLennardJones.cc Outdated Show resolved Hide resolved
hoomd/hpmc/PairPotential.h Outdated Show resolved Hide resolved
hoomd/hpmc/IntegratorHPMC.h Outdated Show resolved Hide resolved
Copy link
Member

@b-butler b-butler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks ready to me.

@joaander
Copy link
Member Author

Here is a performance test of hoomd-benchmarks.hpmc_pair_lj with 1000 particles on cheme-hodges:

  • 4.4.1 - LLVM: 117 sweeps per second
  • hpmc-pair-lj - LLVM: 88.6 sweeps per second
  • hpmc-pair-lj - compiled potential: 141 sweeps per second

There is some small overhead introduced to the LLVM code path from the generalization to add multiple pair potentials together (computeOnePairEnergy). However, the compiled code path is even faster than the LLVM code path, and should be even faster after we remove LLVM. Much of the LLVM path's overhead is in the virtual function calls to getRCut and getAdditiveCutoff. The new compiled code path makes these inlined non-virtual functions to avoid this overhead.

Copy link
Member

@tcmoore3 tcmoore3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Just a few clarification questions, but otherwise seems ready to go.

hoomd/hpmc/IntegratorHPMC.h Outdated Show resolved Hide resolved
hoomd/hpmc/IntegratorHPMC.h Show resolved Hide resolved
hoomd/hpmc/PairPotential.h Outdated Show resolved Hide resolved
hoomd/hpmc/pair/lennard_jones.py Outdated Show resolved Hide resolved
hoomd/hpmc/pair/lennard_jones.py Outdated Show resolved Hide resolved
@joaander joaander merged commit d4a2061 into trunk-minor Jan 22, 2024
40 checks passed
@joaander joaander deleted the hpmc-pair-lj branch January 22, 2024 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request validate Execute long running validation tests on pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants