Using the python command to launch a python function accessing a file

as I said I tried to use the python command in conjunction with a python type variable to hook python functions into lammps. It works ok unless I try to access another file from the python function with commands such as open(filename). at that point I get a segmentation fault error. By design is it possible to do what I described without getting errors or I’m tryng to do something that’s outside of the scope of what can be done with the python command?
Thank you

Please always report which LAMMPS version you are using and on what platform you are running. Also please provide a minimal example that reproduces the issue (and only that) and the command line that you are launching the calculation with.

Thank you for the reply. I’m providing what information I can be sure of
I’m running LAMMPS (3 Mar 2020) installed on Ubuntu 20.04.4 which is running on wsl2 on my windows 11 operating system.

Trimming down the code shown below to the problematic part, I had misunderstood the problem. the problem is in the pyscal pyscal 2.10.15 documentation package, specifically the command pyscal.system.box.
What’s peculiar is that if I run Lammps without root privileges I get segmentation fault. If I run it with root privileges it says that the pyscal module is not found (whereas in the previous case it imports the module correctly)

the lammps minimal code is
python cowley_SRO_func return v_cowley format f file cowley_SRO_func.py
variable cowley python cowley_SRO_func
print ${cowley}

the python function is
Cowley_SRO_func.py (226 Bytes)
the pyscal.system module is
system.cpp (75.6 KB)
system.h (6.4 KB)

That may not be very peculiar, likely just a consequence of how you installed the pyscal module.

However, there are two major problems that make it difficult for me to help you:

  • You are using a rather old LAMMPS version. We don’t have time to track down possible bugs in older LAMMPS versions. There are known issues with the python embedding that were corrected in a later LAMMPS version, so the primary advice from me is that you need to check with the latest LAMMPS release to see if the issue persists. Without that confirmation it would be too large a risk that I would just chase down a bug that is already fixed.
  • If the problem happens inside the pyscal package, then there is little that can be done on the LAMMPS side anyway. Please note that for some Python versions there are problems when using “sub-interpreters” which is what will happen when you use pyscal since its documentation says it uses pybind11 to integrate c++ code into python. LAMMPS does the same thing, but differently (using ctypes) and we have seen reports of issues of that kind with ctypes and using cython (another approach to embed python). If the segfault is due to that python sub-interpreter issue, then you may need to upgrade your python version. I appeared, was fixed and reappeared a multiple times. I know for a fact that python version 3.10.5 is a “fixed” version (I use a software unrelated to LAMMPS that had the same problem and the segfaults went away after upgrading and checking the python development website about the changes to the code). So what you could do is try to run under the GDB debugger and obtain a stack trace and then we can see if that matches any of the known issues. Upgrading to python 3.10.5 or newer could be another option.