We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
OverflowError when using random_state with Fock space
This produces an `OverflowError` on my system:
```python
import netket as nk

hi = nk.hilbert.Fock(N=1)
print(hi) # Fock(n_max=INT_MAX, N=1)

rng = nk.jax.PRNGSeq(0)
hi.random_state(next(seq))
```
```
OverflowError: Python int 9223372036854775808 too large to convert to int64
```

Note that `9223372036854775808` is `hi.n_max + 1` so it appears to be an off-by-one error somewhere.
OverflowError when using random_state with Fock space
This produces an `OverflowError` on my system:
```python
import netket as nk

hi = nk.hilbert.Fock(N=1)
print(hi) # Fock(n_max=INT_MAX, N=1)

rng = nk.jax.PRNGSeq(0)
hi.random_state(next(seq))
```
```
OverflowError: Python int 9223372036854775808 too large to convert to int64
```

Note that `9223372036854775808` is `hi.n_max + 1` so it appears to be an off-by-one error somewhere.

--- 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/hilbert/fock.py`
Content:
```
1 # Copyright 2021 The NetKet Authors - All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from typing import List, Optional, Union
16 
17 import numpy as np
18 from numba import jit
19 
20 from netket.graph import AbstractGraph
21 
22 from .homogeneous import HomogeneousHilbert
23 from ._deprecations import graph_to_N_depwarn
24 
25 
26 @jit(nopython=True)
27 def _sum_constraint(x, n_particles):
28     return np.sum(x, axis=1) == n_particles
29 
30 
31 class Fock(HomogeneousHilbert):
32     r"""Hilbert space obtained as tensor product of local fock basis."""
33 
34     def __init__(
35         self,
36         n_max: Optional[int] = None,
37         N: int = 1,
38         n_particles: Optional[int] = None,
39         graph: Optional[AbstractGraph] = None,
40     ):
41         r"""
42         Constructs a new ``Boson`` given a maximum occupation number, number of sites
43         and total number of bosons.
44 
45         Args:
46           n_max: Maximum occupation for a site (inclusive). If None, the local
47             occupation number is unbounded.
48           N: number of bosonic modes (default = 1)
49           n_particles: Constraint for the number of particles. If None, no constraint
50             is imposed.
51           graph: (Deprecated, pleaese use `N`) A graph, from which the number of nodes
52             is extracted.
53 
54         Examples:
55            Simple boson hilbert space.
56 
57            >>> from netket.hilbert import Fock
58            >>> hi = Fock(n_max=5, n_particles=11, N=3)
59            >>> print(hi.size)
60            3
61            >>> print(hi.n_states)
62            15
63         """
64         N = graph_to_N_depwarn(N=N, graph=graph)
65 
66         self._n_max = n_max
67 
68         if n_particles is not None:
69             n_particles = int(n_particles)
70             self._n_particles = n_particles
71             assert n_particles > 0
72 
73             if self._n_max is None:
74                 self._n_max = n_particles
75             else:
76                 if self._n_max * N < n_particles:
77                     raise Exception(
78                         """The required total number of bosons is not compatible
79                         with the given n_max."""
80                     )
81 
82             def constraints(x):
83                 return _sum_constraint(x, n_particles)
84 
85         else:
86             constraints = None
87             self._n_particles = None
88 
89         if self._n_max is not None:
90             # assert self._n_max > 0
91             local_states = np.arange(self._n_max + 1)
92         else:
93             max_ind = np.iinfo(np.intp).max
94             self._n_max = max_ind
95             local_states = None
96 
97         super().__init__(local_states, N, constraints)
98 
99     @property
100     def n_max(self) -> Optional[int]:
101         r"""The maximum number of bosons per site, or None
102         if the number is unconstrained."""
103         return self._n_max
104 
105     @property
106     def n_particles(self) -> Optional[int]:
107         r"""The total number of particles, or None
108         if the number is unconstrained."""
109         return self._n_particles
110 
111     def __pow__(self, n) -> "Fock":
112         if self.n_particles is None:
113             n_particles = None
114         else:
115             n_particles = n_particles * n
116 
117         return Fock(self.n_max, self.size * n, n_particles=n_particles)
118 
119     def _mul_sametype_(self, other: "Fock") -> "Fock":
120         assert type(self) == type(other)
121         if self.n_max == other.n_max:
122             if self._n_particles is None and other._n_particles is None:
123                 return Fock(self.n_max, N=self.size + other.size)
124 
125         return NotImplemented
126 
127     def ptrace(self, sites: Union[int, List]) -> Optional["Fock"]:
128         if isinstance(sites, int):
129             sites = [sites]
130 
131         for site in sites:
132             if site < 0 or site >= self.size:
133                 raise ValueError(
134                     f"Site {site} not in this hilbert space of site {self.size}"
135                 )
136 
137         if self.n_particles is not None:
138             raise TypeError(
139                 "Cannot take the partial trace with a total particles constraint."
140             )
141 
142         Nsites = len(sites)
143 
144         if self.size - Nsites == 0:
145             return None
146         else:
147             return Fock(self.n_max, N=self.size - Nsites)
148 
149     def __repr__(self):
150         n_particles = (
151             ", n_particles={}".format(self._n_particles)
152             if self._n_particles is not None
153             else ""
154         )
155         nmax = self._n_max if self._n_max < np.iinfo(np.intp).max else "INT_MAX"
156         return "Fock(n_max={}{}, N={})".format(nmax, n_particles, self._size)
157 
158     @property
159     def _attrs(self):
160         return (self.size, self._n_max, self._constraint_fn)
161
```
--- 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/hilbert/fock.py b/netket/hilbert/fock.py
--- a/netket/hilbert/fock.py
+++ b/netket/hilbert/fock.py
@@ -22,6 +22,13 @@
 from .homogeneous import HomogeneousHilbert
 from ._deprecations import graph_to_N_depwarn
 
+FOCK_MAX = np.iinfo(np.intp).max - 1
+"""
+Maximum number of particles in the fock space.
+It is `maxvalue(np.int64)-1` because we use N+1 in several formulas
+and it would overflow.
+"""
+
 
 @jit(nopython=True)
 def _sum_constraint(x, n_particles):
@@ -90,8 +97,7 @@
             # assert self._n_max > 0
             local_states = np.arange(self._n_max + 1)
         else:
-            max_ind = np.iinfo(np.intp).max
-            self._n_max = max_ind
+            self._n_max = FOCK_MAX
             local_states = None
 
         super().__init__(local_states, N, constraints)
@@ -152,7 +158,7 @@
             if self._n_particles is not None
             else ""
         )
-        nmax = self._n_max if self._n_max < np.iinfo(np.intp).max else "INT_MAX"
+        nmax = self._n_max if self._n_max < FOCK_MAX else "FOCK_MAX"
         return "Fock(n_max={}{}, N={})".format(nmax, n_particles, self._size)
 
     @property

{"golden_diff": "diff --git a/netket/hilbert/fock.py b/netket/hilbert/fock.py\n--- a/netket/hilbert/fock.py\n+++ b/netket/hilbert/fock.py\n@@ -22,6 +22,13 @@\n from .homogeneous import HomogeneousHilbert\n from ._deprecations import graph_to_N_depwarn\n \n+FOCK_MAX = np.iinfo(np.intp).max - 1\n+\"\"\"\n+Maximum number of particles in the fock space.\n+It is `maxvalue(np.int64)-1` because we use N+1 in several formulas\n+and it would overflow.\n+\"\"\"\n+\n \n @jit(nopython=True)\n def _sum_constraint(x, n_particles):\n@@ -90,8 +97,7 @@\n             # assert self._n_max > 0\n             local_states = np.arange(self._n_max + 1)\n         else:\n-            max_ind = np.iinfo(np.intp).max\n-            self._n_max = max_ind\n+            self._n_max = FOCK_MAX\n             local_states = None\n \n         super().__init__(local_states, N, constraints)\n@@ -152,7 +158,7 @@\n             if self._n_particles is not None\n             else \"\"\n         )\n-        nmax = self._n_max if self._n_max < np.iinfo(np.intp).max else \"INT_MAX\"\n+        nmax = self._n_max if self._n_max < FOCK_MAX else \"FOCK_MAX\"\n         return \"Fock(n_max={}{}, N={})\".format(nmax, n_particles, self._size)\n \n     @property\n", "issue": "OverflowError when using random_state with Fock space\nThis produces an `OverflowError` on my system:\r\n```python\r\nimport netket as nk\r\n\r\nhi = nk.hilbert.Fock(N=1)\r\nprint(hi) # Fock(n_max=INT_MAX, N=1)\r\n\r\nrng = nk.jax.PRNGSeq(0)\r\nhi.random_state(next(seq))\r\n```\r\n```\r\nOverflowError: Python int 9223372036854775808 too large to convert to int64\r\n```\r\n\r\nNote that `9223372036854775808` is `hi.n_max + 1` so it appears to be an off-by-one error somewhere.\nOverflowError when using random_state with Fock space\nThis produces an `OverflowError` on my system:\r\n```python\r\nimport netket as nk\r\n\r\nhi = nk.hilbert.Fock(N=1)\r\nprint(hi) # Fock(n_max=INT_MAX, N=1)\r\n\r\nrng = nk.jax.PRNGSeq(0)\r\nhi.random_state(next(seq))\r\n```\r\n```\r\nOverflowError: Python int 9223372036854775808 too large to convert to int64\r\n```\r\n\r\nNote that `9223372036854775808` is `hi.n_max + 1` so it appears to be an off-by-one error somewhere.\n", "before_files": [{"content": "# Copyright 2021 The NetKet Authors - All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom typing import List, Optional, Union\n\nimport numpy as np\nfrom numba import jit\n\nfrom netket.graph import AbstractGraph\n\nfrom .homogeneous import HomogeneousHilbert\nfrom ._deprecations import graph_to_N_depwarn\n\n\n@jit(nopython=True)\ndef _sum_constraint(x, n_particles):\n    return np.sum(x, axis=1) == n_particles\n\n\nclass Fock(HomogeneousHilbert):\n    r\"\"\"Hilbert space obtained as tensor product of local fock basis.\"\"\"\n\n    def __init__(\n        self,\n        n_max: Optional[int] = None,\n        N: int = 1,\n        n_particles: Optional[int] = None,\n        graph: Optional[AbstractGraph] = None,\n    ):\n        r\"\"\"\n        Constructs a new ``Boson`` given a maximum occupation number, number of sites\n        and total number of bosons.\n\n        Args:\n          n_max: Maximum occupation for a site (inclusive). If None, the local\n            occupation number is unbounded.\n          N: number of bosonic modes (default = 1)\n          n_particles: Constraint for the number of particles. If None, no constraint\n            is imposed.\n          graph: (Deprecated, pleaese use `N`) A graph, from which the number of nodes\n            is extracted.\n\n        Examples:\n           Simple boson hilbert space.\n\n           >>> from netket.hilbert import Fock\n           >>> hi = Fock(n_max=5, n_particles=11, N=3)\n           >>> print(hi.size)\n           3\n           >>> print(hi.n_states)\n           15\n        \"\"\"\n        N = graph_to_N_depwarn(N=N, graph=graph)\n\n        self._n_max = n_max\n\n        if n_particles is not None:\n            n_particles = int(n_particles)\n            self._n_particles = n_particles\n            assert n_particles > 0\n\n            if self._n_max is None:\n                self._n_max = n_particles\n            else:\n                if self._n_max * N < n_particles:\n                    raise Exception(\n                        \"\"\"The required total number of bosons is not compatible\n                        with the given n_max.\"\"\"\n                    )\n\n            def constraints(x):\n                return _sum_constraint(x, n_particles)\n\n        else:\n            constraints = None\n            self._n_particles = None\n\n        if self._n_max is not None:\n            # assert self._n_max > 0\n            local_states = np.arange(self._n_max + 1)\n        else:\n            max_ind = np.iinfo(np.intp).max\n            self._n_max = max_ind\n            local_states = None\n\n        super().__init__(local_states, N, constraints)\n\n    @property\n    def n_max(self) -> Optional[int]:\n        r\"\"\"The maximum number of bosons per site, or None\n        if the number is unconstrained.\"\"\"\n        return self._n_max\n\n    @property\n    def n_particles(self) -> Optional[int]:\n        r\"\"\"The total number of particles, or None\n        if the number is unconstrained.\"\"\"\n        return self._n_particles\n\n    def __pow__(self, n) -> \"Fock\":\n        if self.n_particles is None:\n            n_particles = None\n        else:\n            n_particles = n_particles * n\n\n        return Fock(self.n_max, self.size * n, n_particles=n_particles)\n\n    def _mul_sametype_(self, other: \"Fock\") -> \"Fock\":\n        assert type(self) == type(other)\n        if self.n_max == other.n_max:\n            if self._n_particles is None and other._n_particles is None:\n                return Fock(self.n_max, N=self.size + other.size)\n\n        return NotImplemented\n\n    def ptrace(self, sites: Union[int, List]) -> Optional[\"Fock\"]:\n        if isinstance(sites, int):\n            sites = [sites]\n\n        for site in sites:\n            if site < 0 or site >= self.size:\n                raise ValueError(\n                    f\"Site {site} not in this hilbert space of site {self.size}\"\n                )\n\n        if self.n_particles is not None:\n            raise TypeError(\n                \"Cannot take the partial trace with a total particles constraint.\"\n            )\n\n        Nsites = len(sites)\n\n        if self.size - Nsites == 0:\n            return None\n        else:\n            return Fock(self.n_max, N=self.size - Nsites)\n\n    def __repr__(self):\n        n_particles = (\n            \", n_particles={}\".format(self._n_particles)\n            if self._n_particles is not None\n            else \"\"\n        )\n        nmax = self._n_max if self._n_max < np.iinfo(np.intp).max else \"INT_MAX\"\n        return \"Fock(n_max={}{}, N={})\".format(nmax, n_particles, self._size)\n\n    @property\n    def _attrs(self):\n        return (self.size, self._n_max, self._constraint_fn)\n", "path": "netket/hilbert/fock.py"}], "after_files": [{"content": "# Copyright 2021 The NetKet Authors - All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom typing import List, Optional, Union\n\nimport numpy as np\nfrom numba import jit\n\nfrom netket.graph import AbstractGraph\n\nfrom .homogeneous import HomogeneousHilbert\nfrom ._deprecations import graph_to_N_depwarn\n\nFOCK_MAX = np.iinfo(np.intp).max - 1\n\"\"\"\nMaximum number of particles in the fock space.\nIt is `maxvalue(np.int64)-1` because we use N+1 in several formulas\nand it would overflow.\n\"\"\"\n\n\n@jit(nopython=True)\ndef _sum_constraint(x, n_particles):\n    return np.sum(x, axis=1) == n_particles\n\n\nclass Fock(HomogeneousHilbert):\n    r\"\"\"Hilbert space obtained as tensor product of local fock basis.\"\"\"\n\n    def __init__(\n        self,\n        n_max: Optional[int] = None,\n        N: int = 1,\n        n_particles: Optional[int] = None,\n        graph: Optional[AbstractGraph] = None,\n    ):\n        r\"\"\"\n        Constructs a new ``Boson`` given a maximum occupation number, number of sites\n        and total number of bosons.\n\n        Args:\n          n_max: Maximum occupation for a site (inclusive). If None, the local\n            occupation number is unbounded.\n          N: number of bosonic modes (default = 1)\n          n_particles: Constraint for the number of particles. If None, no constraint\n            is imposed.\n          graph: (Deprecated, pleaese use `N`) A graph, from which the number of nodes\n            is extracted.\n\n        Examples:\n           Simple boson hilbert space.\n\n           >>> from netket.hilbert import Fock\n           >>> hi = Fock(n_max=5, n_particles=11, N=3)\n           >>> print(hi.size)\n           3\n           >>> print(hi.n_states)\n           15\n        \"\"\"\n        N = graph_to_N_depwarn(N=N, graph=graph)\n\n        self._n_max = n_max\n\n        if n_particles is not None:\n            n_particles = int(n_particles)\n            self._n_particles = n_particles\n            assert n_particles > 0\n\n            if self._n_max is None:\n                self._n_max = n_particles\n            else:\n                if self._n_max * N < n_particles:\n                    raise Exception(\n                        \"\"\"The required total number of bosons is not compatible\n                        with the given n_max.\"\"\"\n                    )\n\n            def constraints(x):\n                return _sum_constraint(x, n_particles)\n\n        else:\n            constraints = None\n            self._n_particles = None\n\n        if self._n_max is not None:\n            # assert self._n_max > 0\n            local_states = np.arange(self._n_max + 1)\n        else:\n            self._n_max = FOCK_MAX\n            local_states = None\n\n        super().__init__(local_states, N, constraints)\n\n    @property\n    def n_max(self) -> Optional[int]:\n        r\"\"\"The maximum number of bosons per site, or None\n        if the number is unconstrained.\"\"\"\n        return self._n_max\n\n    @property\n    def n_particles(self) -> Optional[int]:\n        r\"\"\"The total number of particles, or None\n        if the number is unconstrained.\"\"\"\n        return self._n_particles\n\n    def __pow__(self, n) -> \"Fock\":\n        if self.n_particles is None:\n            n_particles = None\n        else:\n            n_particles = n_particles * n\n\n        return Fock(self.n_max, self.size * n, n_particles=n_particles)\n\n    def _mul_sametype_(self, other: \"Fock\") -> \"Fock\":\n        assert type(self) == type(other)\n        if self.n_max == other.n_max:\n            if self._n_particles is None and other._n_particles is None:\n                return Fock(self.n_max, N=self.size + other.size)\n\n        return NotImplemented\n\n    def ptrace(self, sites: Union[int, List]) -> Optional[\"Fock\"]:\n        if isinstance(sites, int):\n            sites = [sites]\n\n        for site in sites:\n            if site < 0 or site >= self.size:\n                raise ValueError(\n                    f\"Site {site} not in this hilbert space of site {self.size}\"\n                )\n\n        if self.n_particles is not None:\n            raise TypeError(\n                \"Cannot take the partial trace with a total particles constraint.\"\n            )\n\n        Nsites = len(sites)\n\n        if self.size - Nsites == 0:\n            return None\n        else:\n            return Fock(self.n_max, N=self.size - Nsites)\n\n    def __repr__(self):\n        n_particles = (\n            \", n_particles={}\".format(self._n_particles)\n            if self._n_particles is not None\n            else \"\"\n        )\n        nmax = self._n_max if self._n_max < FOCK_MAX else \"FOCK_MAX\"\n        return \"Fock(n_max={}{}, N={})\".format(nmax, n_particles, self._size)\n\n    @property\n    def _attrs(self):\n        return (self.size, self._n_max, self._constraint_fn)\n", "path": "netket/hilbert/fock.py"}]}