Skip to content

Conversation

@clpetix
Copy link
Contributor

@clpetix clpetix commented Sep 15, 2025

Compute bond without using minimum image convention to avoid issues with bonds that are longer than L/2.

@clpetix
Copy link
Contributor Author

clpetix commented Sep 15, 2025

@mphoward, I've copied the file over here and made a change I think should get the unwrapped positions to compute the bond length.

I'm fairly unfamiliar working with C++ projects. Could you explain what the process is like for getting these changes connected in and usable in HOOMD?

@astatt astatt self-assigned this Sep 15, 2025
Copy link
Collaborator

@mphoward mphoward left a comment

Choose a reason for hiding this comment

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

Thanks! See comment for how to implement the change.

The next step will be to add enough code to make this template class compile.

  1. Make a file export_ImageBondPotentialHarmonic.cc, and explicitly wrap the template of the export function from the end of this file for EvaluatorBondHarmonic from hoomd::md. Something like:

    void export_ImageBondPotentialHarmonic(pybind11::module& m)
        {
        hoomd::azplugins::detail::export_ImageBondPotential<hoomd::md::EvaluatorBondHarmonic>(m, "ImageBondPotentialHarmonic");
        }
    

    with necessary includes.

  2. Add this file to src/CMakeLists.txt with the other cc files.

  3. Call the export function in module.cc in the bond potential section.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We will end up simplifying this file using subclassing later, it's fine for now though.

@clpetix
Copy link
Contributor Author

clpetix commented Sep 15, 2025

@mphoward, I've applied those changes and was able to get it to compile without error after a few small tweaks.

Copy link
Collaborator

@mphoward mphoward left a comment

Choose a reason for hiding this comment

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

Looking good! After applying these changes, the next step will be to add a Python object for this class to bond.py and test it. A good name might be like ImageHarmonic or something like that.

You should be able to just copy one of the existing classes and change the Python / C++ class names. I am OK if you also want to farm out most of the documentation to HOOMD as well, since it is the same potential other than how the bond distance is calculated. That part should be documented clearly.

For testing, you can start by adding this potential to the standard list that is there. Then, we should also add a new test case that checks for Image bond potentials that it is computed correctly even in a small box (e.g., put them on opposite edges but the same image, so the true distance is longer than the minimum distance).

@clpetix clpetix self-assigned this Sep 16, 2025
@clpetix
Copy link
Contributor Author

clpetix commented Sep 16, 2025

@mphoward, I have this working on 1 CPU core and added the two test scenarios we discussed. It has an issue when running under MPI. I'm not sure what is happening there. Let me know if you have any ideas on what that could be, before we start with GPU & reducing code duplication.

Copy link
Collaborator

@mphoward mphoward left a comment

Choose a reason for hiding this comment

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

Try requesting that the image be communicated with ghost particles to see if that fixes the problem you were having in MPI. There are still going to be issues in MPI simulations if bond lengths get too long, but that cannot be fixed. We should just document that and make sure the code would throw an error (it probably does) already.

@clpetix
Copy link
Contributor Author

clpetix commented Sep 18, 2025

@mphoward, the parametrized tests are working fine without MPI, but something is off with the MPI versions. The MPI tests worked fine here using the GSD package so I think it must be something with using hoomd.snapshot.

Could you have a look and see if anything sticks out? I think I must just be overlooking something

@mphoward
Copy link
Collaborator

The tests are deadlocking, but it isn't obvious to me where it is happening since there isn't any output. Are you able to compile with MPI locally and run them to do debugging?

@clpetix
Copy link
Contributor Author

clpetix commented Sep 19, 2025

@mphoward, the local version was also gridlocking with no output, but I was able to go line by line, raising errors to figure where it was locking. I had:

if sim.device.communicator.rank == 0:
            numpy.testing.assert_array_almost_equal(
                harmonic.forces, expected_forces, decimal=4
            )

It should have been:

forces = harmonic.forces
if sim.device.communicator.rank == 0:
          numpy.testing.assert_array_almost_equal(forces, expected_forces, decimal=4)

One day I'll figure out this MPI stuff 😅

@mphoward
Copy link
Collaborator

Ah yes, that is expected. That property returns the forces on all particles, even if they are distributed onto multiple ranks, so it is a collective call that needs to be invoked on all processors. The data is only valid on rank 0 though.

Copy link
Collaborator

@mphoward mphoward left a comment

Choose a reason for hiding this comment

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

Here are suggested changes to switch to using inheritance from PotentialBond!

Co-authored-by: Michael Howard <mphoward@auburn.edu>
@clpetix
Copy link
Contributor Author

clpetix commented Sep 22, 2025

@mphoward, thank you for the help switching this over to use inheritance. I think I have it all working!

Copy link
Collaborator

@mphoward mphoward left a comment

Choose a reason for hiding this comment

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

Looks great! Here are just a couple small things. We'll discuss the GPU implementation next.

@clpetix
Copy link
Contributor Author

clpetix commented Sep 24, 2025

@mphoward, I have the GPU implementation working locally and all the tests are passing. I'm not sure what is happening with the actions here.

This should be good for you to have another look at, when you have time!

@mphoward
Copy link
Collaborator

I'm not sure what is happening with the actions here.

There was some authentication error preventing the runner from pulling the Docker container it needs. I re-ran the workflow, and whatever was causing that problem seems to have resolved.

@mphoward mphoward marked this pull request as ready for review September 25, 2025 13:02
Copy link
Collaborator

@mphoward mphoward left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great! Can you please take care of these comments, then we can ping Antonia to have a look.

@clpetix clpetix requested a review from astatt September 25, 2025 16:57
Copy link
Collaborator

@astatt astatt left a comment

Choose a reason for hiding this comment

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

Since all of Mike's comments are resolved and I did not find any additional issues, I think this is ready to merge. Thank you!

@mphoward mphoward merged commit 095ab02 into main Sep 29, 2025
6 checks passed
@mphoward mphoward deleted the feature/bond-no-PBC branch September 29, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants