We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Getting acceptance of numpy metropolis_hastings
The method defining the acceptance for `numpy/metropolis_hastings` in v3.0 is

```python
@property
def acceptance(self):
    """The measured acceptance probability."""
    return _mean(self._accepted_samples) / _mean(self._total_samples)
```

But `self._accepted_samples` and `self._total_samples` are ints. Don't know if this has been fixed in a PR, but if it's not, maybe it should be included.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `netket/stats/_sum_inplace.py`
Content:
```
1 from functools import singledispatch
2 import numpy as _np
3 
4 from netket.utils import mpi_available as _mpi_available, n_nodes as _n_nodes
5 
6 if _mpi_available:
7     from netket.utils import MPI_comm as _MPI_comm
8     from netket.utils import MPI as _MPI
9 
10 
11 @singledispatch
12 def sum_inplace(x):
13     """
14     Computes the elementwie sum of an array or a scalar across all MPI processes.
15     Attempts to perform this sum inplace if possible, but for some types a copy
16     might be returned.
17 
18     Args:
19         a: The input array, which will usually be overwritten in place.
20     Returns:
21         out: The reduced array.
22     """
23     raise TypeError("Unknown type to perform dispatch upon: {}".format(type(x)))
24 
25 
26 #######
27 # Scalar
28 @sum_inplace.register(complex)
29 @sum_inplace.register(_np.float64)
30 @sum_inplace.register(_np.float32)
31 @sum_inplace.register(_np.complex64)
32 @sum_inplace.register(_np.complex128)
33 @sum_inplace.register(float)
34 def sum_inplace_scalar(a):
35     ar = _np.asarray(a)
36 
37     if _n_nodes > 1:
38         _MPI_comm.Allreduce(_MPI.IN_PLACE, ar.reshape(-1), op=_MPI.SUM)
39 
40     return ar
41 
42 
43 ##############
44 # Numpy Array
45 #
46 @sum_inplace.register(_np.ndarray)
47 def sum_inplace_MPI(a):
48     """
49     Computes the elementwise sum of a numpy array over all MPI processes.
50 
51     Args:
52         a (numpy.ndarray): The input array, which will be overwritten in place.
53     """
54     if _n_nodes > 1:
55         _MPI_comm.Allreduce(_MPI.IN_PLACE, a.reshape(-1), op=_MPI.SUM)
56 
57     return a
58 
59 
60 ##############
61 # Jax
62 #
63 from netket.utils import jax_available
64 
65 if jax_available:
66     import numpy as _np
67     import jax
68 
69     @sum_inplace.register(jax.interpreters.xla.DeviceArray)
70     def sum_inplace_jax(x):
71         if not isinstance(x, jax.interpreters.xla.DeviceArray):
72             raise TypeError(
73                 "Argument to sum_inplace_jax must be a DeviceArray, got {}".format(
74                     type(x)
75                 )
76             )
77 
78         if _n_nodes == 1:
79             return x
80 
81         # This below only works on cpus...
82         # we should make this work for gpus too..
83         # TODO: unsafe_buffer_pointer is considered not yet definitive interface
84         ptr = x.block_until_ready().device_buffer.unsafe_buffer_pointer()
85 
86         # The above is faster.
87         # This below should work more often, but might copy.
88         # Depending on future changes in jaxlib, we might have to switch to
89         # this below.
90         # see Google/jax #2123 and #1009
91         # _x = jax.xla._force(x.block_until_ready())
92         # ptr = _x.device_buffer.unsafe_buffer_pointer()
93 
94         # using native numpy because jax's numpy does not have ctypeslib
95         data_pointer = _np.ctypeslib.ndpointer(x.dtype, shape=x.shape)
96 
97         # wrap jax data into a standard numpy array which is handled by MPI
98         arr = data_pointer(ptr).contents
99         _MPI_comm.Allreduce(_MPI.IN_PLACE, arr.reshape(-1), op=_MPI.SUM)
100 
101         return x
102 
103     @sum_inplace.register(jax.interpreters.partial_eval.JaxprTracer)
104     @sum_inplace.register(jax.interpreters.ad.JVPTracer)
105     def sum_inplace_jax_jittracer(x):
106         if _n_nodes == 1:
107             return x
108         else:
109             raise RuntimError(
110                 "Cannot jit through sum_inplace when running with multiple MPI processes."
111             )
112
```

Path: `netket/sampler/numpy/metropolis_hastings.py`
Content:
```
1 from ..abstract_sampler import AbstractSampler
2 from ...stats import mean as _mean
3 from netket import random as _random
4 
5 import math
6 import numpy as _np
7 from numba import jit, int64, float64
8 from ..._jitclass import jitclass
9 
10 
11 class MetropolisHastings(AbstractSampler):
12     def __init__(self, machine, kernel, n_chains=16, sweep_size=None):
13 
14         super().__init__(machine, n_chains)
15 
16         self.n_chains = n_chains
17 
18         self.sweep_size = sweep_size
19 
20         self._kernel = kernel
21 
22         self.machine_pow = 2.0
23         self.reset(True)
24 
25     @property
26     def n_chains(self):
27         return self._n_chains
28 
29     @n_chains.setter
30     def n_chains(self, n_chains):
31         if n_chains < 0:
32             raise ValueError("Expected a positive integer for n_chains ")
33 
34         self._n_chains = n_chains
35 
36         self._state = _np.zeros((n_chains, self._input_size))
37         self._state1 = _np.copy(self._state)
38 
39         self._log_values = _np.zeros(n_chains, dtype=_np.complex128)
40         self._log_values_1 = _np.zeros(n_chains, dtype=_np.complex128)
41         self._log_prob_corr = _np.zeros(n_chains)
42 
43     @property
44     def machine_pow(self):
45         return self._machine_pow
46 
47     @machine_pow.setter
48     def machine_pow(self, m_power):
49         if not _np.isscalar(m_power):
50             raise ValueError("machine_pow should be a scalar.")
51         self._machine_pow = m_power
52 
53     @property
54     def sweep_size(self):
55         return self._sweep_size
56 
57     @sweep_size.setter
58     def sweep_size(self, sweep_size):
59         self._sweep_size = sweep_size if sweep_size != None else self._input_size
60         if self._sweep_size < 0:
61             raise ValueError("Expected a positive integer for sweep_size ")
62 
63     def reset(self, init_random=False):
64         if init_random:
65             self._kernel.random_state(self._state)
66         self._log_values = self.machine.log_val(self._state, out=self._log_values)
67 
68         self._accepted_samples = 0
69         self._total_samples = 0
70 
71     @staticmethod
72     @jit(nopython=True)
73     def acceptance_kernel(
74         state, state1, log_values, log_values_1, log_prob_corr, machine_pow
75     ):
76         accepted = 0
77 
78         for i in range(state.shape[0]):
79             prob = _np.exp(
80                 machine_pow * (log_values_1[i] - log_values[i] + log_prob_corr[i]).real
81             )
82             assert not math.isnan(prob)
83 
84             if prob > _random.uniform(0, 1):
85                 log_values[i] = log_values_1[i]
86                 state[i] = state1[i]
87                 accepted += 1
88 
89         return accepted
90 
91     def __next__(self):
92 
93         _log_val = self.machine.log_val
94         _acc_kernel = self.acceptance_kernel
95         _state = self._state
96         _state1 = self._state1
97         _log_values = self._log_values
98         _log_values_1 = self._log_values_1
99         _log_prob_corr = self._log_prob_corr
100         _machine_pow = self._machine_pow
101         _t_kernel = self._kernel.transition
102 
103         accepted = 0
104 
105         for sweep in range(self.sweep_size):
106 
107             # Propose a new state using the transition kernel
108             _t_kernel(_state, _state1, _log_prob_corr)
109 
110             _log_values_1 = _log_val(_state1, out=_log_values_1)
111 
112             # Acceptance Kernel
113             accepted += _acc_kernel(
114                 _state,
115                 _state1,
116                 _log_values,
117                 _log_values_1,
118                 _log_prob_corr,
119                 _machine_pow,
120             )
121 
122         self._total_samples += self.sweep_size * self.n_chains
123         self._accepted_samples += accepted
124 
125         return self._state
126 
127     @property
128     def acceptance(self):
129         """The measured acceptance probability."""
130         return _mean(self._accepted_samples) / _mean(self._total_samples)
131
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/netket/sampler/numpy/metropolis_hastings.py b/netket/sampler/numpy/metropolis_hastings.py
--- a/netket/sampler/numpy/metropolis_hastings.py
+++ b/netket/sampler/numpy/metropolis_hastings.py
@@ -1,7 +1,8 @@
 from ..abstract_sampler import AbstractSampler
-from ...stats import mean as _mean
 from netket import random as _random
 
+from netket.stats import sum_inplace as _sum_inplace
+
 import math
 import numpy as _np
 from numba import jit, int64, float64
@@ -127,4 +128,4 @@
     @property
     def acceptance(self):
         """The measured acceptance probability."""
-        return _mean(self._accepted_samples) / _mean(self._total_samples)
+        return _sum_inplace(self._accepted_samples) / _sum_inplace(self._total_samples)
diff --git a/netket/stats/_sum_inplace.py b/netket/stats/_sum_inplace.py
--- a/netket/stats/_sum_inplace.py
+++ b/netket/stats/_sum_inplace.py
@@ -31,6 +31,7 @@
 @sum_inplace.register(_np.complex64)
 @sum_inplace.register(_np.complex128)
 @sum_inplace.register(float)
+@sum_inplace.register(int)
 def sum_inplace_scalar(a):
     ar = _np.asarray(a)

{"golden_diff": "diff --git a/netket/sampler/numpy/metropolis_hastings.py b/netket/sampler/numpy/metropolis_hastings.py\n--- a/netket/sampler/numpy/metropolis_hastings.py\n+++ b/netket/sampler/numpy/metropolis_hastings.py\n@@ -1,7 +1,8 @@\n from ..abstract_sampler import AbstractSampler\n-from ...stats import mean as _mean\n from netket import random as _random\n \n+from netket.stats import sum_inplace as _sum_inplace\n+\n import math\n import numpy as _np\n from numba import jit, int64, float64\n@@ -127,4 +128,4 @@\n     @property\n     def acceptance(self):\n         \"\"\"The measured acceptance probability.\"\"\"\n-        return _mean(self._accepted_samples) / _mean(self._total_samples)\n+        return _sum_inplace(self._accepted_samples) / _sum_inplace(self._total_samples)\ndiff --git a/netket/stats/_sum_inplace.py b/netket/stats/_sum_inplace.py\n--- a/netket/stats/_sum_inplace.py\n+++ b/netket/stats/_sum_inplace.py\n@@ -31,6 +31,7 @@\n @sum_inplace.register(_np.complex64)\n @sum_inplace.register(_np.complex128)\n @sum_inplace.register(float)\n+@sum_inplace.register(int)\n def sum_inplace_scalar(a):\n     ar = _np.asarray(a)\n", "issue": "Getting acceptance of numpy metropolis_hastings\nThe method defining the acceptance for `numpy/metropolis_hastings` in v3.0 is\r\n\r\n```python\r\n@property\r\ndef acceptance(self):\r\n    \"\"\"The measured acceptance probability.\"\"\"\r\n    return _mean(self._accepted_samples) / _mean(self._total_samples)\r\n```\r\n\r\nBut `self._accepted_samples` and `self._total_samples` are ints. Don't know if this has been fixed in a PR, but if it's not, maybe it should be included.\n", "before_files": [{"content": "from functools import singledispatch\nimport numpy as _np\n\nfrom netket.utils import mpi_available as _mpi_available, n_nodes as _n_nodes\n\nif _mpi_available:\n    from netket.utils import MPI_comm as _MPI_comm\n    from netket.utils import MPI as _MPI\n\n\n@singledispatch\ndef sum_inplace(x):\n    \"\"\"\n    Computes the elementwie sum of an array or a scalar across all MPI processes.\n    Attempts to perform this sum inplace if possible, but for some types a copy\n    might be returned.\n\n    Args:\n        a: The input array, which will usually be overwritten in place.\n    Returns:\n        out: The reduced array.\n    \"\"\"\n    raise TypeError(\"Unknown type to perform dispatch upon: {}\".format(type(x)))\n\n\n#######\n# Scalar\n@sum_inplace.register(complex)\n@sum_inplace.register(_np.float64)\n@sum_inplace.register(_np.float32)\n@sum_inplace.register(_np.complex64)\n@sum_inplace.register(_np.complex128)\n@sum_inplace.register(float)\ndef sum_inplace_scalar(a):\n    ar = _np.asarray(a)\n\n    if _n_nodes > 1:\n        _MPI_comm.Allreduce(_MPI.IN_PLACE, ar.reshape(-1), op=_MPI.SUM)\n\n    return ar\n\n\n##############\n# Numpy Array\n#\n@sum_inplace.register(_np.ndarray)\ndef sum_inplace_MPI(a):\n    \"\"\"\n    Computes the elementwise sum of a numpy array over all MPI processes.\n\n    Args:\n        a (numpy.ndarray): The input array, which will be overwritten in place.\n    \"\"\"\n    if _n_nodes > 1:\n        _MPI_comm.Allreduce(_MPI.IN_PLACE, a.reshape(-1), op=_MPI.SUM)\n\n    return a\n\n\n##############\n# Jax\n#\nfrom netket.utils import jax_available\n\nif jax_available:\n    import numpy as _np\n    import jax\n\n    @sum_inplace.register(jax.interpreters.xla.DeviceArray)\n    def sum_inplace_jax(x):\n        if not isinstance(x, jax.interpreters.xla.DeviceArray):\n            raise TypeError(\n                \"Argument to sum_inplace_jax must be a DeviceArray, got {}\".format(\n                    type(x)\n                )\n            )\n\n        if _n_nodes == 1:\n            return x\n\n        # This below only works on cpus...\n        # we should make this work for gpus too..\n        # TODO: unsafe_buffer_pointer is considered not yet definitive interface\n        ptr = x.block_until_ready().device_buffer.unsafe_buffer_pointer()\n\n        # The above is faster.\n        # This below should work more often, but might copy.\n        # Depending on future changes in jaxlib, we might have to switch to\n        # this below.\n        # see Google/jax #2123 and #1009\n        # _x = jax.xla._force(x.block_until_ready())\n        # ptr = _x.device_buffer.unsafe_buffer_pointer()\n\n        # using native numpy because jax's numpy does not have ctypeslib\n        data_pointer = _np.ctypeslib.ndpointer(x.dtype, shape=x.shape)\n\n        # wrap jax data into a standard numpy array which is handled by MPI\n        arr = data_pointer(ptr).contents\n        _MPI_comm.Allreduce(_MPI.IN_PLACE, arr.reshape(-1), op=_MPI.SUM)\n\n        return x\n\n    @sum_inplace.register(jax.interpreters.partial_eval.JaxprTracer)\n    @sum_inplace.register(jax.interpreters.ad.JVPTracer)\n    def sum_inplace_jax_jittracer(x):\n        if _n_nodes == 1:\n            return x\n        else:\n            raise RuntimError(\n                \"Cannot jit through sum_inplace when running with multiple MPI processes.\"\n            )\n", "path": "netket/stats/_sum_inplace.py"}, {"content": "from ..abstract_sampler import AbstractSampler\nfrom ...stats import mean as _mean\nfrom netket import random as _random\n\nimport math\nimport numpy as _np\nfrom numba import jit, int64, float64\nfrom ..._jitclass import jitclass\n\n\nclass MetropolisHastings(AbstractSampler):\n    def __init__(self, machine, kernel, n_chains=16, sweep_size=None):\n\n        super().__init__(machine, n_chains)\n\n        self.n_chains = n_chains\n\n        self.sweep_size = sweep_size\n\n        self._kernel = kernel\n\n        self.machine_pow = 2.0\n        self.reset(True)\n\n    @property\n    def n_chains(self):\n        return self._n_chains\n\n    @n_chains.setter\n    def n_chains(self, n_chains):\n        if n_chains < 0:\n            raise ValueError(\"Expected a positive integer for n_chains \")\n\n        self._n_chains = n_chains\n\n        self._state = _np.zeros((n_chains, self._input_size))\n        self._state1 = _np.copy(self._state)\n\n        self._log_values = _np.zeros(n_chains, dtype=_np.complex128)\n        self._log_values_1 = _np.zeros(n_chains, dtype=_np.complex128)\n        self._log_prob_corr = _np.zeros(n_chains)\n\n    @property\n    def machine_pow(self):\n        return self._machine_pow\n\n    @machine_pow.setter\n    def machine_pow(self, m_power):\n        if not _np.isscalar(m_power):\n            raise ValueError(\"machine_pow should be a scalar.\")\n        self._machine_pow = m_power\n\n    @property\n    def sweep_size(self):\n        return self._sweep_size\n\n    @sweep_size.setter\n    def sweep_size(self, sweep_size):\n        self._sweep_size = sweep_size if sweep_size != None else self._input_size\n        if self._sweep_size < 0:\n            raise ValueError(\"Expected a positive integer for sweep_size \")\n\n    def reset(self, init_random=False):\n        if init_random:\n            self._kernel.random_state(self._state)\n        self._log_values = self.machine.log_val(self._state, out=self._log_values)\n\n        self._accepted_samples = 0\n        self._total_samples = 0\n\n    @staticmethod\n    @jit(nopython=True)\n    def acceptance_kernel(\n        state, state1, log_values, log_values_1, log_prob_corr, machine_pow\n    ):\n        accepted = 0\n\n        for i in range(state.shape[0]):\n            prob = _np.exp(\n                machine_pow * (log_values_1[i] - log_values[i] + log_prob_corr[i]).real\n            )\n            assert not math.isnan(prob)\n\n            if prob > _random.uniform(0, 1):\n                log_values[i] = log_values_1[i]\n                state[i] = state1[i]\n                accepted += 1\n\n        return accepted\n\n    def __next__(self):\n\n        _log_val = self.machine.log_val\n        _acc_kernel = self.acceptance_kernel\n        _state = self._state\n        _state1 = self._state1\n        _log_values = self._log_values\n        _log_values_1 = self._log_values_1\n        _log_prob_corr = self._log_prob_corr\n        _machine_pow = self._machine_pow\n        _t_kernel = self._kernel.transition\n\n        accepted = 0\n\n        for sweep in range(self.sweep_size):\n\n            # Propose a new state using the transition kernel\n            _t_kernel(_state, _state1, _log_prob_corr)\n\n            _log_values_1 = _log_val(_state1, out=_log_values_1)\n\n            # Acceptance Kernel\n            accepted += _acc_kernel(\n                _state,\n                _state1,\n                _log_values,\n                _log_values_1,\n                _log_prob_corr,\n                _machine_pow,\n            )\n\n        self._total_samples += self.sweep_size * self.n_chains\n        self._accepted_samples += accepted\n\n        return self._state\n\n    @property\n    def acceptance(self):\n        \"\"\"The measured acceptance probability.\"\"\"\n        return _mean(self._accepted_samples) / _mean(self._total_samples)\n", "path": "netket/sampler/numpy/metropolis_hastings.py"}], "after_files": [{"content": "from functools import singledispatch\nimport numpy as _np\n\nfrom netket.utils import mpi_available as _mpi_available, n_nodes as _n_nodes\n\nif _mpi_available:\n    from netket.utils import MPI_comm as _MPI_comm\n    from netket.utils import MPI as _MPI\n\n\n@singledispatch\ndef sum_inplace(x):\n    \"\"\"\n    Computes the elementwie sum of an array or a scalar across all MPI processes.\n    Attempts to perform this sum inplace if possible, but for some types a copy\n    might be returned.\n\n    Args:\n        a: The input array, which will usually be overwritten in place.\n    Returns:\n        out: The reduced array.\n    \"\"\"\n    raise TypeError(\"Unknown type to perform dispatch upon: {}\".format(type(x)))\n\n\n#######\n# Scalar\n@sum_inplace.register(complex)\n@sum_inplace.register(_np.float64)\n@sum_inplace.register(_np.float32)\n@sum_inplace.register(_np.complex64)\n@sum_inplace.register(_np.complex128)\n@sum_inplace.register(float)\n@sum_inplace.register(int)\ndef sum_inplace_scalar(a):\n    ar = _np.asarray(a)\n\n    if _n_nodes > 1:\n        _MPI_comm.Allreduce(_MPI.IN_PLACE, ar.reshape(-1), op=_MPI.SUM)\n\n    return ar\n\n\n##############\n# Numpy Array\n#\n@sum_inplace.register(_np.ndarray)\ndef sum_inplace_MPI(a):\n    \"\"\"\n    Computes the elementwise sum of a numpy array over all MPI processes.\n\n    Args:\n        a (numpy.ndarray): The input array, which will be overwritten in place.\n    \"\"\"\n    if _n_nodes > 1:\n        _MPI_comm.Allreduce(_MPI.IN_PLACE, a.reshape(-1), op=_MPI.SUM)\n\n    return a\n\n\n##############\n# Jax\n#\nfrom netket.utils import jax_available\n\nif jax_available:\n    import numpy as _np\n    import jax\n\n    @sum_inplace.register(jax.interpreters.xla.DeviceArray)\n    def sum_inplace_jax(x):\n        if not isinstance(x, jax.interpreters.xla.DeviceArray):\n            raise TypeError(\n                \"Argument to sum_inplace_jax must be a DeviceArray, got {}\".format(\n                    type(x)\n                )\n            )\n\n        if _n_nodes == 1:\n            return x\n\n        # This below only works on cpus...\n        # we should make this work for gpus too..\n        # TODO: unsafe_buffer_pointer is considered not yet definitive interface\n        ptr = x.block_until_ready().device_buffer.unsafe_buffer_pointer()\n\n        # The above is faster.\n        # This below should work more often, but might copy.\n        # Depending on future changes in jaxlib, we might have to switch to\n        # this below.\n        # see Google/jax #2123 and #1009\n        # _x = jax.xla._force(x.block_until_ready())\n        # ptr = _x.device_buffer.unsafe_buffer_pointer()\n\n        # using native numpy because jax's numpy does not have ctypeslib\n        data_pointer = _np.ctypeslib.ndpointer(x.dtype, shape=x.shape)\n\n        # wrap jax data into a standard numpy array which is handled by MPI\n        arr = data_pointer(ptr).contents\n        _MPI_comm.Allreduce(_MPI.IN_PLACE, arr.reshape(-1), op=_MPI.SUM)\n\n        return x\n\n    @sum_inplace.register(jax.interpreters.partial_eval.JaxprTracer)\n    @sum_inplace.register(jax.interpreters.ad.JVPTracer)\n    def sum_inplace_jax_jittracer(x):\n        if _n_nodes == 1:\n            return x\n        else:\n            raise RuntimError(\n                \"Cannot jit through sum_inplace when running with multiple MPI processes.\"\n            )\n", "path": "netket/stats/_sum_inplace.py"}, {"content": "from ..abstract_sampler import AbstractSampler\nfrom netket import random as _random\n\nfrom netket.stats import sum_inplace as _sum_inplace\n\nimport math\nimport numpy as _np\nfrom numba import jit, int64, float64\nfrom ..._jitclass import jitclass\n\n\nclass MetropolisHastings(AbstractSampler):\n    def __init__(self, machine, kernel, n_chains=16, sweep_size=None):\n\n        super().__init__(machine, n_chains)\n\n        self.n_chains = n_chains\n\n        self.sweep_size = sweep_size\n\n        self._kernel = kernel\n\n        self.machine_pow = 2.0\n        self.reset(True)\n\n    @property\n    def n_chains(self):\n        return self._n_chains\n\n    @n_chains.setter\n    def n_chains(self, n_chains):\n        if n_chains < 0:\n            raise ValueError(\"Expected a positive integer for n_chains \")\n\n        self._n_chains = n_chains\n\n        self._state = _np.zeros((n_chains, self._input_size))\n        self._state1 = _np.copy(self._state)\n\n        self._log_values = _np.zeros(n_chains, dtype=_np.complex128)\n        self._log_values_1 = _np.zeros(n_chains, dtype=_np.complex128)\n        self._log_prob_corr = _np.zeros(n_chains)\n\n    @property\n    def machine_pow(self):\n        return self._machine_pow\n\n    @machine_pow.setter\n    def machine_pow(self, m_power):\n        if not _np.isscalar(m_power):\n            raise ValueError(\"machine_pow should be a scalar.\")\n        self._machine_pow = m_power\n\n    @property\n    def sweep_size(self):\n        return self._sweep_size\n\n    @sweep_size.setter\n    def sweep_size(self, sweep_size):\n        self._sweep_size = sweep_size if sweep_size != None else self._input_size\n        if self._sweep_size < 0:\n            raise ValueError(\"Expected a positive integer for sweep_size \")\n\n    def reset(self, init_random=False):\n        if init_random:\n            self._kernel.random_state(self._state)\n        self._log_values = self.machine.log_val(self._state, out=self._log_values)\n\n        self._accepted_samples = 0\n        self._total_samples = 0\n\n    @staticmethod\n    @jit(nopython=True)\n    def acceptance_kernel(\n        state, state1, log_values, log_values_1, log_prob_corr, machine_pow\n    ):\n        accepted = 0\n\n        for i in range(state.shape[0]):\n            prob = _np.exp(\n                machine_pow * (log_values_1[i] - log_values[i] + log_prob_corr[i]).real\n            )\n            assert not math.isnan(prob)\n\n            if prob > _random.uniform(0, 1):\n                log_values[i] = log_values_1[i]\n                state[i] = state1[i]\n                accepted += 1\n\n        return accepted\n\n    def __next__(self):\n\n        _log_val = self.machine.log_val\n        _acc_kernel = self.acceptance_kernel\n        _state = self._state\n        _state1 = self._state1\n        _log_values = self._log_values\n        _log_values_1 = self._log_values_1\n        _log_prob_corr = self._log_prob_corr\n        _machine_pow = self._machine_pow\n        _t_kernel = self._kernel.transition\n\n        accepted = 0\n\n        for sweep in range(self.sweep_size):\n\n            # Propose a new state using the transition kernel\n            _t_kernel(_state, _state1, _log_prob_corr)\n\n            _log_values_1 = _log_val(_state1, out=_log_values_1)\n\n            # Acceptance Kernel\n            accepted += _acc_kernel(\n                _state,\n                _state1,\n                _log_values,\n                _log_values_1,\n                _log_prob_corr,\n                _machine_pow,\n            )\n\n        self._total_samples += self.sweep_size * self.n_chains\n        self._accepted_samples += accepted\n\n        return self._state\n\n    @property\n    def acceptance(self):\n        \"\"\"The measured acceptance probability.\"\"\"\n        return _sum_inplace(self._accepted_samples) / _sum_inplace(self._total_samples)\n", "path": "netket/sampler/numpy/metropolis_hastings.py"}]}