NetKet 3.9.2__tar.gz → 3.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. {netket-3.9.2 → netket-3.10}/PKG-INFO +20 -14
  2. {netket-3.9.2 → netket-3.10}/README.md +1 -1
  3. {netket-3.9.2 → netket-3.10}/netket/__init__.py +1 -8
  4. netket-3.10/netket/_version.py +16 -0
  5. {netket-3.9.2 → netket-3.10}/netket/driver/abstract_variational_driver.py +19 -11
  6. {netket-3.9.2 → netket-3.10}/netket/driver/steady_state.py +3 -3
  7. {netket-3.9.2 → netket-3.10}/netket/driver/vmc.py +3 -3
  8. {netket-3.9.2 → netket-3.10}/netket/errors.py +23 -0
  9. {netket-3.9.2 → netket-3.10}/netket/exact.py +3 -1
  10. {netket-3.9.2 → netket-3.10}/netket/experimental/__init__.py +4 -0
  11. {netket-3.9.2 → netket-3.10}/netket/experimental/driver/__init__.py +1 -1
  12. {netket-3.9.2 → netket-3.10}/netket/experimental/driver/tdvp.py +1 -2
  13. {netket-3.9.2 → netket-3.10}/netket/experimental/driver/tdvp_common.py +4 -2
  14. {netket-3.9.2 → netket-3.10}/netket/experimental/driver/tdvp_schmitt.py +4 -5
  15. netket-3.10/netket/experimental/driver/vmc_srt.py +248 -0
  16. {netket-3.9.2 → netket-3.10}/netket/experimental/dynamics/_rk_solver_structures.py +2 -2
  17. {netket-3.9.2 → netket-3.10}/netket/experimental/dynamics/_rk_tableau.py +3 -3
  18. {netket-3.9.2 → netket-3.10}/netket/experimental/hilbert/__init__.py +0 -2
  19. netket-3.10/netket/experimental/hilbert/spin_orbital_fermions.py +311 -0
  20. {netket-3.9.2/netket/experimental/hilbert/random → netket-3.10/netket/experimental/logging}/__init__.py +4 -2
  21. {netket-3.9.2 → netket-3.10}/netket/experimental/logging/hdf5_log.py +15 -5
  22. netket-3.10/netket/experimental/models/__init__.py +15 -0
  23. netket-3.9.2/netket/utils/optional_deps.py → netket-3.10/netket/experimental/observable/__init__.py +2 -5
  24. netket-3.10/netket/experimental/observable/renyi2/S2_operator.py +119 -0
  25. {netket-3.9.2/netket/experimental/logging → netket-3.10/netket/experimental/observable/renyi2}/__init__.py +4 -1
  26. netket-3.10/netket/experimental/observable/renyi2/exact.py +46 -0
  27. netket-3.10/netket/experimental/observable/renyi2/expect.py +111 -0
  28. {netket-3.9.2 → netket-3.10}/netket/experimental/operator/__init__.py +1 -0
  29. {netket-3.9.2 → netket-3.10}/netket/experimental/operator/_fermion_operator_2nd.py +147 -49
  30. {netket-3.9.2 → netket-3.10}/netket/experimental/operator/_fermion_operator_2nd_utils.py +124 -29
  31. {netket-3.9.2 → netket-3.10}/netket/experimental/operator/fermion.py +82 -22
  32. netket-3.10/netket/experimental/operator/pyscf.py +380 -0
  33. {netket-3.9.2 → netket-3.10}/netket/experimental/qsr/dataset.py +12 -13
  34. {netket-3.9.2 → netket-3.10}/netket/experimental/qsr/driver.py +3 -3
  35. {netket-3.9.2 → netket-3.10}/netket/experimental/sampler/metropolis_pmap.py +2 -2
  36. {netket-3.9.2 → netket-3.10}/netket/experimental/sampler/metropolis_pt.py +0 -1
  37. {netket-3.9.2 → netket-3.10}/netket/graph/_lattice_edge_logic.py +4 -3
  38. {netket-3.9.2 → netket-3.10}/netket/graph/abstract_graph.py +6 -5
  39. {netket-3.9.2 → netket-3.10}/netket/graph/common_lattices.py +3 -2
  40. {netket-3.9.2 → netket-3.10}/netket/graph/graph.py +4 -3
  41. {netket-3.9.2 → netket-3.10}/netket/graph/lattice.py +5 -4
  42. {netket-3.9.2 → netket-3.10}/netket/graph/space_group.py +2 -1
  43. {netket-3.9.2 → netket-3.10}/netket/hilbert/abstract_hilbert.py +5 -3
  44. {netket-3.9.2 → netket-3.10}/netket/hilbert/continuous_hilbert.py +9 -6
  45. {netket-3.9.2 → netket-3.10}/netket/hilbert/custom_hilbert.py +8 -3
  46. {netket-3.9.2 → netket-3.10}/netket/hilbert/discrete_hilbert.py +33 -6
  47. {netket-3.9.2 → netket-3.10}/netket/hilbert/doubled_hilbert.py +4 -0
  48. {netket-3.9.2 → netket-3.10}/netket/hilbert/fock.py +7 -2
  49. {netket-3.9.2 → netket-3.10}/netket/hilbert/homogeneous.py +24 -16
  50. {netket-3.9.2 → netket-3.10}/netket/hilbert/index/constrained.py +0 -1
  51. {netket-3.9.2 → netket-3.10}/netket/hilbert/index/unconstrained.py +0 -1
  52. {netket-3.9.2 → netket-3.10}/netket/hilbert/particle.py +39 -16
  53. {netket-3.9.2 → netket-3.10}/netket/hilbert/qubit.py +2 -2
  54. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/base.py +2 -2
  55. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/tensor_hilbert.py +1 -2
  56. {netket-3.9.2 → netket-3.10}/netket/hilbert/spin.py +2 -2
  57. {netket-3.9.2 → netket-3.10}/netket/hilbert/tensor_hilbert.py +6 -4
  58. {netket-3.9.2 → netket-3.10}/netket/hilbert/tensor_hilbert_discrete.py +17 -3
  59. {netket-3.9.2 → netket-3.10}/netket/jax/__init__.py +14 -6
  60. {netket-3.9.2 → netket-3.10}/netket/jax/_expect.py +3 -3
  61. {netket-3.9.2 → netket-3.10}/netket/jax/_grad.py +5 -4
  62. {netket-3.9.2 → netket-3.10}/netket/jax/_jacobian/default_mode.py +5 -1
  63. {netket-3.9.2 → netket-3.10}/netket/jax/_jacobian/jacobian_pytree.py +7 -9
  64. {netket-3.9.2 → netket-3.10}/netket/jax/_jacobian/logic.py +29 -10
  65. {netket-3.9.2 → netket-3.10}/netket/jax/_math.py +32 -1
  66. {netket-3.9.2 → netket-3.10}/netket/jax/_scanmap.py +7 -2
  67. netket-3.10/netket/jax/_utils_dtype.py +85 -0
  68. netket-3.10/netket/jax/_utils_random.py +116 -0
  69. netket-3.9.2/netket/jax/utils.py → netket-3.10/netket/jax/_utils_tree.py +4 -147
  70. {netket-3.9.2 → netket-3.10}/netket/jax/_vjp.py +65 -50
  71. {netket-3.9.2 → netket-3.10}/netket/jax/_vjp_chunked.py +1 -4
  72. {netket-3.9.2 → netket-3.10}/netket/logging/__init__.py +2 -3
  73. {netket-3.9.2 → netket-3.10}/netket/logging/json_log.py +7 -0
  74. {netket-3.9.2 → netket-3.10}/netket/logging/runtime_log.py +6 -1
  75. {netket-3.9.2 → netket-3.10}/netket/logging/state_log.py +2 -0
  76. {netket-3.9.2 → netket-3.10}/netket/logging/tensorboard.py +12 -4
  77. {netket-3.9.2 → netket-3.10}/netket/models/autoreg.py +6 -6
  78. {netket-3.9.2 → netket-3.10}/netket/models/deepset.py +10 -8
  79. {netket-3.9.2 → netket-3.10}/netket/models/equivariant.py +16 -17
  80. {netket-3.9.2 → netket-3.10}/netket/models/fast_autoreg.py +6 -6
  81. {netket-3.9.2 → netket-3.10}/netket/models/mlp.py +4 -4
  82. {netket-3.9.2 → netket-3.10}/netket/models/rbm.py +7 -1
  83. netket-3.10/netket/models/slater.py +135 -0
  84. {netket-3.9.2 → netket-3.10}/netket/nn/blocks/deepset.py +5 -5
  85. {netket-3.9.2 → netket-3.10}/netket/nn/blocks/mlp.py +4 -5
  86. {netket-3.9.2 → netket-3.10}/netket/nn/blocks/symmetry_sum.py +35 -16
  87. {netket-3.9.2 → netket-3.10}/netket/nn/deprecation.py +0 -1
  88. {netket-3.9.2 → netket-3.10}/netket/nn/fast_masked_linear.py +3 -3
  89. {netket-3.9.2 → netket-3.10}/netket/nn/masked_linear.py +5 -5
  90. {netket-3.9.2 → netket-3.10}/netket/nn/symmetric_linear.py +28 -19
  91. {netket-3.9.2 → netket-3.10}/netket/nn/utils.py +15 -20
  92. netket-3.10/netket/operator/_abstract_observable.py +51 -0
  93. {netket-3.9.2 → netket-3.10}/netket/operator/_abstract_operator.py +24 -11
  94. {netket-3.9.2 → netket-3.10}/netket/operator/_abstract_super_operator.py +2 -0
  95. {netket-3.9.2 → netket-3.10}/netket/operator/_bose_hubbard.py +1 -2
  96. {netket-3.9.2 → netket-3.10}/netket/operator/_continuous_operator.py +4 -2
  97. {netket-3.9.2 → netket-3.10}/netket/operator/_discrete_operator.py +7 -5
  98. {netket-3.9.2 → netket-3.10}/netket/operator/_discrete_operator_jax.py +4 -3
  99. {netket-3.9.2 → netket-3.10}/netket/operator/_graph_operator.py +3 -3
  100. {netket-3.9.2 → netket-3.10}/netket/operator/_heisenberg.py +3 -2
  101. {netket-3.9.2 → netket-3.10}/netket/operator/_ising/base.py +4 -4
  102. {netket-3.9.2 → netket-3.10}/netket/operator/_ising/jax.py +11 -2
  103. {netket-3.9.2 → netket-3.10}/netket/operator/_ising/numba.py +4 -1
  104. {netket-3.9.2 → netket-3.10}/netket/operator/_kinetic.py +4 -4
  105. {netket-3.9.2 → netket-3.10}/netket/operator/_lazy.py +0 -1
  106. {netket-3.9.2 → netket-3.10}/netket/operator/_local_liouvillian.py +8 -6
  107. {netket-3.9.2 → netket-3.10}/netket/operator/_local_operator/base.py +14 -10
  108. netket-3.10/netket/operator/_local_operator/compile_helpers.py +303 -0
  109. {netket-3.9.2 → netket-3.10}/netket/operator/_local_operator/convert.py +7 -1
  110. {netket-3.9.2 → netket-3.10}/netket/operator/_local_operator/helpers.py +23 -12
  111. {netket-3.9.2 → netket-3.10}/netket/operator/_pauli_strings/base.py +155 -78
  112. {netket-3.9.2 → netket-3.10}/netket/operator/_pauli_strings/jax.py +24 -7
  113. {netket-3.9.2 → netket-3.10}/netket/operator/_pauli_strings/numba.py +22 -6
  114. {netket-3.9.2 → netket-3.10}/netket/operator/_potential.py +3 -2
  115. {netket-3.9.2 → netket-3.10}/netket/operator/_sumoperators.py +8 -7
  116. {netket-3.9.2 → netket-3.10}/netket/operator/boson.py +24 -18
  117. {netket-3.9.2 → netket-3.10}/netket/operator/spin.py +63 -28
  118. {netket-3.9.2 → netket-3.10}/netket/optimizer/linear_operator.py +2 -2
  119. {netket-3.9.2 → netket-3.10}/netket/optimizer/preconditioner.py +0 -1
  120. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/common.py +1 -1
  121. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/qgt_jacobian_dense.py +3 -2
  122. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/qgt_jacobian_pytree.py +3 -3
  123. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/qgt_onthefly.py +1 -2
  124. {netket-3.9.2 → netket-3.10}/netket/optimizer/solver/solvers.py +10 -10
  125. {netket-3.9.2 → netket-3.10}/netket/optimizer/sr.py +14 -20
  126. {netket-3.9.2 → netket-3.10}/netket/sampler/autoreg.py +2 -22
  127. {netket-3.9.2 → netket-3.10}/netket/sampler/base.py +6 -7
  128. {netket-3.9.2 → netket-3.10}/netket/sampler/exact.py +6 -4
  129. {netket-3.9.2 → netket-3.10}/netket/sampler/metropolis.py +10 -11
  130. {netket-3.9.2 → netket-3.10}/netket/sampler/metropolis_numpy.py +2 -3
  131. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/base.py +2 -3
  132. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/exchange.py +2 -2
  133. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/hamiltonian.py +0 -1
  134. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/multiple.py +3 -3
  135. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/tensor.py +3 -3
  136. {netket-3.9.2 → netket-3.10}/netket/stats/_autocorr.py +3 -0
  137. {netket-3.9.2 → netket-3.10}/netket/stats/mc_stats.py +2 -0
  138. {netket-3.9.2 → netket-3.10}/netket/utils/__init__.py +2 -2
  139. {netket-3.9.2 → netket-3.10}/netket/utils/_dependencies_check.py +18 -8
  140. {netket-3.9.2 → netket-3.10}/netket/utils/config_flags.py +49 -2
  141. {netket-3.9.2 → netket-3.10}/netket/utils/deprecation.py +2 -3
  142. netket-3.10/netket/utils/dispatch.py +46 -0
  143. {netket-3.9.2 → netket-3.10}/netket/utils/group/_group.py +4 -5
  144. {netket-3.9.2 → netket-3.10}/netket/utils/group/_point_group.py +4 -5
  145. {netket-3.9.2 → netket-3.10}/netket/utils/group/_semigroup.py +1 -2
  146. {netket-3.9.2 → netket-3.10}/netket/utils/history.py +6 -6
  147. {netket-3.9.2 → netket-3.10}/netket/utils/holomorphic.py +1 -1
  148. {netket-3.9.2 → netket-3.10}/netket/utils/model_frameworks/base.py +1 -3
  149. {netket-3.9.2 → netket-3.10}/netket/utils/model_frameworks/flax.py +0 -1
  150. {netket-3.9.2 → netket-3.10}/netket/utils/model_frameworks/haiku.py +2 -4
  151. {netket-3.9.2 → netket-3.10}/netket/utils/model_frameworks/jax.py +2 -5
  152. {netket-3.9.2 → netket-3.10}/netket/utils/mpi/__init__.py +5 -0
  153. {netket-3.9.2 → netket-3.10}/netket/utils/mpi/primitives.py +57 -3
  154. netket-3.10/netket/utils/optional_deps.py +39 -0
  155. netket-3.10/netket/utils/plum/__init__.py +61 -0
  156. netket-3.10/netket/utils/plum/_version.py +17 -0
  157. netket-3.10/netket/utils/plum/alias.py +166 -0
  158. netket-3.10/netket/utils/plum/autoreload.py +77 -0
  159. netket-3.10/netket/utils/plum/dispatcher.py +128 -0
  160. netket-3.10/netket/utils/plum/function.py +487 -0
  161. netket-3.10/netket/utils/plum/method.py +232 -0
  162. netket-3.10/netket/utils/plum/overload.py +9 -0
  163. netket-3.10/netket/utils/plum/parametric.py +421 -0
  164. netket-3.10/netket/utils/plum/promotion.py +169 -0
  165. netket-3.10/netket/utils/plum/py.typed +0 -0
  166. netket-3.10/netket/utils/plum/repr.py +179 -0
  167. netket-3.10/netket/utils/plum/resolver.py +307 -0
  168. netket-3.10/netket/utils/plum/signature.py +424 -0
  169. netket-3.10/netket/utils/plum/type.py +296 -0
  170. netket-3.10/netket/utils/plum/util.py +170 -0
  171. {netket-3.9.2 → netket-3.10}/netket/utils/struct/dataclass.py +3 -3
  172. {netket-3.9.2 → netket-3.10}/netket/utils/types.py +2 -1
  173. {netket-3.9.2 → netket-3.10}/netket/utils/version_check.py +2 -2
  174. {netket-3.9.2 → netket-3.10}/netket/vqs/base.py +69 -79
  175. {netket-3.9.2 → netket-3.10}/netket/vqs/full_summ/expect.py +37 -35
  176. {netket-3.9.2 → netket-3.10}/netket/vqs/full_summ/state.py +20 -10
  177. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/common.py +21 -0
  178. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/kernels.py +2 -2
  179. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_mixed_state/expect_chunked.py +7 -0
  180. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_mixed_state/state.py +6 -5
  181. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_state/expect.py +3 -3
  182. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_state/expect_chunked.py +10 -8
  183. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_state/expect_forces.py +5 -5
  184. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_state/expect_forces_chunked.py +12 -14
  185. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_state/expect_grad.py +50 -52
  186. netket-3.10/netket/vqs/mc/mc_state/expect_grad_chunked.py +74 -0
  187. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_state/state.py +83 -53
  188. {netket-3.9.2 → netket-3.10}/pyproject.toml +36 -16
  189. netket-3.9.2/netket/_version.py +0 -4
  190. netket-3.9.2/netket/experimental/hilbert/random/spin_orbital_fermions.py +0 -31
  191. netket-3.9.2/netket/experimental/hilbert/spin_orbital_fermions.py +0 -175
  192. netket-3.9.2/netket/operator/_local_operator/compile_helpers.py +0 -194
  193. netket-3.9.2/netket/utils/dispatch.py +0 -22
  194. netket-3.9.2/netket/vqs/mc/mc_mixed_state/expect_grad_chunked.py +0 -45
  195. netket-3.9.2/netket/vqs/mc/mc_state/expect_grad_chunked.py +0 -89
  196. {netket-3.9.2 → netket-3.10}/.gitignore +0 -0
  197. {netket-3.9.2 → netket-3.10}/LICENSE +0 -0
  198. {netket-3.9.2 → netket-3.10}/netket/callbacks/__init__.py +0 -0
  199. {netket-3.9.2 → netket-3.10}/netket/callbacks/convergence_stopping.py +0 -0
  200. {netket-3.9.2 → netket-3.10}/netket/callbacks/earlystopping.py +0 -0
  201. {netket-3.9.2 → netket-3.10}/netket/callbacks/invalidlossstopping.py +0 -0
  202. {netket-3.9.2 → netket-3.10}/netket/callbacks/timeout.py +0 -0
  203. {netket-3.9.2 → netket-3.10}/netket/driver/__init__.py +0 -0
  204. {netket-3.9.2 → netket-3.10}/netket/driver/vmc_common.py +0 -0
  205. {netket-3.9.2 → netket-3.10}/netket/experimental/dynamics/__init__.py +0 -0
  206. {netket-3.9.2 → netket-3.10}/netket/experimental/dynamics/_rk_solver.py +0 -0
  207. {netket-3.9.2 → netket-3.10}/netket/experimental/qsr/__init__.py +0 -0
  208. {netket-3.9.2 → netket-3.10}/netket/experimental/qsr/logic_helpers.py +0 -0
  209. {netket-3.9.2 → netket-3.10}/netket/experimental/sampler/__init__.py +0 -0
  210. {netket-3.9.2 → netket-3.10}/netket/experimental/vqs/__init__.py +0 -0
  211. {netket-3.9.2 → netket-3.10}/netket/experimental/vqs/io.py +0 -0
  212. {netket-3.9.2 → netket-3.10}/netket/graph/__init__.py +0 -0
  213. {netket-3.9.2 → netket-3.10}/netket/hilbert/__init__.py +0 -0
  214. {netket-3.9.2 → netket-3.10}/netket/hilbert/index/__init__.py +0 -0
  215. {netket-3.9.2 → netket-3.10}/netket/hilbert/index/base.py +0 -0
  216. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/__init__.py +0 -0
  217. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/custom.py +0 -0
  218. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/doubled.py +0 -0
  219. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/fock.py +0 -0
  220. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/particle.py +0 -0
  221. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/qubit.py +0 -0
  222. {netket-3.9.2 → netket-3.10}/netket/hilbert/random/spin.py +0 -0
  223. {netket-3.9.2 → netket-3.10}/netket/jax/_chunk_utils.py +0 -0
  224. {netket-3.9.2 → netket-3.10}/netket/jax/_jacobian/__init__.py +0 -0
  225. {netket-3.9.2 → netket-3.10}/netket/jax/_jacobian/jacobian_dense.py +0 -0
  226. {netket-3.9.2 → netket-3.10}/netket/jax/_vmap_chunked.py +0 -0
  227. {netket-3.9.2 → netket-3.10}/netket/models/README.md +0 -0
  228. {netket-3.9.2 → netket-3.10}/netket/models/__init__.py +0 -0
  229. {netket-3.9.2 → netket-3.10}/netket/models/full_space.py +0 -0
  230. {netket-3.9.2 → netket-3.10}/netket/models/gaussian.py +0 -0
  231. {netket-3.9.2 → netket-3.10}/netket/models/jastrow.py +0 -0
  232. {netket-3.9.2 → netket-3.10}/netket/models/mps.py +0 -0
  233. {netket-3.9.2 → netket-3.10}/netket/models/ndm.py +0 -0
  234. {netket-3.9.2 → netket-3.10}/netket/models/utils.py +0 -0
  235. {netket-3.9.2 → netket-3.10}/netket/nn/__init__.py +0 -0
  236. {netket-3.9.2 → netket-3.10}/netket/nn/activation.py +0 -0
  237. {netket-3.9.2 → netket-3.10}/netket/nn/blocks/__init__.py +0 -0
  238. {netket-3.9.2 → netket-3.10}/netket/nn/initializers.py +0 -0
  239. {netket-3.9.2 → netket-3.10}/netket/operator/__init__.py +0 -0
  240. {netket-3.9.2 → netket-3.10}/netket/operator/_hamiltonian.py +0 -0
  241. {netket-3.9.2 → netket-3.10}/netket/operator/_ising/__init__.py +0 -0
  242. {netket-3.9.2 → netket-3.10}/netket/operator/_local_operator/__init__.py +0 -0
  243. {netket-3.9.2 → netket-3.10}/netket/operator/_pauli_strings/__init__.py +0 -0
  244. {netket-3.9.2 → netket-3.10}/netket/optimizer/__init__.py +0 -0
  245. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/__init__.py +0 -0
  246. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/default.py +0 -0
  247. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/qgt_jacobian_common.py +0 -0
  248. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/qgt_jacobian_pytree_logic.py +0 -0
  249. {netket-3.9.2 → netket-3.10}/netket/optimizer/qgt/qgt_onthefly_logic.py +0 -0
  250. {netket-3.9.2 → netket-3.10}/netket/optimizer/solver/__init__.py +0 -0
  251. {netket-3.9.2 → netket-3.10}/netket/sampler/__init__.py +0 -0
  252. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/__init__.py +0 -0
  253. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/continuous_gaussian.py +0 -0
  254. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/custom_numpy.py +0 -0
  255. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/fixed.py +0 -0
  256. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/hamiltonian_numpy.py +0 -0
  257. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/langevin.py +0 -0
  258. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/local.py +0 -0
  259. {netket-3.9.2 → netket-3.10}/netket/sampler/rules/local_numpy.py +0 -0
  260. {netket-3.9.2 → netket-3.10}/netket/stats/__init__.py +0 -0
  261. {netket-3.9.2 → netket-3.10}/netket/stats/mc_stats_old.py +0 -0
  262. {netket-3.9.2 → netket-3.10}/netket/stats/mpi_stats.py +0 -0
  263. {netket-3.9.2 → netket-3.10}/netket/tools/__init__.py +0 -0
  264. {netket-3.9.2 → netket-3.10}/netket/tools/_common.py +0 -0
  265. {netket-3.9.2 → netket-3.10}/netket/tools/_cpu_info.py +0 -0
  266. {netket-3.9.2 → netket-3.10}/netket/tools/_mpi_info.py +0 -0
  267. {netket-3.9.2 → netket-3.10}/netket/tools/check_mpi.py +0 -0
  268. {netket-3.9.2 → netket-3.10}/netket/tools/info.py +0 -0
  269. {netket-3.9.2 → netket-3.10}/netket/utils/array.py +0 -0
  270. {netket-3.9.2 → netket-3.10}/netket/utils/float.py +0 -0
  271. {netket-3.9.2 → netket-3.10}/netket/utils/group/__init__.py +0 -0
  272. {netket-3.9.2 → netket-3.10}/netket/utils/group/_permutation_group.py +0 -0
  273. {netket-3.9.2 → netket-3.10}/netket/utils/group/axial.py +0 -0
  274. {netket-3.9.2 → netket-3.10}/netket/utils/group/cubic.py +0 -0
  275. {netket-3.9.2 → netket-3.10}/netket/utils/group/icosa.py +0 -0
  276. {netket-3.9.2 → netket-3.10}/netket/utils/group/planar.py +0 -0
  277. {netket-3.9.2 → netket-3.10}/netket/utils/jax.py +0 -0
  278. {netket-3.9.2 → netket-3.10}/netket/utils/model_frameworks/__init__.py +0 -0
  279. {netket-3.9.2 → netket-3.10}/netket/utils/moduletools.py +0 -0
  280. {netket-3.9.2 → netket-3.10}/netket/utils/mpi/mpi.py +0 -0
  281. {netket-3.9.2 → netket-3.10}/netket/utils/numbers.py +0 -0
  282. {netket-3.9.2 → netket-3.10}/netket/utils/partial.py +0 -0
  283. {netket-3.9.2 → netket-3.10}/netket/utils/seed.py +0 -0
  284. {netket-3.9.2 → netket-3.10}/netket/utils/static_number.py +0 -0
  285. {netket-3.9.2 → netket-3.10}/netket/utils/struct/__init__.py +0 -0
  286. {netket-3.9.2 → netket-3.10}/netket/utils/struct/utils.py +0 -0
  287. {netket-3.9.2 → netket-3.10}/netket/utils/summation.py +0 -0
  288. {netket-3.9.2 → netket-3.10}/netket/vqs/__init__.py +0 -0
  289. {netket-3.9.2 → netket-3.10}/netket/vqs/deprecated.py +0 -0
  290. {netket-3.9.2 → netket-3.10}/netket/vqs/experimental.py +0 -0
  291. {netket-3.9.2 → netket-3.10}/netket/vqs/full_summ/__init__.py +0 -0
  292. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/__init__.py +0 -0
  293. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_mixed_state/__init__.py +0 -0
  294. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_mixed_state/expect.py +0 -0
  295. {netket-3.9.2 → netket-3.10}/netket/vqs/mc/mc_state/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: NetKet
3
- Version: 3.9.2
3
+ Version: 3.10
4
4
  Summary: Netket : Machine Learning toolbox for many-body quantum systems.
5
5
  Project-URL: homepage, https://www.netket.org
6
6
  Project-URL: documentation, https://netket.readthedocs.io/en/latest/#
@@ -17,23 +17,26 @@ Classifier: Operating System :: POSIX :: Linux
17
17
  Classifier: Operating System :: Unix
18
18
  Classifier: Programming Language :: Python :: 3
19
19
  Classifier: Topic :: Scientific/Engineering :: Physics
20
- Requires-Python: >=3.8
21
- Requires-Dist: flax<0.8,>=0.6.5
22
- Requires-Dist: igraph<0.11.0,>=0.10.0
20
+ Requires-Python: >=3.9
21
+ Requires-Dist: beartype>=0.16.2
22
+ Requires-Dist: flax<0.8,>=0.7.1
23
+ Requires-Dist: igraph<0.12.0,>=0.10.0
23
24
  Requires-Dist: jax<0.5,>=0.4.3
24
25
  Requires-Dist: jaxlib<0.5,>=0.4.3
25
26
  Requires-Dist: numba4jax<0.1,>=0.0.10.post1
26
- Requires-Dist: numba<0.58,>=0.52
27
+ Requires-Dist: numba<0.59,>=0.52
27
28
  Requires-Dist: numpy~=1.20
28
29
  Requires-Dist: optax<0.2,>=0.1.3
29
30
  Requires-Dist: orjson<4,>=3.4
30
- Requires-Dist: plum-dispatch<3,>=1.5.1
31
+ Requires-Dist: rich>=10.0
31
32
  Requires-Dist: scipy<2,>=1.5.3
32
33
  Requires-Dist: tqdm<5,>=4.60
34
+ Requires-Dist: typing-extensions; python_version <= '3.10'
33
35
  Provides-Extra: dev
34
- Requires-Dist: black==22.10.0; extra == 'dev'
36
+ Requires-Dist: black==23.9.1; extra == 'dev'
35
37
  Requires-Dist: build; extra == 'dev'
36
38
  Requires-Dist: coverage>=5; extra == 'dev'
39
+ Requires-Dist: ipython; extra == 'dev'
37
40
  Requires-Dist: matplotlib>=3; extra == 'dev'
38
41
  Requires-Dist: networkx<4,>=2.4; extra == 'dev'
39
42
  Requires-Dist: pre-commit>=2.7; extra == 'dev'
@@ -41,25 +44,28 @@ Requires-Dist: pytest-cov>=2.10.1; extra == 'dev'
41
44
  Requires-Dist: pytest-json-report>=1.3; extra == 'dev'
42
45
  Requires-Dist: pytest-xdist[psutil]>=2; extra == 'dev'
43
46
  Requires-Dist: pytest>=6; extra == 'dev'
44
- Requires-Dist: ruff==0.0.278; extra == 'dev'
47
+ Requires-Dist: ruff==0.1.0; extra == 'dev'
45
48
  Requires-Dist: wheel; extra == 'dev'
46
49
  Provides-Extra: docs
47
- Requires-Dist: myst-nb~=0.17.1; extra == 'docs'
50
+ Requires-Dist: myst-nb~=1.0.0rc0; extra == 'docs'
48
51
  Requires-Dist: myst-parser<2.1.0,>=0.18.1; extra == 'docs'
49
- Requires-Dist: nbsphinx~=0.9.1; extra == 'docs'
50
52
  Requires-Dist: sphinx-autodoc-typehints~=1.22; extra == 'docs'
51
53
  Requires-Dist: sphinx-book-theme~=1.0.1; extra == 'docs'
52
- Requires-Dist: sphinx<7.1,>=5.3; extra == 'docs'
54
+ Requires-Dist: sphinx-design>=0.4.0; extra == 'docs'
55
+ Requires-Dist: sphinx<7.3,>=6.2; extra == 'docs'
53
56
  Requires-Dist: sphinxcontrib-fulltoc~=1.2.0; extra == 'docs'
54
57
  Requires-Dist: sphinxcontrib-jsmath~=1.0.1; extra == 'docs'
55
- Requires-Dist: sphinxcontrib-napoleon==0.7; extra == 'docs'
56
58
  Provides-Extra: extra
57
59
  Requires-Dist: h5py>=3.7.0; extra == 'extra'
58
60
  Requires-Dist: openfermion>=1.0.0; extra == 'extra'
61
+ Requires-Dist: qutip>=4; extra == 'extra'
59
62
  Requires-Dist: tensorboardx>=2.0.0; extra == 'extra'
60
63
  Provides-Extra: mpi
61
- Requires-Dist: mpi4jax<0.4,>=0.3.9; extra == 'mpi'
64
+ Requires-Dist: mpi4jax<0.5,>=0.3.9; extra == 'mpi'
62
65
  Requires-Dist: mpi4py<4,>=3.0.1; extra == 'mpi'
66
+ Provides-Extra: pyscf
67
+ Requires-Dist: pyscf>=2.0; extra == 'pyscf'
68
+ Requires-Dist: sparse>=0.12.0; extra == 'pyscf'
63
69
  Description-Content-Type: text/markdown
64
70
 
65
71
  <div align="center">
@@ -158,7 +164,7 @@ If you want MPI support, please follow the discussion in [mpi4jax](https://githu
158
164
 
159
165
  ## Getting Started
160
166
 
161
- To get started with NetKet, we recommend you give a look at our [tutorials page](https://netket.readthedocs.io/en/latest/tutorials/gs-ising.htmls), by running them on your computer or on [Google Colaboratory](https://colab.research.google.com).
167
+ To get started with NetKet, we recommend you give a look at our [tutorials page](https://netket.readthedocs.io/en/latest/tutorials/gs-ising.html), by running them on your computer or on [Google Colaboratory](https://colab.research.google.com).
162
168
  There are also many example scripts that you can download, run and edit that showcase some use-cases of NetKet, although they are not commented.
163
169
 
164
170
  If you want to get in touch with us, feel free to open an issue or a discussion here on GitHub, or to join the MLQuantum slack group where several people involved with NetKet hang out. To join the slack channel just accept [this invitation](https://join.slack.com/t/mlquantum/shared_invite/zt-19wibmfdv-LLRI6i43wrLev6oQX0OfOw)
@@ -94,7 +94,7 @@ If you want MPI support, please follow the discussion in [mpi4jax](https://githu
94
94
 
95
95
  ## Getting Started
96
96
 
97
- To get started with NetKet, we recommend you give a look at our [tutorials page](https://netket.readthedocs.io/en/latest/tutorials/gs-ising.htmls), by running them on your computer or on [Google Colaboratory](https://colab.research.google.com).
97
+ To get started with NetKet, we recommend you give a look at our [tutorials page](https://netket.readthedocs.io/en/latest/tutorials/gs-ising.html), by running them on your computer or on [Google Colaboratory](https://colab.research.google.com).
98
98
  There are also many example scripts that you can download, run and edit that showcase some use-cases of NetKet, although they are not commented.
99
99
 
100
100
  If you want to get in touch with us, feel free to open an issue or a discussion here on GitHub, or to join the MLQuantum slack group where several people involved with NetKet hang out. To join the slack channel just accept [this invitation](https://join.slack.com/t/mlquantum/shared_invite/zt-19wibmfdv-LLRI6i43wrLev6oQX0OfOw)
@@ -12,18 +12,11 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # enable x64 on jax
16
- # must be done at startup.
17
- from jax.config import config
18
-
19
- config.update("jax_enable_x64", True)
20
- del config
21
-
22
15
  from ._version import version as __version__ # noqa: F401
23
16
 
24
- from . import utils
25
17
  from .utils import config
26
18
 
19
+ from . import utils
27
20
  from . import errors
28
21
 
29
22
  __all__ = [
@@ -0,0 +1,16 @@
1
+ # file generated by setuptools_scm
2
+ # don't change, don't track in version control
3
+ TYPE_CHECKING = False
4
+ if TYPE_CHECKING:
5
+ from typing import Tuple, Union
6
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
7
+ else:
8
+ VERSION_TUPLE = object
9
+
10
+ version: str
11
+ __version__: str
12
+ __version_tuple__: VERSION_TUPLE
13
+ version_tuple: VERSION_TUPLE
14
+
15
+ __version__ = version = '3.10'
16
+ __version_tuple__ = version_tuple = (3, 10)
@@ -22,6 +22,7 @@ import jax
22
22
  from jax.tree_util import tree_map
23
23
 
24
24
  from netket.logging import JsonLog
25
+ from netket.operator import AbstractOperator
25
26
  from netket.utils import mpi
26
27
 
27
28
 
@@ -108,19 +109,18 @@ class AbstractVariationalDriver(abc.ABC):
108
109
  def reset(self):
109
110
  """
110
111
  Resets the driver.
111
- Concrete drivers should also call super().reset() to ensure that the step
112
- count is set to 0.
112
+
113
+ Subclasses should make sure to call :code:`super().reset()` to ensure
114
+ that the step count is set to 0.
113
115
  """
114
116
  self.state.reset()
115
117
  self._step_count = 0
116
- pass
117
118
 
118
119
  @abc.abstractmethod
119
120
  def info(self, depth=0):
120
121
  """
121
122
  Returns an info string used to print information to screen about this driver.
122
123
  """
123
- pass # pragma: no cover
124
124
 
125
125
  @property
126
126
  def state(self):
@@ -156,9 +156,10 @@ class AbstractVariationalDriver(abc.ABC):
156
156
  after every `step_size` steps.
157
157
 
158
158
  Args:
159
- n_iter: The total number of steps to perform.
160
- step_size: The number of internal steps the simulation
161
- is advanced every turn.
159
+ n_steps: The total number of steps to perform (this is
160
+ equivalent to the length of the iterator)
161
+ step: The number of internal steps the simulation
162
+ is advanced between yielding from the iterator
162
163
 
163
164
  Yields:
164
165
  int: The current step.
@@ -176,7 +177,9 @@ class AbstractVariationalDriver(abc.ABC):
176
177
  """
177
178
  Performs `steps` optimization steps.
178
179
 
179
- steps: (Default=1) number of steps
180
+ Args:
181
+ steps: (Default=1) number of steps.
182
+
180
183
  """
181
184
  for _ in self.iter(steps):
182
185
  pass
@@ -254,7 +257,6 @@ class AbstractVariationalDriver(abc.ABC):
254
257
  first_step = True
255
258
 
256
259
  for step in self.iter(n_iter, step_size):
257
-
258
260
  log_data = self.estimate(obs)
259
261
  self._log_additional_data(log_data, step)
260
262
 
@@ -306,7 +308,14 @@ class AbstractVariationalDriver(abc.ABC):
306
308
  A pytree of the same structure as the input, containing MCMC statistics
307
309
  for the corresponding operators as leaves.
308
310
  """
309
- return tree_map(self._estimate_stats, observables)
311
+
312
+ # Do not unpack operators, even if they are pytrees!
313
+ # this is necessary to support jax operators.
314
+ return tree_map(
315
+ self._estimate_stats,
316
+ observables,
317
+ is_leaf=lambda x: isinstance(x, AbstractOperator),
318
+ )
310
319
 
311
320
  def update_parameters(self, dp):
312
321
  """
@@ -333,7 +342,6 @@ class AbstractVariationalDriver(abc.ABC):
333
342
  Returns:
334
343
  Nothing. The log dictionary should be modified in place.
335
344
  """
336
- pass # pragma: no cover
337
345
 
338
346
 
339
347
  @partial(jax.jit, static_argnums=0)
@@ -119,8 +119,8 @@ class SteadyState(AbstractVariationalDriver):
119
119
  argument is the step, used to change some parameters along the
120
120
  optimisation.
121
121
 
122
- Often, this is taken to be :func:`nk.optimizer.SR`. If it is set to
123
- `None`, then the identity is used.
122
+ Often, this is taken to be :func:`~netket.optimizer.SR`. If it is
123
+ set to `None`, then the identity is used.
124
124
  """
125
125
  return self._preconditioner
126
126
 
@@ -158,4 +158,4 @@ class SteadyState(AbstractVariationalDriver):
158
158
  ("SR solver ", self.sr),
159
159
  ]
160
160
  ]
161
- return "\n{}".format(" " * 3 * (depth + 1)).join([str(self)] + lines)
161
+ return "\n{}".format(" " * 3 * (depth + 1)).join([str(self), *lines])
@@ -103,8 +103,8 @@ class VMC(AbstractVariationalDriver):
103
103
  argument is the step, used to change some parameters along the
104
104
  optimisation.
105
105
 
106
- Often, this is taken to be :func:`nk.optimizer.SR`. If it is set to
107
- `None`, then the identity is used.
106
+ Often, this is taken to be :func:`~netket.optimizer.SR`. If it is
107
+ set to `None`, then the identity is used.
108
108
  """
109
109
  return self._preconditioner
110
110
 
@@ -169,4 +169,4 @@ class VMC(AbstractVariationalDriver):
169
169
  ("State ", self.state),
170
170
  ]
171
171
  ]
172
- return "\n{}".format(" " * 3 * (depth + 1)).join([str(self)] + lines)
172
+ return "\n{}".format(" " * 3 * (depth + 1)).join([str(self), *lines])
@@ -599,6 +599,29 @@ class RealQGTComplexDomainError(Exception):
599
599
  )
600
600
 
601
601
 
602
+ class UnoptimalSRtWarning(NetketWarning):
603
+ """
604
+ SRt should be used when the number of parameters exceed the number of samples.
605
+ If this is not the case, employing `netket.driver.VMC` with the `nk.optimizer.SR` preconditioner
606
+ is a more efficient option while maintaining the same parameter dynamics.
607
+
608
+ .. note::
609
+ a detailed discussion can be found in the documentation of
610
+ :func:`netket.experimental.driver.VMC_SRt`).
611
+
612
+ """
613
+
614
+ def __init__(self, n_parameters, n_samples):
615
+ super().__init__(
616
+ f"""
617
+ You are in the case n_samples > num_params ({n_samples} > {n_parameters}),
618
+ for which the `VMC_SRt` is not optimal. Consider using `netket.driver.VMC`
619
+ with the preconditioner `nk.optimizer.SR` to achieve the same parameter dynamics,
620
+ but with improved speed.
621
+ """
622
+ )
623
+
624
+
602
625
  #################################################
603
626
  # Functions to throw errors #
604
627
  #################################################
@@ -12,6 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from typing import Optional
16
+
15
17
  import numpy as _np
16
18
  from scipy.sparse.linalg import bicgstab as _bicgstab
17
19
  from scipy.sparse.linalg import LinearOperator as _LinearOperator
@@ -26,7 +28,7 @@ def lanczos_ed(
26
28
  k: int = 1,
27
29
  compute_eigenvectors: bool = False,
28
30
  matrix_free: bool = False,
29
- scipy_args: dict = None,
31
+ scipy_args: Optional[dict] = None,
30
32
  ):
31
33
  r"""Computes `first_n` smallest eigenvalues and, optionally, eigenvectors
32
34
  of a Hermitian operator using :meth:`scipy.sparse.linalg.eigsh`.
@@ -18,9 +18,11 @@ __all__ = [
18
18
  "sampler",
19
19
  "vqs",
20
20
  "TDVP",
21
+ "models",
21
22
  "hilbert",
22
23
  "operator",
23
24
  "logging",
25
+ "observable",
24
26
  ]
25
27
 
26
28
  from . import hilbert
@@ -28,9 +30,11 @@ from . import operator
28
30
  from . import driver
29
31
  from . import dynamics
30
32
  from . import sampler
33
+ from . import models
31
34
  from . import vqs
32
35
  from . import logging
33
36
  from . import qsr
37
+ from . import observable
34
38
 
35
39
  from .driver import TDVP
36
40
  from .qsr import QSR
@@ -14,7 +14,7 @@
14
14
 
15
15
  from .tdvp import TDVP
16
16
  from .tdvp_schmitt import TDVPSchmitt
17
-
17
+ from .vmc_srt import VMC_SRt
18
18
  from netket.utils import _hide_submodules
19
19
 
20
20
  _hide_submodules(__name__)
@@ -135,7 +135,7 @@ class TDVP(TDVPBaseDriver):
135
135
  ("state ", self.state),
136
136
  ]
137
137
  ]
138
- return "\n{}".format(" " * 3 * (depth + 1)).join([str(self)] + lines)
138
+ return "\n{}".format(" " * 3 * (depth + 1)).join([str(self), *lines])
139
139
 
140
140
 
141
141
  @odefun.dispatch
@@ -179,7 +179,6 @@ def odefun_tdvp( # noqa: F811
179
179
 
180
180
  @partial(jax.jit, static_argnums=(3, 4))
181
181
  def _map_parameters(forces, parameters, loss_grad_factor, propagation_type, state_T):
182
-
183
182
  forces = jax.tree_map(
184
183
  lambda x, target: loss_grad_factor * x,
185
184
  forces,
@@ -12,7 +12,8 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import Callable, Optional, Sequence, Union
15
+ from typing import Callable, Optional, Union
16
+ from collections.abc import Sequence
16
17
  import warnings
17
18
 
18
19
  import jax
@@ -205,6 +206,7 @@ class TDVPBaseDriver(AbstractVariationalDriver):
205
206
  at which this method will stop and yield. By default, a stop is performed
206
207
  after each time step (at potentially varying step size if an adaptive
207
208
  integrator is used).
209
+
208
210
  Yields:
209
211
  The current step count.
210
212
  """
@@ -214,7 +216,7 @@ class TDVPBaseDriver(AbstractVariationalDriver):
214
216
  self,
215
217
  T: float,
216
218
  tstops: Optional[Sequence[float]] = None,
217
- callback: Callable = None,
219
+ callback: Optional[Callable] = None,
218
220
  ):
219
221
  """
220
222
  Implementation of :code:`iter`. This method accepts and additional `callback` object, which
@@ -12,7 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- from typing import Callable, Union
15
+ from typing import Callable, Union, Optional
16
16
 
17
17
  from functools import partial
18
18
 
@@ -108,9 +108,9 @@ class TDVPSchmitt(TDVPBaseDriver):
108
108
  *,
109
109
  t0: float = 0.0,
110
110
  propagation_type="real",
111
- holomorphic: bool = None,
111
+ holomorphic: Optional[bool] = None,
112
112
  diag_shift: float = 0.0,
113
- diag_scale: float = None,
113
+ diag_scale: Optional[float] = None,
114
114
  error_norm: Union[str, Callable] = "qgt",
115
115
  rcond: float = 1e-14,
116
116
  rcond_smooth: float = 1e-8,
@@ -192,7 +192,7 @@ class TDVPSchmitt(TDVPBaseDriver):
192
192
  ("state ", self.state),
193
193
  ]
194
194
  ]
195
- return "\n{}".format(" " * 3 * (depth + 1)).join([str(self)] + lines)
195
+ return "\n{}".format(" " * 3 * (depth + 1)).join([str(self), *lines])
196
196
 
197
197
 
198
198
  # Copyright notice:
@@ -295,7 +295,6 @@ def odefun_schmitt(state: MCState, self: TDVPSchmitt, t, w, *, stage=0): # noqa
295
295
 
296
296
  @partial(jax.jit, static_argnums=(3, 4))
297
297
  def _map_parameters(forces, parameters, loss_grad_factor, propagation_type, state_T):
298
-
299
298
  forces = jax.tree_map(
300
299
  lambda x, target: loss_grad_factor * x,
301
300
  forces,
@@ -0,0 +1,248 @@
1
+ from functools import partial
2
+ from typing import Callable, Optional
3
+
4
+ import jax
5
+ import jax.numpy as jnp
6
+ import jax.scipy as jsp
7
+ from netket.driver.vmc import VMC
8
+
9
+ import netket.jax as nkjax
10
+ import netket.stats as nkstats
11
+ from netket.operator import AbstractOperator
12
+ from netket.errors import UnoptimalSRtWarning
13
+ import warnings
14
+
15
+ from netket.vqs import MCState
16
+ from netket.utils import mpi
17
+ from netket.utils.types import ScalarOrSchedule
18
+
19
+ from jax.flatten_util import ravel_pytree
20
+
21
+
22
+ @partial(jax.jit, static_argnames=("mode", "solver_fn"))
23
+ def SRt(O_L, local_energies, diag_shift, *, mode, solver_fn, e_mean=None):
24
+ """
25
+ For more details, see `https://arxiv.org/abs/2310.05715'. In particular,
26
+ the following parallel implementation is described in Appendix "Distributed SR computation".
27
+ """
28
+ N_params = O_L.shape[-1]
29
+ N_mc = O_L.shape[0] * mpi.n_nodes
30
+
31
+ local_energies = local_energies.flatten()
32
+
33
+ if e_mean is None:
34
+ e_mean = mpi.mean(local_energies)
35
+ de = jnp.conj(local_energies - e_mean).squeeze()
36
+
37
+ # * in this case O_L should be padded with zeros
38
+ assert (N_params % mpi.n_nodes) == 0
39
+
40
+ O_L = O_L / N_mc**0.5
41
+ dv = -2.0 * de / N_mc**0.5
42
+
43
+ if mode == "complex":
44
+ O_L = jnp.concatenate((O_L[:, 0], O_L[:, 1]), axis=0)
45
+ dv = jnp.concatenate((jnp.real(dv), -jnp.imag(dv)), axis=-1)
46
+ elif mode == "real":
47
+ dv = dv.real
48
+ else:
49
+ raise NotImplementedError()
50
+
51
+ # twons, (np, n_nodes) -> twons, np, n_nodes
52
+ O_LT = O_L.reshape(O_L.shape[0], -1, mpi.n_nodes)
53
+ # twons, np, n_nodes -> n_nodes, twons, np
54
+ O_LT = jnp.moveaxis(O_LT, -1, 0)
55
+
56
+ dv, token = mpi.mpi_gather_jax(dv)
57
+ dv = dv.reshape(-1, *dv.shape[2:])
58
+ O_LT, token = mpi.mpi_alltoall_jax(O_LT, token=token)
59
+
60
+ # proc, twons, np -> (proc, twons) np
61
+ O_LT = O_LT.reshape(-1, O_LT.shape[-1])
62
+
63
+ matrix, token = mpi.mpi_reduce_sum_jax(O_LT @ O_LT.T, token=token)
64
+ matrix_side = matrix.shape[-1] # * it can be Ns or 2*Ns, depending on mode
65
+
66
+ if mpi.rank == 0:
67
+ matrix = matrix + diag_shift * jnp.eye(
68
+ matrix_side
69
+ ) # * shift diagonal regularization
70
+ aus_vector = solver_fn(matrix, dv)
71
+ aus_vector = aus_vector.reshape(mpi.n_nodes, -1)
72
+ aus_vector, token = mpi.mpi_scatter_jax(aus_vector, token=token)
73
+ else:
74
+ shape = jnp.zeros((int(matrix_side / mpi.n_nodes),), dtype=jnp.float64)
75
+ aus_vector, token = mpi.mpi_scatter_jax(shape, token=token)
76
+
77
+ updates = O_L.T @ aus_vector
78
+ updates, token = mpi.mpi_allreduce_sum_jax(updates, token=token)
79
+
80
+ return -updates
81
+
82
+
83
+ inv_default_solver = lambda A, b: jnp.linalg.inv(A) @ b
84
+ linear_solver = lambda A, b: jsp.linalg.solve(A, b, assume_a="pos")
85
+
86
+
87
+ @jax.jit
88
+ def _flatten_samples(x):
89
+ return x.reshape(-1, x.shape[-1])
90
+
91
+
92
+ class VMC_SRt(VMC):
93
+ r"""
94
+ Energy minimization using Variational Monte Carlo (VMC) and the kernel
95
+ formulation of Stochastic Reconfiguration (SR). This approach lead to
96
+ *exactly* the same parameter updates of the standard SR with a
97
+ diagonal shift regularization. For this reason, it is equivalent to the standard
98
+ nk.driver.VMC with the preconditioner nk.optimizer.SR(solver=netket.optimizer.solver.solvers.solve)).
99
+ In the kernel SR framework, the updates of the parameters can be written as:
100
+
101
+ .. math::
102
+ \delta \theta = \tau X(X^TX + \lambda \mathbb{I}_{2M})^{-1} f,
103
+
104
+ where :math:`X \in R^{P \times 2M}` is the concatenation of the real and imaginary part
105
+ of the centered Jacobian, with P the number of parameters and M the number of samples.
106
+ The vector f is the concatenation of the real and imaginary part of the centered local
107
+ energy. Note that, to compute the updates, it is sufficient to invert an :math:`M\times M` matrix
108
+ instead of a :math:`P\times P` one. As a consequence, this formulation is useful
109
+ in the typical deep learning regime where :math:`P \gg M`.
110
+
111
+ See `R.Rende, L.L.Viteritti, L.Bardone, F.Becca and S.Goldt <https://arxiv.org/abs/2310.05715>`_
112
+ for a detailed description of the derivation. A similar result can be obtained by minimizing the
113
+ Fubini-Study distance with a specific constrain, see `A.Chen and M.Heyl <https://arxiv.org/abs/2302.01941>`_
114
+ for details.
115
+ """
116
+
117
+ def __init__(
118
+ self,
119
+ hamiltonian: AbstractOperator,
120
+ optimizer,
121
+ *,
122
+ diag_shift: ScalarOrSchedule,
123
+ linear_solver_fn: Callable[[jax.Array, jax.Array], jax.Array] = linear_solver,
124
+ jacobian_mode: Optional[str] = None,
125
+ variational_state: MCState = None,
126
+ ):
127
+ """
128
+ Initializes the driver class.
129
+
130
+ Args:
131
+ hamiltonian: The Hamiltonian of the system.
132
+ optimizer: Determines how optimization steps are performed given the
133
+ bare energy gradient.
134
+ diag_shift: The diagonal shift of the stochastic reconfiguration matrix.
135
+ Typical values are 1e-4 ÷ 1e-3. Can also be an optax schedule.
136
+ hamiltonian: The Hamiltonian of the system.
137
+ linear_solver_fn: Callable to solve the linear problem associated to the
138
+ updates of the parameters
139
+ jacobian_mode: The mode used to compute the jacobian of the variational state. Can be `'real'`
140
+ or `'complex'` (defaults to the dtype of the output of the model).
141
+ variational_state: The :class:`netket.vqs.MCState` to be optimised. Other
142
+ variational states are not supported.
143
+ """
144
+ super().__init__(hamiltonian, optimizer, variational_state=variational_state)
145
+
146
+ self._ham = hamiltonian.collect() # type: AbstractOperator
147
+ self.diag_shift = diag_shift
148
+ self.jacobian_mode = jacobian_mode
149
+ self._linear_solver_fn = linear_solver_fn
150
+
151
+ _, unravel_params_fn = ravel_pytree(self.state.parameters)
152
+ self._unravel_params_fn = jax.jit(unravel_params_fn)
153
+
154
+ if self.state.n_parameters % mpi.n_nodes != 0:
155
+ raise NotImplementedError(
156
+ f"""
157
+ VMC_SRt requires a network with a number of parameters
158
+ multiple of the number of MPI devices/ranks in use.
159
+
160
+ You have a network with {self.state.n_parameters}, but
161
+ there are {mpi.n_nodes} MPI ranks in use.
162
+
163
+ To fix this, either add some 'fake' parameters to your
164
+ network, or change the number of MPI nodes, or contribute
165
+ some padding logic to NetKet!
166
+ """
167
+ )
168
+
169
+ if self.state.n_parameters < self.state.n_samples:
170
+ warnings.warn(
171
+ UnoptimalSRtWarning(self.state.n_parameters, self.state.n_samples),
172
+ UserWarning,
173
+ stacklevel=2,
174
+ )
175
+
176
+ @property
177
+ def jacobian_mode(self) -> str:
178
+ """
179
+ The mode used to compute the jacobian of the variational state. Can be `'real'`
180
+ or `'complex'`.
181
+
182
+ Real mode truncates imaginary part of the wavefunction, while `complex` does not.
183
+ This internally uses :func:`netket.jax.jacobian`. See that function for a more
184
+ complete documentation.
185
+ """
186
+ return self._jacobian_mode
187
+
188
+ @jacobian_mode.setter
189
+ def jacobian_mode(self, mode: Optional[str]):
190
+ if mode is None:
191
+ mode = nkjax.jacobian_default_mode(
192
+ self.state._apply_fun,
193
+ self.state.parameters,
194
+ self.state.model_state,
195
+ self.state.samples,
196
+ warn=False,
197
+ )
198
+
199
+ if mode not in ["complex", "real"]:
200
+ raise ValueError(
201
+ "`jacobian_mode` only supports 'real' for real-valued wavefunctions and"
202
+ "'complex'.\n\n"
203
+ "`holomorphic` is not yet supported, but could be contributed in the future."
204
+ )
205
+ self._jacobian_mode = mode
206
+
207
+ def _forward_and_backward(self):
208
+ """
209
+ Performs a number of VMC optimization steps.
210
+
211
+ Args:
212
+ n_steps (int): Number of steps to perform.
213
+ """
214
+
215
+ self.state.reset()
216
+
217
+ # Compute the local energy estimator and average Energy
218
+ local_energies = self.state.local_estimators(self._ham)
219
+
220
+ self._loss_stats = nkstats.statistics(local_energies)
221
+
222
+ samples = _flatten_samples(self.state.samples)
223
+ jacobians = nkjax.jacobian(
224
+ self.state._apply_fun,
225
+ self.state.parameters,
226
+ samples,
227
+ self.state.model_state,
228
+ mode=self.jacobian_mode,
229
+ dense=True,
230
+ center=True,
231
+ ) # * jaxcobians is centered
232
+
233
+ diag_shift = self.diag_shift
234
+ if callable(self.diag_shift):
235
+ diag_shift = diag_shift(self.step_count)
236
+
237
+ updates = SRt(
238
+ jacobians,
239
+ local_energies,
240
+ diag_shift,
241
+ mode=self.jacobian_mode,
242
+ solver_fn=self._linear_solver_fn,
243
+ e_mean=self._loss_stats.Mean,
244
+ )
245
+
246
+ self._dp = self._unravel_params_fn(updates)
247
+
248
+ return self._dp