Repository: netket/netket

Issue:
Python bindings for Jastrow machines randomly failing
I realized in #91 that once in a while the python tests for the `Jastrow` machines fail. This issue seems related to some memory problem, but I still don't understand if it is on the c++ side or python 


Discussion:
Maybe related to the failures seen in #104 on linux machines

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -58,7 +58,7 @@ def build_extension(self, ext):
 
 setup(
     name='netket',
-    version='0.1',
+    version='2.0',
     author='Giuseppe Carleo et al.',
     description='NetKet',
     url='http://github.com/netket/netket',


Test patch:
diff --git a/Test/Machine/test_machine.py b/Test/Machine/test_machine.py
--- a/Test/Machine/test_machine.py
+++ b/Test/Machine/test_machine.py
@@ -99,7 +99,6 @@ def test_log_derivative():
         print("Machine test: %s" % name)
 
         npar = machine.n_par()
-        randpars = 0.1 * (np.random.randn(npar) + 1.0j * np.random.randn(npar))
 
         # random visibile state
         hi = machine.get_hilbert()
@@ -109,15 +108,18 @@ def test_log_derivative():
 
         for i in range(100):
             hi.random_vals(v, rg)
-            grad = (nd.Gradient(log_val_f, step=1.0e-8))
 
+            randpars = 0.1 * (np.random.randn(npar) +
+                              1.0j * np.random.randn(npar))
             machine.set_parameters(randpars)
             der_log = machine.der_log(v)
 
             if("Jastrow" in name):
                 assert(np.max(np.imag(der_log)) == approx(0.))
 
+            grad = (nd.Gradient(log_val_f, step=1.0e-8))
             num_der_log = grad(randpars, machine, v)
+
             assert(np.max(np.real(der_log - num_der_log))
                    == approx(0., rel=1e-4, abs=1e-4))
             # The imaginary part is a bit more tricky, there might be an arbitrary phase shift
diff --git a/Test/Operator/test_operator.py b/Test/Operator/test_operator.py
--- a/Test/Operator/test_operator.py
+++ b/Test/Operator/test_operator.py
@@ -6,19 +6,19 @@
 operators = {}
 
 # Ising 1D
-g_1 = nk.graph.Hypercube(length=20, ndim=1, pbc=True)
-hi = nk.hilbert.Spin(s=0.5, graph=g_1)
-operators["Ising 1D"] = [nk.operator.Ising(h=1.321, hilbert=hi), hi]
+g = nk.graph.Hypercube(length=20, ndim=1, pbc=True)
+hi = nk.hilbert.Spin(s=0.5, graph=g)
+operators["Ising 1D"] = nk.operator.Ising(h=1.321, hilbert=hi)
 
 # Heisenberg 1D
-g_2 = nk.graph.Hypercube(length=20, ndim=1, pbc=True)
-hi = nk.hilbert.Spin(s=0.5, total_sz=0, graph=g_1)
-operators["Heisenberg 1D"] = [nk.operator.Heisenberg(hilbert=hi), hi]
+g = nk.graph.Hypercube(length=20, ndim=1, pbc=True)
+hi = nk.hilbert.Spin(s=0.5, total_sz=0, graph=g)
+operators["Heisenberg 1D"] = nk.operator.Heisenberg(hilbert=hi)
 
 # Bose Hubbard
-g_3 = nk.graph.Hypercube(length=10, ndim=2, pbc=True)
-hi = nk.hilbert.Boson(n_max=3, n_bosons=23, graph=g_3)
-operators["Bose Hubbard"] = [nk.operator.BoseHubbard(U=4.0, hilbert=hi), hi]
+g = nk.graph.Hypercube(length=3, ndim=2, pbc=True)
+hi = nk.hilbert.Boson(n_max=3, n_bosons=6, graph=g)
+operators["Bose Hubbard"] = nk.operator.BoseHubbard(U=4.0, hilbert=hi)
 
 # Graph Hamiltonian
 # TODO (jamesETsmith)
@@ -30,23 +30,26 @@
 #sy = np.array([[0,1j],[-1j,0]])
 #
 # operators["Custom"] =
+rg = nk.utils.RandomEngine(seed=1234)
 
 
 def test_produce_elements_in_hilbert():
     for name, ha in operators.items():
-        hi = ha[1]
+        hi = ha.get_hilbert()
         print(name, hi)
         assert (len(hi.local_states()) == hi.local_size())
 
         rstate = np.zeros(hi.size())
-        rg = nk.utils.RandomEngine(seed=1234)
+
         local_states = hi.local_states()
 
         for i in range(1000):
             hi.random_vals(rstate, rg)
-            conns = ha[0].get_conn(rstate)
+            conns = ha.get_conn(rstate)
 
             for connector, newconf in zip(conns[1], conns[2]):
-                hi.update_conf(rstate, connector, newconf)
-                for rs in rstate:
+                rstatet = np.array(rstate)
+                hi.update_conf(rstatet, connector, newconf)
+
+                for rs in rstatet:
                     assert(rs in local_states)