Repository navigation
MLIAP Unified Interface - #3458
Conversation
akohlmey
left a comment
There was a problem hiding this comment.
@Boogie3D @lubbersnick Thanks for your submission. This looks quite nicely done. I've made some - mostly cosmetic - minor changes to improve consistency with the rest of LAMMPS and some (yet undocumented) conventions.
There are a couple notes/questions added in different locations, but neither is a big concern.
| (0/1) to disable/enable the construction of neighbors lists including | ||
| neighbors of ghost atoms. If the filename ends in '.pt', or '.pth', it will be loaded | ||
| using pytorch; otherwise, it will be loaded as a pickle file. | ||
| If ghostneigh is enabled, it is recommended to set :doc:`comm_modify <comm_modify>` |
There was a problem hiding this comment.
FYI: when I enable the "ghostneigh" flag in the in.mliap.unified.lj.Ar example, I get a segmentation fault. Is this expected behavior? Can this be checked for and an error triggered?
Increasing the communication cutoff as suggested below did not make a difference.
There was a problem hiding this comment.
I don't believe this is expected behavior. The error likely comes from neighbor list memory allocation as this segfault occurs while calculating Per MPI Rank memory allocation (see backtrace below). If I reduce the problem size from 4000 atoms to 256 I get a neighbor list overflow instead of a segfault. This error does not happen with the hippynn Al or InP examples.
Core was generated by `lmp -i in.mliap.unified.lj.Ar'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000149cd25883d8 in int_mallinfo () from /lib64/libc.so.6
Missing separate debuginfos, use: yum debuginfo-install glibc-2.28-151.el8.x86_64
(gdb) bt
#0 0x0000149cd25883d8 in int_mallinfo () from /lib64/libc.so.6
#1 0x0000149cd258e09c in mallinfo () from /lib64/libc.so.6
#2 0x0000149cd32247c6 in LAMMPS_NS::Info::get_memory_info (this=this@entry=0x7ffc14762a90, meminfo=meminfo@entry=0x7ffc14762a20)
at /projects/ml4chem/sanaya/lammps/src/info.cpp:1300
#3 0x0000149cd3310b6b in LAMMPS_NS::Output::memory_usage (this=0x744a30) at /projects/ml4chem/sanaya/lammps/src/output.cpp:1018
#4 0x0000149cd33110d1 in LAMMPS_NS::Output::setup (this=0x744a30, memflag=memflag@entry=1) at /projects/ml4chem/sanaya/lammps/src/output.cpp:299
#5 0x0000149cd33f3ae2 in LAMMPS_NS::Verlet::setup (this=0x73ca20, flag=1) at /projects/ml4chem/sanaya/lammps/src/verlet.cpp:160
#6 0x0000149cd33a0c6f in LAMMPS_NS::Run::command (this=0x91bbc0, narg=1, arg=0x749180) at /projects/ml4chem/sanaya/lammps/src/run.cpp:171
#7 0x0000149cd323d1b8 in LAMMPS_NS::Input::execute_command (this=0x72d6f0) at /projects/ml4chem/sanaya/lammps/src/input.cpp:847
#8 0x0000149cd323d58d in LAMMPS_NS::Input::file (this=0x72d6f0) at /projects/ml4chem/sanaya/lammps/src/input.cpp:302
#9 0x0000000000400e85 in main (argc=<optimized out>, argv=<optimized out>) at /projects/ml4chem/sanaya/lammps/src/main.cpp:76
There was a problem hiding this comment.
The gdb trace is bogus. Something has written to an allocated storage block beyond the allocated size and thus messed up the internal malloc data structures.
I have run the code with valgrind and identified the location of the problem at this location:
https://github.com/lammps/lammps/pull/3458/files#diff-cb6b51f0e9ebcb4ecda7e8a34b450fb05f24b7de8a8bfbac614cbfd21af03b6dR256
The index i overflows the dimension of the data->eatoms array which is of size data->nlistatoms.
I am implementing a hack that avoids the crash, but will likely lead to incorrect per-atom energy data.
I would expect that data->eatoms would need to be allocated (and cleared) so it includes ghost atoms and then a reverse communication would be needed to sum the contributions to ghost atoms to their principal owned atoms.
There was a problem hiding this comment.
Also found and fixed a memory leak, an initialization issue and noticed that destructors of some polymorph classes were not make virtutal and general our conventions for using virtual/override were not fully followed.
There was a problem hiding this comment.
@Boogie3D I think I have sorted this out for the LJ example. I could not test the hippynn examples, since I did not see any of the .pt files.
I also added a test that creates two LAMMPS instances with mliap.unified.lj and lj/cut pair styles, respectively and check some results after a couple of MD steps.
There was a problem hiding this comment.
@Boogie3D I think I have sorted this out for the LJ example. I could not test the hippynn examples, since I did not see any of the .pt files. I also added a test that creates two LAMMPS instances with mliap.unified.lj and lj/cut pair styles, respectively and check some results after a couple of MD steps.
The scripts to create the hippynn .pt files are in the hippynn repo but unfortunately require HIPNN training to be performed first; the .pt files themselves are not uploaded anywhere.
Thank you for your various improvements and for solving the problem with memory allocation and LJ so quickly. I am beginning graduate school soon and am not currently working at LANL so I may not have had the time to do so myself.
There was a problem hiding this comment.
the .pt files themselves are not uploaded anywhere
Can you send me a copy of those files via email? I would very much like to make certain that my changes did not break anything.
…ions from non-local i atoms
|
@lubbersnick How do propose to continue with this PR? |
|
@lubbersnick I think @akohlmey has a point about the unrunnable HIPNN examples. Either we should make them runnable or take them out. |
|
@akohlmey @athomps I would like an eventual future where we have an example in the lammps repository because it shows a much more clear reason and use case compared to reimplementing LJ. In some sense the difficulty with including networks in the repository is the number of things to validate in order to prove a network is good/useful for an actual application. Although I don't think it is possible to release a practically useful network from the very limited InP dataset, we can maybe make a standardized one for aluminum. I am slightly confused at the comment that the code is not public - it is, and will very soon be merged into the main hippynn repository. Building your own network for aluminum is our basic example in hippynn. It is probably not worth the effort to do so for the sake of checking the lammps codebase; it requires going to get the training dataset and so on. I will email you a network so you can before/after test your changes if you like. However I am pretty sure that the change to However, it was good to identify this difficulty of mixing update_pair_energies with ghostneigh. We should probably be clear that ghostneigh is connected to the semantics of the model -- models can give different answers with it on or of and so ghostneigh needs to be set as appropriate for that model. So the fact that ghostneigh gives a segfault for LJ does not surprise me. It is better that we have this check instead of corrupting memory though, and very sharp of you to find it. A good 'future work' thing for us would be to set up the mliap interface class to store the ghostneigh information as needed for that model so that the setting cannot be wrong. |
The examples in the LAMMPS repository are not meant to be blueprints for excellent research. Their purpose is to a) demonstrate the syntax and structure of inputs for a given package and b) to provide a reference that can be checked against in case changes to the code base are made that may (or may not) affect a package. In both cases, the input does not have to produce a high accuracy result. If you are concerned about people misusing the network, just make up a new element/compound and for example call it Bovinexcrementum (element symbol BS) and then there is no danger of somebody using it for real research and blaming bad results on you (or rather the main LAMMPS developers, since most people in first approximation blame us for everything that goes wrong, regardless of who actually authored the code).
I followed the instructions given in the pull request description (and in your private email) and in both cases it points to a repository that at that moment did not contain the necessary changes. You cannot expect people to know that this is not correct.
Then a check whether this is required or not should be in the model and a proper error should be thrown if the wrong setting is used, or - even better - the C++ code should have a way to query the model for the correct setting and then there need not be a flag. Same as some manybody potentials already contain the pairwise cutoff and set it accordingly. The available documentation suggests (at least the way how it appears to me) that the flag can be chosen rather freely.
Exactly. For the LJ case, it causes a significant slowdown, for obvious reasons. I just enabled it, since there was nothing saying in the docs that it is not supported and can cause problems, and as part of my test procedure for new features, I try to check different flags added to commands and also run with valgrind and other tools to check for memory issues etc (where possible, the python part is next to impossible to debug that way though). |
Since there seems to be no mention of hippynn in the manual itself and no documentation for how to obtain the code and the potential files (the only reference is |
|
Okay, let's just remove those examples for this PR. At some point I will write an example with more complete documentation and a dummy network. |
I second this for now. |
|
I agree that it is sufficient for now to provide only the LJ example (in two different forms). |
Summary
This PR introduces new features and improvements to the ML-IAP Python component, most prominently including a new "Unified" pair style. It also fixes problems raised in #2934.
Related Issue(s)
Fixes an issue where ML-IAP loads
lammpslibrary separately fromlammps-python.A NumPy example for ML-IAP is also included.
Author(s)
Steven Anaya, LANL | [email protected]
Nicholas Lubbers, LANL | [email protected]
Licensing
By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).
Backward Compatibility
No known backward compatibility problems are introduced by this PR.
Implementation Notes
The main improvement is the addition of the ML-IAP "Unified" pair style, which allows Python libraries to build ML-IAP components for LAMMPS, taking control of both the descriptor and model protocols. This feature allows, among other possibilities, the ability to use Deep Neural Network models which are end-to-end (taking positions as input, rather than features) and those that view the environment of each atom recursively. A pedagogical example showing how Lennard-Jones can be implemented efficiently in Python is provided. There is a corresponding example, which reproduces the classic lj/melt example using this programming technique. There are also several non-trivial examples which give a notion of more practical usage using the HIP-NN Deep Neural Network via the
hippynnpython library.Secondly, this PR introduces improvements to the ML-IAP Python coupling:
lammpslibrary object, rather than seeking out thelammpslibrary. This prevents any possibility thatlammps.lammps()objects andlammps.mliapmodule.Lastly, this PR introduces a few extra features for the ML-IAP pair style and data structure. The ML-IAP pair style can be toggled to use neighbors of ghost atoms, which is required for some kinds of potentials.
It also introduces the following members to the
MLIAPDataclass:double **f- pointer toatom->f, updated on each call togenerate_neighdata()int ntotal- stores total number of owned and ghost atoms on this procint natomneigh- current number of atoms and ghosts in atom neighbor arraysint npairs- number ofijneighbor pairsint *pair_i- array storing index of each i atom for each ij pairint *elems- array storing element of each atom in or not in the neighborlistThe following member is added to the
MLIAPDescriptorclass:double ** cutghost- array storing cutoff for each ghost pairWe used Cython similarly to
mliap_model_python.Post Submission Checklist
Further Information, Files, and Links
https://www.lanl.gov/org/ddste/aldsc/hpc/_assets/docs/posters/22HPC-showcase-poster-anaya.pdf