Segmentation fault when using python

Hello everyone.

I should run multiple lammps inputs, say 500 inputs (just single point calculation) and extract total energy. I need this to iteratively optimize some force filed parameters. I used my own python script for this optimization. So, my problem is that when I try to run lammps by python module (lammps, PyLammps), I will face the following problem: “Segemntation fault (core dumped)” after successfully calculated 3 or 4 inputs (first works, then writes error).
Instead if I submit them as usual (lmp -in input.in) via python os.system() command, it works without any problem. The problem is that it takes a bit much time to initialize the calculation and to extract all data I need. That’s why I want to use python to make my script effective and faster. Is this bug or is there anything I should pay attention to fix?

My Lammps version is 2023 Aug. 2.
Python version is 3.10.9

Best regards,
Tolib.

There are two issues at hand here:

  • how to make your calculation efficient
  • how to determine the reason for your crashes and how to avoid them

If you create new LAMMPS instances for each calculation, there are no savings over just running LAMMPS from the command line. The cost for a single point calculation (run 0 post no) is going to dominate anyway. You should be able to avoid restarting “everything” since you can easily just change the pair_coeff settings and then recompute. That should save you the cost of the neighbor list rebuild for as long as you don’t change cutoffs.

To determine the cause of the crash, more information is needed. E.g. your python script and a way to reproduce the segfault (it does not have to be for your system of interest, you can just construct a smaller/simpler one that runs faster which will make it easier to debug) or some stack trace information as shown here: 11.4. Debugging crashes — LAMMPS documentation