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

Add param_array to CPPExternalPotential #1608

Merged
merged 9 commits into from Sep 8, 2023

Conversation

tcmoore3
Copy link
Member

@tcmoore3 tcmoore3 commented Aug 17, 2023

Description

Adds variable parameters to hpmc.external.user.CPPExternalPotential, directly analogous to the param_arrays in the hpmc.pair.user classes.

This is technically an API-breaking change suited for a major release, but there is a clear warning in the python class documentation that this feature is experimental.

Motivation and context

Can change parameters in the external potential function.

How has this been tested?

The existing tests pass, and I have been using it in exploratory simulations for research. I haven't yet, but I will add a more direct unit test of changing the values in param_array.

Change log

- Add variable parameters to `hpmc.external.user.CPPExternalPotential`

Checklist:

@tcmoore3 tcmoore3 requested review from a team as code owners August 17, 2023 01:28
@tcmoore3 tcmoore3 requested review from joaander and vyasr and removed request for a team August 17, 2023 01:28
@tcmoore3 tcmoore3 added the enhancement New feature or request label Aug 17, 2023
@tcmoore3 tcmoore3 marked this pull request as draft August 17, 2023 01:29
@tcmoore3
Copy link
Member Author

pre-commit.ci autofix

@tcmoore3 tcmoore3 marked this pull request as ready for review August 19, 2023 01:50
@tcmoore3 tcmoore3 requested review from joaander, a team and Tobias-Dwyer and removed request for a team August 19, 2023 01:51
Copy link
Member

@joaander joaander left a comment

Choose a reason for hiding this comment

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

Thanks! Changes are needed to not break the existing API and expand testing.

hoomd/hpmc/external/user.py Outdated Show resolved Hide resolved
@@ -10,17 +10,13 @@
# check if llvm_enabled
llvm_disabled = not hoomd.version.llvm_enabled

valid_constructor_args = [dict(code='return -1;')]
valid_constructor_args = [dict(code='return -1;', param_array=[1])]
Copy link
Member

Choose a reason for hiding this comment

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

Also test with no param_arary to ensure that the existing API functions.

@@ -175,7 +198,8 @@ def test_electric_field(device, orientations, charge, result,

sim = simulation_factory(two_particle_snapshot_factory())

ext = hoomd.hpmc.external.user.CPPExternalPotential(code=electric_field)
ext = hoomd.hpmc.external.user.CPPExternalPotential(code=electric_field,
param_array=[0])
Copy link
Member

Choose a reason for hiding this comment

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

This code doesn't use param_array. It should remain unchanged and should continue to function.

@@ -76,7 +85,7 @@ class CPPExternalPotential(ExternalField):

gravity_code = "return r_i.z + box.getL().z/2;"
gravity = hoomd.hpmc.external.user.CPPExternalPotential(
code=gravity_code)
code=gravity_code, param_array=[])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
code=gravity_code, param_array=[])
code=gravity_code)

The user should not need to explicitly set param_array=[]. Doing so will break all existing scripts that use `CPPExternalPotential).

Also, update this example to run successfully in Sybil.

hoomd/hpmc/external/user.py Show resolved Hide resolved
hoomd/hpmc/external/user.py Show resolved Hide resolved
hoomd/hpmc/external/user.py Show resolved Hide resolved
@joaander joaander added the validate Execute long running validation tests on pull requests label Sep 7, 2023
Copy link
Contributor

@Tobias-Dwyer Tobias-Dwyer left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for adding this functionality.

Copy link
Member

@joaander joaander left a comment

Choose a reason for hiding this comment

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

Thanks!

hoomd/hpmc/pytest/test_external_user.py Outdated Show resolved Hide resolved
hoomd/hpmc/pytest/test_external_user.py Outdated Show resolved Hide resolved
@joaander joaander merged commit 8a23cb0 into trunk-minor Sep 8, 2023
40 checks passed
@joaander joaander deleted the hpmc-external-field-param_array branch September 8, 2023 11:59
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.

None yet

3 participants