Segmentation fault when performing operations on operators
Created by: PhilipVinc
As pointed out by @femtobit in #203, when we perform arithmetic operations with operators in python, creating new objects, we do not tell the reference counter in python that there are new references to the hilbert
object. This can lead to segmentation faults (See example below):
import netket as nk
g = nk.graph.Hypercube(8, 1)
hi = nk.hilbert.Spin(g, 1/2)
lo = nk.operator.LocalOperator(hi, [[1,0],[0,1]], [0])
lo = lo*lo
# Assign hi to something else so it will no longer keep alive the original Hilbert object
hi = nk.hilbert.Qubit(g)
# This will try to access the now deleted Hilbert object
lo = lo * lo
One possible solution might be to use std::shared_ptr
in place of a reference. Otherwise we must find a way to explicitly update python/pybind reference counter.