Implementation of machine learning framework not working with fix_box_relax

Hello,
I am currently working to expand the original AGNI implementation in LAMMPS with the inclusion of 2 new machine learning models for potential energy and stress. This means inside of pair_agni.cpp there are 3 independent machine learning models, one predicting force, one energy, and one the stress tensor. While this has been coded, there are issues that propagate down to other LAMMPS functions that I’m hoping someone can provide some insight towards.

  1. The stress tensor values are currently being passed directly to compute_pressure.cpp. This isn’t ideal, but it works for now. The compute_scalar and compute_vector functions essentially just have a conditional statement saying if(AGNI){do stuff}else{default code}. If I pass the stress values in this way, are there other calls that will change either the scalar or vector terms outside of compute_pressure that I would be missing?

  2. The biggest issue is that fix_box_relax seems completely incompatible with how this ML framework has been implemented. With the stresses being passed via compute_pressure, and forces and energy being passed through ev_tally in the pair style, the box barely moves and the atoms don’t move at all. Contrast this with say EAM, and the fix works as intended. Is there any semi-obvious reason why the way I’ve coded these 3 independent ML models would result in that behaviour?

  3. Following the same thought as question 2, similar issues are occurring during NPT simulations. So again, is passing these values (force, energy, and stress) in the manner I’ve done just simply wrong, and I’m being very naive to assume that it’s that simple?

I understand that these questions are pretty vague, so I’m more than happy to share any code I’ve put together, but if there’s anything obvious that comes to mind just let me know.

Thanks and regards,
James Chapman

Hello,
I am currently working to expand the original AGNI implementation in LAMMPS with the inclusion of 2 new machine learning models for potential energy and stress. This means inside of pair_agni.cpp there are 3 independent machine learning models, one predicting force, one energy, and one the stress tensor. While this has been coded, there are issues that propagate down to other LAMMPS functions that I’m hoping someone can provide some insight towards.

  1. The stress tensor values are currently being passed directly to compute_pressure.cpp. This isn’t ideal, but it works for now. The compute_scalar and compute_vector functions essentially just have a conditional statement saying if(AGNI){do stuff}else{default code}. If I pass the stress values in this way, are there other calls that will change either the scalar or vector terms outside of compute_pressure that I would be missing?

this is a design that conflicts with the design philosophy of LAMMPS.
pair style agni already tallies stress via Pair::ev_tally_xyz_full() and then uses F dot r to compute the stress. if you want to replace this functionality, you could just have a different way to add the stress contribution to the stress arrays. If your alternate way of computing stress(and through it pressure) is not compatible with per-atom stress tallies, you need to check for Pair::vflag_atom and error out. you are not bound to follow the regiment of per-atom tallies and F dot r.
see for example compute styles pressure/uef or PRESSURE/GREM or compute PRESSURE/GREM

if this still does not sound acceptable, the logical way to handle this, would be to implement a compute pressure/agni style that handles then how the pressure is computed, but NOT alter compute pressure.
all fixes/computes/thermo styles that use pressure internally, have ways to utilize a different than the default pressure computes (or temperature computes!). this is for example needed for extended particles. this mechanism allows for a clean implementation of different approaches without encumbering the default implementation with hacks for specific (optional) features.

  1. The biggest issue is that fix_box_relax seems completely incompatible with how this ML framework has been implemented. With the stresses being passed via compute_pressure, and forces and energy being passed through ev_tally in the pair style, the box barely moves and the atoms don’t move at all. Contrast this with say EAM, and the fix works as intended. Is there any semi-obvious reason why the way I’ve coded these 3 independent ML models would result in that behaviour?

impossible to say from remote and without looking at the code, but see my concerns about your point 1. if you handle point 1 correctly (and cleanly), then there should be no issues with point 2.

  1. Following the same thought as question 2, similar issues are occurring during NPT simulations. So again, is passing these values (force, energy, and stress) in the manner I’ve done just simply wrong, and I’m being very naive to assume that it’s that simple?

both fix box/relax and fix npt rely on a pressure compute providing the information they use to adjust box dimensions. so, if you cannot provide that information through the regular tally method, you would need to provide a custom pressure compute.

axel.