segfault when trying to load wf on RbmSpinSymm if hilbert space goes out of scope
Created by: skkestrel
if the hilbert space goes out of scope, the RbmSpinSymm doesn't keep the reference alive.
below are the test cases:
- graph and hilbert both in scope, OK
- graph is out of scope, hilbert in scope, OK
- graph and hilbert both out of scope, error
is the RbmSpinSymm not incrementing the reference counter for the hilbert?
import netket as nk
print('****** SAVE LOAD TEST 1')
g = nk.graph.Hypercube(length=4, n_dim=2, pbc=True)
hi = nk.hilbert.Spin(s=0.5, graph=g, total_sz=0)
ma = nk.machine.RbmSpinSymm(alpha=8, hilbert=hi)
ma.save('temp.wf')
ma.load('temp.wf')
print('****** SAVE LOAD TEST 1 OK')
print('****** SAVE LOAD TEST 2')
def get_hilbert():
g = nk.graph.Hypercube(length=4, n_dim=2, pbc=True)
hi = nk.hilbert.Spin(s=0.5, graph=g, total_sz=0)
return hi
hi = get_hilbert()
ma = nk.machine.RbmSpinSymm(alpha=8, hilbert=hi)
ma.save('temp.wf')
ma.load('temp.wf')
print('****** SAVE LOAD TEST 2 OK')
print('****** SAVE LOAD TEST 3')
def get_rbm():
g = nk.graph.Hypercube(length=4, n_dim=2, pbc=True)
hi = nk.hilbert.Spin(s=0.5, graph=g, total_sz=0)
ma = nk.machine.RbmSpinSymm(alpha=8, hilbert=hi)
return ma
ma = get_rbm()
ma.save('temp.wf')
ma.load('temp.wf')
print('****** SAVE LOAD TEST 3 OK')
output:
****** SAVE LOAD TEST 1
# RBM Initizialized with nvisible = 16 and nhidden = 128
# Symmetries are being used : 137 parameters left, instead of 2192
# RBM Initizialized with nvisible = 16 and nhidden = 128
# Symmetries are being used : 137 parameters left, instead of 2192
****** SAVE LOAD TEST 1 OK
****** SAVE LOAD TEST 2
# RBM Initizialized with nvisible = 16 and nhidden = 128
# Symmetries are being used : 137 parameters left, instead of 2192
# RBM Initizialized with nvisible = 16 and nhidden = 128
# Symmetries are being used : 137 parameters left, instead of 2192
****** SAVE LOAD TEST 2 OK
****** SAVE LOAD TEST 3
# RBM Initizialized with nvisible = 16 and nhidden = 128
# Symmetries are being used : 137 parameters left, instead of 2192
[Timefall:10516] *** Process received signal ***
[Timefall:10516] Signal: Segmentation fault (11)
[Timefall:10516] Signal code: (128)