Segmentation fault when using extract_compute() in python wrapper

Dear Axel,

I am sorry to have mislead you, I forgot to take care of the cutoff
condition in the example script (in.test) that I showed here. I took this
example to simply demonstrate the idea without other complications. In
actuality, I use an eam.fs potential (Cu-Zr3.eam.fs, link
<https://www.ctcms.nist.gov/potentials/Cu-Zr.html>)---and my cluster/atom
cutoff here is lesser than the pair cutoff. I have now taken care to define
computes outside the run.

Though this was the case, the error came up for me because of a
write_restart command that perhaps invoked the compute during the same run.

​this statement makes no sense.​

However, even without the write_restart command the segmentation fault
error still persists; I am unable to access/play with the values returned
by the extract_compute(). To avoid any unintentional miscommunication in
the future I have attached the actual script I am working with (in.test).

In line #54, I tried to access the vector returned by the compute and this
triggered the error. I have confirmed from a previous thread
<https://sourceforge.net/p/lammps/mailman/message/29349507/>that one does
not need to cast the pointer of the compute's internal structure to a
python float vector, and that the function automatically does it. Any leads
on what else is causing the error would be very helpful.

​the problem is that you are using ​"max(cvec)". cvec is not a python list
or tuple, but a wrapper around a pointer and - same as with a pointer in
C/C++ - there is no size information associated with such a pointer. since
compute cluster/atom returns a per-atom vector, it will be a 1-dimensional
array of doubles with as many elements as you have local atoms.

so you need to replace:
        clumps = [[] for x in range(0, max(cvec))]
with:
        nlocal = l.extract_global("nlocal",0)
        clumps = [cvec[x] for x in range(nlocal)]

Another error comes up when trying to access a variable returned by the
python function. (Please uncomment line# 62 to see this):
* Trying to build an occasional neighbor list before initialization
completed *(According to the manual: This is not allowed. Source code
caller needs to be modified.).
All I am trying to do is pass on a value from python to a python variable
in LAMMPS. Could you please tell me what my mistake is?

​the mistake is using the print command. that will invoke the python
variable and thus the python function, which will access the compute when
it is not ready.​

​at this point, you don't need to use fix python/invoke. but rather can use
instead:

​fix 0 all print 5000 "cltr = ${cltr}"

To explain my question about the set_variables better, I was looking for a
way to pass python variables to LAMMPS. set_variables() seemed like a good
way to do it with strings and I was looking for a variant to handle arrays
or vectors. But I realise that returning the variables via the python
function is a much better thing to do.

​this sounds rather crazy and is not likely to work.​ python variables
returns a global scalar.
please also note, that extract_compute() will provide "local" data, while a
python variable returns a global scalar. so you will likely have to do some
parallel programming.

​overall, it looks to me, that you are spending a massive effort to
shoehorn something that can likely be easily implemented as a new custom
compute or fix into the lammps python interface, through methods that
cannot work. by the time you have figured all of that out, you'd have
learned and spent more time than taking a similar existing chunk of c++
code and adapt it.

axel.