Segmentation fault from the "python command"

Hello everyone,
I meet a problem about the “python command”. when I define a python function and invoke it to evaluate the “TEMPCORE variable” as the “ctempcore function” in the following script shows, the error about segmentation fault reports and kills the process. The python is successfully embeded in lammps and the “loop function” can work well.

Can anybody give some suggestions on how to solve the problem?

Thanks a lot!

Here are the input scripts:

variables input

variable DT equal 4.0 #time step
variable T equal 0.25e6
variable A equal 200
variable r equal 10 #radius of indent
variable R equal 30 #radius of sphere region
variable L equal 35 #half length of system scale
variable DELTA equal 20 #redefine fix npt after DELTA timesteps
variable THERMO equal 250 #print thermo after THERMO timesteps
variable RESTART equal 62500 #write restart after RESTART timesteps
variable Pstart equal 1000.0-10.0*$A/$Tstepdt
variable Pstop equal 1000.0-10.0*$A/T*(step+{DELTA})*dt

init

units real
dimension 3
boundary p p p
atom_style full
timestep ${DT}

create geometry

pair_style lj/charmm/coul/charmm 8.0 10.0 7.0 9.0
bond_style harmonic
angle_style harmonic
special_bonds charmm
read_data data.droplet_npt

regions & groups

region core sphere $L $L $L $R units box side in
group core dynamic all region core every 1

computes

compute tcore core temp

variables output

variable N equal count(all,core)
variable TEMPCORE python ctempcore

functions

python ctempcore input 2 SELF v_N return v_TEMPCORE format pif here “”"
def ctempcore(lmpptr,N):
from lammps import lammps
lmp=lammps(ptr=lmpptr)
if N>1000:
return lmp.extract_compute(tcore,0,0)
else:
return 298
“”"
python loop input 5 SELF v_NT v_T v_DT v_DELTA format pfffi here “”"
def loop(lmpptr,NT,T,DT,DELTA):
from lammps import lammps
lmp = lammps(ptr=lmpptr)
for i in range(0,int(NTT/DT/DELTA)):
lmp.command("fix barostat all npt temp 298.0 298.0 (100.0*dt) iso {Pstart} {Pstop} (250.0
dt) drag 1.0")
lmp.command(“run ${DELTA} pre yes post yes”)
lmp.command(“unfix barostat”)
“”"

fixes

fix 0 all indent 10.0 sphere $L $L $L r units box fix 1 all shake 0.0001 20 0 b 1 a 1 fix print_tempcore all print 1 "{TEMPCORE}" file tempcore.dat screen no title “”
fix print_n all print 1 “${N}” file n.dat screen no title “”

run

thermo_style custom step temp press
thermo {THERMO} restart {RESTART} restart.droplet
python loop invoke

Here are the error messages:

[ubuntu:04018] *** Process received signal ***
[ubuntu:04018] Signal: Segmentation fault (11)
[ubuntu:04018] Signal code: Address not mapped (1)
[ubuntu:04018] Failing at address: 0x18
[ubuntu:04018] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10330)[0x7f776ca06330]
[ubuntu:04018] [ 1] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x2a)[0x7f776c5a808a]
[ubuntu:04018] [ 2] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x47)[0x7f776c63b5f7]
[ubuntu:04018] [ 3] ./lmp_mpi(_ZN9LAMMPS_NS6Python15invoke_functionEiPc+0x1fd)[0x8ac5bd]
[ubuntu:04018] [ 4] ./lmp_mpi(_ZN9LAMMPS_NS8Variable8retrieveEPc+0x523)[0x8feca3]
[ubuntu:04018] [ 5] ./lmp_mpi(_ZN9LAMMPS_NS5Input10substituteERPcS2_RiS3_i+0x3ad)[0x69c6dd]
[ubuntu:04018] [ 6] ./lmp_mpi(_ZN9LAMMPS_NS8FixPrint11end_of_stepEv+0x4e)[0x610e9e]
[ubuntu:04018] [ 7] ./lmp_mpi(_ZN9LAMMPS_NS6Modify11end_of_stepEv+0x78)[0x6c83b8]
[ubuntu:04018] [ 8] ./lmp_mpi(_ZN9LAMMPS_NS6Verlet3runEi+0x49e)[0x90a71e]
[ubuntu:04018] [ 9] ./lmp_mpi(_ZN9LAMMPS_NS3Run7commandEiPPc+0x8ec)[0x8d8cec]
[ubuntu:04018] [10] ./lmp_mpi(_ZN9LAMMPS_NS5Input15command_creatorINS_3RunEEEvPNS_6LAMMPSEiPPc+0x26)[0x6a6216]
[ubuntu:04018] [11] ./lmp_mpi(_ZN9LAMMPS_NS5Input15execute_commandEv+0x7e1)[0x6a46b1]
[ubuntu:04018] [12] ./lmp_mpi(ZN9LAMMPS_NS5Input3oneEPKc+0x85)[0x6a5445]
[ubuntu:04018] [13] /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call_unix64+0x4c)[0x7f77601d6adc]
[ubuntu:04018] [14] /usr/lib/x86_64-linux-gnu/libffi.so.6(ffi_call+0x1fc)[0x7f77601d640c]
[ubuntu:04018] [15] /usr/lib/python2.7/lib-dynload/
ctypes.x86_64-linux-gnu.so(ctypes_callproc+0x48e)[0x7f77606ce5fe]
[ubuntu:04018] [16] /usr/lib/python2.7/lib-dynload/
ctypes.x86_64-linux-gnu.so(+0x15f9e)[0x7f77606cff9e]
[ubuntu:04018] [17] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f776c5a80a3]
[ubuntu:04018] [18] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x2316)[0x7f776c5cf2d6]
[ubuntu:04018] [19] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x80d)[0x7f776c5d3c3d]
[ubuntu:04018] [20] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x48d8)[0x7f776c5d1898]
[ubuntu:04018] [21] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x80d)[0x7f776c5d3c3d]
[ubuntu:04018] [22] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(+0x141dd0)[0x7f776c5d3dd0]
[ubuntu:04018] [23] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyObject_Call+0x43)[0x7f776c5a80a3]
[ubuntu:04018] [24] /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x47)[0x7f776c63b5f7]
[ubuntu:04018] [25] ./lmp_mpi(_ZN9LAMMPS_NS6Python15invoke_functionEiPc+0x1fd)[0x8ac5bd]
[ubuntu:04018] [26] ./lmp_mpi(_ZN9LAMMPS_NS5Input15execute_commandEv+0x9bc)[0x6a488c]
[ubuntu:04018] [27] ./lmp_mpi(_ZN9LAMMPS_NS5Input4fileEv+0x312)[0x6a5192]
[ubuntu:04018] [28] ./lmp_mpi(main+0x46)[0x4a2226]
[ubuntu:04018] [29] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f776b5ecf45]
[ubuntu:04018] *** End of error message ***
Segmentation fault (core dumped)

Hello everyone,
       I meet a problem about the "python command". when I define a python
function and invoke it to evaluate the "TEMPCORE variable" as the
"ctempcore function" in the following script shows, the error about
segmentation fault reports and kills the process. The python is
successfully embeded in lammps and the "loop function" can work well.
Can anybody give some suggestions on how to solve the problem?

​there is no good reason to use python commands here. you are just making
things needlessly complex and difficult to debug.

the ctempcore function can be easily replaced by an equal style variable:

​variable TEMPCORE equal (v_N>1000)*c_tcore+(v_N<=1000)*298.0

​similarly, the loop function can be ​easily replaced with a loop style
variable and a standard LAMMPS loop construct:

example:

variable a loop 1000
label loop
fix barostat all npt temp 298.0 298.0 \(100\.0\*dt\) iso {Pstart} \{Pstop\} (250.0*dt) drag 1.0
run ${DELTA} pre yes post yes
unfix barostat"
next a
jump SELF loop

​therefore, i strongly discourage you from using python and instead use the
simpler constructs above.​
​that said, there are obvious issues with *both* python functions.​

​as for the segfault. first off, you didn't mention your LAMMPS version.
this is crucial information when reporting segfaults and other unexpected
LAMMPS behavior. thus if you have not done so, please update to the latest
version (31 March 2017 currently). you may receive a more meaningful error
messages. significant effort has been made to make python support more

in addition, in your ctempcore python function you are passing the id tcore
as a literal and not as a string ('tcore' or "tcore"). this is a bug. i
also see your python loop function referencing a variable NT, but i don't
see it defined in your input. also from the stack trace it looks the issue
is due to evaluation of a LAMMPS variable.

apart from that, where is the value in re-initializing the nose-hoover
chains every few steps? especially considering, that your relaxation times
are 5 to 12.5 times larger than the duration of each segment. this is most
certainly not an NPT ensemble that you are simulating here.

axel.

​​