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

External potentials in HPMC. #1811

Merged
merged 25 commits into from
Jun 18, 2024
Merged

External potentials in HPMC. #1811

merged 25 commits into from
Jun 18, 2024

Conversation

joaander
Copy link
Member

@joaander joaander commented Jun 11, 2024

Description

  • Implement the infrastructure needed for compiled in external potentials in HPMC.
  • Add linear external potential.

Motivation and context

Replace CPPExternalPotential.

How has this been tested?

Added unit tests.

Change log

Added:

* ``hoomd.hpmc.external.External`` provides an abstract interface to external potentials
  (`#1811 <https://github.com/glotzerlab/hoomd-blue/pull/1811>`__).
* ``hoomd.hpmc.external.Linear`` computes linear potential as a function of the distance from a point to a plane
  (`#1811 <https://github.com/glotzerlab/hoomd-blue/pull/1811>`__).
* ``HPMCIntegrator.external_potentials`` sets the list of external potentials applied to the system
  (`#1811 <https://github.com/glotzerlab/hoomd-blue/pull/1811>`__).

Deprecated:

* ``HPMCIntegrator.external_potential`` - use ``HPMCIntegrator.external_potentials``
  (`#1811 <https://github.com/glotzerlab/hoomd-blue/pull/1811>`__).
* ``hoomd.hpmc.external.user.CPPExternalPotential`` - use ``hoomd.hpmc.external.Linear`` or write a custom component in C++
  (`#1811 <https://github.com/glotzerlab/hoomd-blue/pull/1811>`__).

Checklist:

joaander and others added 11 commits May 28, 2024 14:44
Implement ExternalPotential. Pass trial=true/false to control whether
walls will evaluate old energies or assume 0. The old API is not
possible to integrate with the new - callers will need to use both for
now.

Implement the new API in IntegratorHPMCMono.h.

TODO:
- [ ] Implement in BoxMC and MuVT.
- [ ] Implement total energy evaluation (ext.energy and
mc.external_energy).
- [ ] Python API.
- [ ] Gravity potential.
* Use computeTotalExternalEnergy in BoxMC.
* Add `mc.external_energy`

TODO:
- [ ] Implement external in muVT
- [ ] Python API.
- [ ] Gravity potential.
TODO:
- [ ] Python API.
- [ ] Gravity potential.
I did not get very far because I ran into errors in my new test that I
could not figure out how to fix.
I wrote a test that tests attaching external potentials to the
simulation.
However, an exception is raised when HOOMD tries to attach the linear
external potential.
The error message I get is
```
TypeError: (): incompatible function arguments. The following argument types are supported:
    1. (arg0: hoomd.hpmc._hpmc.ExternalPotentialLinear, arg1: hoomd._hoomd.vec3_double) -> None

Invoked with: <hoomd.hpmc._hpmc.ExternalPotentialLinear object at 0x10706f3f0>, (0.0, 0.0, 0.0)
```

The 2nd argument in the "invoked with:" list is a `_HOOMDTuple` and not
a `vec3_double`. I'm not sure if that's the cause of the error, but it's
my best guess.
@joaander joaander requested review from a team, tcmoore3, tommy-waltmann and shihkual and removed request for a team June 11, 2024 20:19
@joaander joaander added the validate Execute long running validation tests on pull requests label Jun 11, 2024
hoomd/hpmc/ExternalPotential.h Outdated Show resolved Hide resolved
hoomd/hpmc/ExternalPotential.h Outdated Show resolved Hide resolved
hoomd/hpmc/ExternalPotentialLinear.h Outdated Show resolved Hide resolved
hoomd/hpmc/ExternalPotentialLinear.h Outdated Show resolved Hide resolved
hoomd/hpmc/ExternalPotential.cc Outdated Show resolved Hide resolved
hoomd/hpmc/external/linear.py Show resolved Hide resolved
Copy link
Contributor

@tommy-waltmann tommy-waltmann left a comment

Choose a reason for hiding this comment

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

This looks to be in good shape, I just had two small comments.

hoomd/hpmc/external/linear.py Show resolved Hide resolved
hoomd/hpmc/ExternalPotentialLinear.cc Show resolved Hide resolved
vec3<Scalar> origin(m_pdata->getOrigin());
const BoxDim box = this->m_pdata->getGlobalBox();
vec3<Scalar> r0 = m_reference_positions[h_tags.data[index]];
Scalar3 t = vec_to_scalar3(position - origin);
box.wrap(t, dummy);
vec3<Scalar> shifted_pos(t);
Copy link
Member

Choose a reason for hiding this comment

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

How did this never trigger an unused variable warning?

old_mean_z = np.mean(snapshot.particles.position[:, 2])
old_energy = ext.energy

for n in range(10):
Copy link
Member

Choose a reason for hiding this comment

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

Given the bug this test uncovered, it's a good thing you happened to realize we could adopt the test from CPPExternalPotential.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if our gravity with no walls test would look more reasonable now?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if our gravity with no walls test would look more reasonable now?

It won't, we ran than in serial...

Also move the slightly longer running z_bias test to validate.
@joaander joaander merged commit 0bce354 into trunk-minor Jun 18, 2024
34 checks passed
@joaander joaander deleted the external-potentials branch June 18, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validate Execute long running validation tests on pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants