pygfmc 0.1.0__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 (48) hide show
  1. pygfmc-0.1.0/LICENSE +202 -0
  2. pygfmc-0.1.0/NOTICE +4 -0
  3. pygfmc-0.1.0/PKG-INFO +317 -0
  4. pygfmc-0.1.0/README.md +293 -0
  5. pygfmc-0.1.0/pygfmc/__init__.py +103 -0
  6. pygfmc-0.1.0/pygfmc/_output.py +20 -0
  7. pygfmc-0.1.0/pygfmc/_precision.py +9 -0
  8. pygfmc-0.1.0/pygfmc/_validation.py +19 -0
  9. pygfmc-0.1.0/pygfmc/engine/__init__.py +17 -0
  10. pygfmc-0.1.0/pygfmc/engine/driver.py +1510 -0
  11. pygfmc-0.1.0/pygfmc/engine/estimators.py +1362 -0
  12. pygfmc-0.1.0/pygfmc/engine/evolution.py +1101 -0
  13. pygfmc-0.1.0/pygfmc/engine/io.py +1540 -0
  14. pygfmc-0.1.0/pygfmc/engine/multi_gpu.py +866 -0
  15. pygfmc-0.1.0/pygfmc/hamiltonian/SpinHalf.py +649 -0
  16. pygfmc-0.1.0/pygfmc/hamiltonian/__init__.py +20 -0
  17. pygfmc-0.1.0/pygfmc/hamiltonian/_common.py +85 -0
  18. pygfmc-0.1.0/pygfmc/hamiltonian/bose_hubbard.py +479 -0
  19. pygfmc-0.1.0/pygfmc/hamiltonian/exact.py +375 -0
  20. pygfmc-0.1.0/pygfmc/hamiltonian/lattice.py +262 -0
  21. pygfmc-0.1.0/pygfmc/hamiltonian/observables.py +174 -0
  22. pygfmc-0.1.0/pygfmc/hamiltonian/plaquette.py +282 -0
  23. pygfmc-0.1.0/pygfmc/hamiltonian/spin.py +438 -0
  24. pygfmc-0.1.0/pygfmc/hamiltonian/toric.py +304 -0
  25. pygfmc-0.1.0/pygfmc/protocols.py +143 -0
  26. pygfmc-0.1.0/pygfmc/walkers/__init__.py +14 -0
  27. pygfmc-0.1.0/pygfmc/walkers/_h5io.py +27 -0
  28. pygfmc-0.1.0/pygfmc/walkers/reconfiguration.py +62 -0
  29. pygfmc-0.1.0/pygfmc/walkers/walker.py +342 -0
  30. pygfmc-0.1.0/pygfmc/wavefunction/__init__.py +20 -0
  31. pygfmc-0.1.0/pygfmc/wavefunction/_layout.py +19 -0
  32. pygfmc-0.1.0/pygfmc/wavefunction/_optional.py +35 -0
  33. pygfmc-0.1.0/pygfmc/wavefunction/_seed.py +19 -0
  34. pygfmc-0.1.0/pygfmc/wavefunction/_tied_params.py +66 -0
  35. pygfmc-0.1.0/pygfmc/wavefunction/cluster_cps.py +702 -0
  36. pygfmc-0.1.0/pygfmc/wavefunction/cluster_mlp.py +512 -0
  37. pygfmc-0.1.0/pygfmc/wavefunction/exact_ground_state.py +289 -0
  38. pygfmc-0.1.0/pygfmc/wavefunction/generic_netket_training.py +473 -0
  39. pygfmc-0.1.0/pygfmc/wavefunction/jastrow_bose_hubbard.py +341 -0
  40. pygfmc-0.1.0/pygfmc/wavefunction/jastrow_spin.py +318 -0
  41. pygfmc-0.1.0/pygfmc/wavefunction/jastrow_spin_half.py +499 -0
  42. pygfmc-0.1.0/pygfmc.egg-info/PKG-INFO +317 -0
  43. pygfmc-0.1.0/pygfmc.egg-info/SOURCES.txt +46 -0
  44. pygfmc-0.1.0/pygfmc.egg-info/dependency_links.txt +1 -0
  45. pygfmc-0.1.0/pygfmc.egg-info/requires.txt +12 -0
  46. pygfmc-0.1.0/pygfmc.egg-info/top_level.txt +1 -0
  47. pygfmc-0.1.0/pyproject.toml +45 -0
  48. pygfmc-0.1.0/setup.cfg +4 -0
pygfmc-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
pygfmc-0.1.0/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ PyGFMC
2
+ Copyright 2026 Robin Schaefer
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
pygfmc-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,317 @@
1
+ Metadata-Version: 2.4
2
+ Name: pygfmc
3
+ Version: 0.1.0
4
+ Summary: JAX-based Green's Function Monte Carlo for quantum lattice models
5
+ Author: Robin Schaefer
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/robin-schaefer/PyGFMC
8
+ Project-URL: Documentation, https://robin-schaefer.github.io/PyGFMC/
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Requires-Dist: jax
14
+ Requires-Dist: numpy
15
+ Requires-Dist: scipy
16
+ Requires-Dist: h5py
17
+ Provides-Extra: netket
18
+ Requires-Dist: netket; extra == "netket"
19
+ Requires-Dist: optax; extra == "netket"
20
+ Requires-Dist: flax; extra == "netket"
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest; extra == "test"
23
+ Dynamic: license-file
24
+
25
+ # PyGFMC
26
+
27
+ PyGFMC is a Green's Function Monte Carlo (GFMC) code for quantum lattice models, written in [JAX](https://github.com/jax-ml/jax) so it runs on CPUs and GPUs (including several GPUs at once). It projects the ground state out of a trial state by imaginary-time evolution, with importance sampling by a guiding wavefunction. It covers:
28
+
29
+ - three propagators: `single_step`, `multi_step` and continuous-time `cont_time` (the default);
30
+ - mixed estimators for the energy, and pure (forward-walking) estimators for diagonal and off-diagonal observables;
31
+ - spin-1/2, spin-S, Bose-Hubbard, plaquette ring-exchange and toric-code Hamiltonians on arbitrary graphs;
32
+ - Jastrow guides for spin-1/2, spin-S and bosons, cluster-CPS and cluster-MLP guides, optionally trained by VMC through NetKet;
33
+ - HDF5 checkpointing (lossless compressed series) with bit-identical continuation, and re-estimation with blocked-jackknife error bars.
34
+
35
+ ## Installation
36
+
37
+ From this folder:
38
+
39
+ ```bash
40
+ pip install . # GFMC only
41
+ pip install '.[netket]' # + training guides with NetKet (VMC)
42
+ pip install '.[test]' # + pytest
43
+ ```
44
+
45
+ For GPU support, install the CUDA build of JAX first, following the [JAX installation guide](https://docs.jax.dev/en/latest/installation.html).
46
+
47
+ ## Dependencies
48
+
49
+ | Group | Packages | Needed for |
50
+ |---|---|---|
51
+ | core | `jax`, `numpy`, `scipy`, `h5py` | everything: GFMC runs, Hamiltonians, guides, exact diagonalization, HDF5 I/O |
52
+ | `netket` extra | `netket`, `optax`, `flax` | only for **training** guides by VMC (`pygfmc.wavefunction.train_with_netket`) |
53
+ | `test` extra | `pytest` | the test suite |
54
+
55
+ Python >= 3.11. Tested with Python 3.13.9, jax 0.9.2, numpy 2.3.5, scipy 1.16.3, h5py 3.15.1, flax 0.12.5, netket 3.21.0 and optax 0.2.6.
56
+
57
+ The NetKet imports are inside the training function, so `import pygfmc` works without NetKet. A training call without it raises an `ImportError` that says how to install it. Guides trained elsewhere can be saved to HDF5 and loaded for GFMC.
58
+
59
+ ## Package layout
60
+
61
+ The code is one package, `pygfmc`, with four subpackages: one for each
62
+ ingredient of a simulation (walkers, Hamiltonian, guide) and the engine that
63
+ runs it. The everyday engine API (`run`, `run_gfmc`, `statistics` and the
64
+ HDF5 functions) is re-exported at the top level, so `from pygfmc import run`
65
+ works; walkers, Hamiltonians and guides are imported from their subpackages
66
+ (`from pygfmc.walkers import prepare_walkers_sz`,
67
+ `from pygfmc.hamiltonian import SpinHalf`, `from pygfmc.wavefunction import JastrowSpinHalf`).
68
+ Importing `pygfmc` also enables deterministic XLA GPU kernels (set
69
+ `PYGFMC_NONDETERMINISTIC=1` before the import to opt out).
70
+ All console output of the package goes through `pygfmc._output.emit`, gated
71
+ on the `verbosity` argument of the drivers (`verbosity=0` is silent); set
72
+ `pygfmc._output.stream` to redirect it to a file-like object.
73
+
74
+ ```
75
+ pygfmc/
76
+ ├── __init__.py # deterministic XLA flags, top-level API, __version__
77
+ ├── _output.py # every printed message passes through emit(), gated on verbosity
78
+ ├── protocols.py # Operator, DiagonalOperator, Guide: the interfaces as typing.Protocol classes
79
+ ├── _precision.py # float_dtype(): float64 when jax_enable_x64 is on, else float32
80
+ ├── walkers/ # Walker population, initializers, reconfiguration
81
+ ├── engine/ # the GFMC engine
82
+ ├── hamiltonian/ # models, lattices, exact diagonalization
83
+ └── wavefunction/ # guiding wavefunctions
84
+ ```
85
+
86
+ | Folder | Role | Detailed documentation |
87
+ |---|---|---|
88
+ | `pygfmc/walkers/` | The `Walker` population (a JAX pytree with HDF5 `save`/`load`), the initializers `prepare_walkers_random`, `prepare_walkers_sz`, `prepare_walkers_from_configs`, and `reconfiguration` (systematic resampling). | [`pygfmc/walkers/README.md`](https://github.com/robin-schaefer/PyGFMC/blob/main/codes/pygfmc/walkers/README.md) |
89
+ | `pygfmc/engine/` | The GFMC engine: the propagators, reconfiguration (resampling), the estimators and diagnostics, the drivers `run` / `run_gfmc` (and the multi-device `run_gfmc_pmap` behind `run`), and HDF5 storage, continuation and re-estimation. | [`pygfmc/engine/README.md`](https://github.com/robin-schaefer/PyGFMC/blob/main/codes/pygfmc/engine/README.md) |
90
+ | `pygfmc/hamiltonian/` | Hamiltonians and measurement operators that follow the rate protocol `pygfmc.Operator` (`M_total`, `get_rates`, `generate_state`), lattice factories, structure-factor measurement operators, and exact diagonalization for reference values. | [`pygfmc/hamiltonian/README.md`](https://github.com/robin-schaefer/PyGFMC/blob/main/codes/pygfmc/hamiltonian/README.md) |
91
+ | `pygfmc/wavefunction/` | Guiding (trial) wavefunctions, which follow the guide protocol `pygfmc.Guide` (`log_diff_from_operator` / `log_diff_from_configs` / `log_psi`), plus optional VMC training through NetKet. | [`pygfmc/wavefunction/README.md`](https://github.com/robin-schaefer/PyGFMC/blob/main/codes/pygfmc/wavefunction/README.md) |
92
+
93
+ **Each subpackage has its own `README.md`.** They document every module, all public functions and classes with their signatures, the protocols for writing your own Hamiltonian or guide, and the conventions (step size, estimator windows, return values, resuming a run). This file gives an overview only.
94
+
95
+ ## Quick start
96
+
97
+ ```python
98
+ import jax
99
+ from pygfmc import run, evaluate_observables
100
+ from pygfmc.walkers import prepare_walkers_sz
101
+ from pygfmc.hamiltonian import SpinHalf, chain, exact_diagonalization
102
+ from pygfmc.wavefunction import JastrowSpinHalf
103
+
104
+ # L=8 Heisenberg antiferromagnet on a ring, in the sublattice-rotated
105
+ # (sign-problem-free) form J_x = J_y = -1, J_z = +1.
106
+ lat = chain(8)
107
+ H = SpinHalf.create(lat.edges, J_x=-1.0, J_y=-1.0, J_z=1.0)
108
+ guide = JastrowSpinHalf(H.N, H.edges, beta=0.3)
109
+ walkers = prepare_walkers_sz(512, H.N, jax.random.PRNGKey(0), sz=0)
110
+
111
+ # fresh, unequilibrated walkers: ask for a warm-up explicitly (default is none)
112
+ walkers, energy, obs, stats, raw = run(
113
+ walkers, 2000, H, step_size=0.2, guide=guide,
114
+ p_array=[2, 4, 8, 16], method="cont_time",
115
+ rng_key=jax.random.PRNGKey(1), warmup_steps=500, verbosity=0)
116
+ print(energy) # dict p -> energy: {2: -3.65148..., 4: -3.65151..., 8: -3.65153..., 16: -3.65157...}
117
+ print(exact_diagonalization(H)[0][0]) # -3.6510934...
118
+
119
+ # continue the same Markov chain (bit-identical to one longer run); the
120
+ # walkers are equilibrated now, so no warm-up, and the compiled scan is reused
121
+ walkers, energy, obs, stats, raw = run(
122
+ walkers, 2000, H, 0.2, guide, [2, 4, 8, 16],
123
+ rng_key=stats["parameters/rng_key_next"],
124
+ avg_log_weight=stats["avg_log_weight"], verbosity=0)
125
+
126
+ # blocked-jackknife error bars from the returned raw series
127
+ E, O, E_err, O_err = evaluate_observables(raw, n_blocks=20) # E_err[p] ~ 0.0016
128
+ ```
129
+
130
+ **Warm-up is off by default (`warmup_steps=0`).** That is right when you
131
+ continue from an equilibrated ensemble (walkers returned by a previous run or
132
+ loaded from a checkpoint). When you start from freshly prepared walkers, pass
133
+ a warm-up explicitly, e.g. `warmup_steps=10000` (the example uses 500 because
134
+ the system is tiny); otherwise the first production steps are not
135
+ equilibrated and `avg_log_weight` stays at its initial estimate.
136
+
137
+ ## Example notebooks
138
+
139
+ The repository's [`notebooks/`](https://github.com/robin-schaefer/PyGFMC/blob/main/notebooks/README.md) folder holds runnable
140
+ examples, stored with the outputs of a full run:
141
+
142
+ | Notebook | Model | What it shows |
143
+ |---|---|---|
144
+ | `bose_hubbard_chain.ipynb` | Bose-Hubbard chain, 50 sites | a guide trained with NetKet, then the ground-state energy |
145
+ | `transverse_field_ising_chain.ipynb` | critical spin-1 transverse-field Ising chain, 12 sites | every code block of the documentation page *Running a simulation* |
146
+ | `xxz_chain.ipynb` | XXZ chain with random couplings and a field, 20 sites | the paper's example: a Jastrow guide trained with NetKet, observables, the raw per-step series, the exact ground state as guide |
147
+ | `n_body_model.ipynb` | four-site n-body model with a field, 12 sites | writing your own Hamiltonian and guiding wavefunction, and training the guide with NetKet |
148
+ | `kagome_xxz.ipynb` | XXZ model on the kagome lattice, 18 and 108 sites | a symmetry-reduced cluster guide: training, storing, loading, and its effect on GFMC |
149
+ | `toric_code.ipynb` | toric code, 10×10 and 3×3 tori | the exact energy without a field, and the convergence with fields against exact diagonalization |
150
+ | `ring_model_pyrochlore.ipynb` | ring exchange on the pyrochlore lattice, 128 sites | sweep from pure ring exchange to the Rokhsar-Kivelson point |
151
+
152
+ ## Conventions at a glance
153
+
154
+ - Configurations are stored as floats: ±1 for spin 1/2 (not 0/1), `m ∈ {−S, …, S}` for spin S, occupations `0, …, n_max` for bosons.
155
+ - Everything runs in float32 by default; importing `pygfmc` sets `NETKET_ENABLE_X64=0`, so a later `import netket` does not switch JAX to float64.
156
+ - `method` is one of `"single_step"`, `"multi_step"` or `"cont_time"` (the default). With `cont_time`, `step_size` is the imaginary time per branching step (any positive float) and no shift is needed. With the discrete methods, `step_size` is an integer number of sub-steps of `(lam - H)`, and the keyword `lam` (the shift, `lam >= max_x H_xx`) is required.
157
+ - `run` / `run_gfmc` return `(walkers, energy, obs, stats, raw)`. Access energy as `energy[p]` and observables as `obs[name][p]`. For even windows, the projection depth on each side of the estimator is `tau = (p/2) * step_size`.
158
+ - `rng_key` is the position of the chain. Passing `stats["parameters/rng_key_next"]` back continues the run exactly. Repeated `run_gfmc` calls reuse the compiled scans, so a continuation does not recompile.
159
+ - `warmup_steps` defaults to 0 (no warm-up); pass e.g. `warmup_steps=10000` for a fresh start.
160
+ - `verbosity=0` prints nothing; the default progress line reports the energy per `p`, and operator estimates are printed only at `verbosity >= 8`.
161
+ - Off-diagonal measurement operators must have non-negative rates, and all `p` must be even when one of them has an off-diagonal transition (`M_total > 1`).
162
+
163
+ ## Full list of public functions and classes
164
+
165
+ These are the names each subpackage exports, grouped by the module that defines them. The subfolder READMEs also list the methods of every class (`create`, `get_rates`, `log_psi`, `save`/`load`, ...) and the module-level functions that are not exported (e.g. `pygfmc.engine.multi_gpu.run_gfmc_pmap`). Everything listed under `pygfmc.engine` is also importable directly from `pygfmc`.
166
+
167
+ ### `pygfmc.walkers`
168
+
169
+ **`pygfmc/walkers/walker.py`**
170
+
171
+ | Name | Kind | Description |
172
+ |---|---|---|
173
+ | `prepare_walkers_random` | function | Initialize walkers by drawing every site independently from `states`. |
174
+ | `prepare_walkers_sz` | function | Initialize walkers in a fixed-charge sector drawn from `states`. |
175
+ | `prepare_walkers_from_configs` | function | Initialize walkers at user-supplied configurations, an `(N_walkers, N_sites)` array. |
176
+ | `Walker` | class | Walker population (or a single walker) as a JAX pytree. |
177
+
178
+ **`pygfmc/walkers/reconfiguration.py`**
179
+
180
+ | Name | Kind | Description |
181
+ |---|---|---|
182
+ | `reconfiguration` | function | Systematic resampling of the walker population. |
183
+
184
+ ### `pygfmc.engine`
185
+
186
+ **`pygfmc/engine/estimators.py`**
187
+
188
+ | Name | Kind | Description |
189
+ |---|---|---|
190
+ | `statistics` | function | Run branching steps and collect diagnostic statistics. |
191
+
192
+ **`pygfmc/engine/driver.py`**
193
+
194
+ | Name | Kind | Description |
195
+ |---|---|---|
196
+ | `run_gfmc` | function | Run the GFMC production loop on a single device. |
197
+
198
+ **`pygfmc/engine/io.py`**
199
+
200
+ | Name | Kind | Description |
201
+ |---|---|---|
202
+ | `evaluate_observables` | function | Re-evaluate the energy and the observables from raw per-step series. |
203
+ | `load_raw_from_HDF5` | function | Read a file's raw series back in the layout `run` returns them in. |
204
+ | `run_from_HDF5` | function | Continue a stored chain in one call, and return what `run_gfmc` returns. |
205
+ | `check_run_compatible` | function | Validate a planned run against a stored file *before* walking. |
206
+ | `resume_from_HDF5` | function | Assemble the `run_gfmc` arguments that continue a stored chain. |
207
+ | `write_to_HDF5` | function | Append one GFMC run to an HDF5 file as a self-contained group. |
208
+
209
+ **`pygfmc/engine/multi_gpu.py`**
210
+
211
+ | Name | Kind | Description |
212
+ |---|---|---|
213
+ | `run` | function | Auto-dispatch GFMC: run_gfmc_pmap on >1 devices, run_gfmc otherwise. |
214
+
215
+ ### `pygfmc.hamiltonian`
216
+
217
+ **`pygfmc/hamiltonian/bose_hubbard.py`**
218
+
219
+ | Name | Kind | Description |
220
+ |---|---|---|
221
+ | `BoseHubbard` | class | Bose-Hubbard model; see the module docstring for H and the rate layout. |
222
+
223
+ **`pygfmc/hamiltonian/exact.py`**
224
+
225
+ | Name | Kind | Description |
226
+ |---|---|---|
227
+ | `exact_diagonalization` | function | Lowest eigenpairs of `hamiltonian`, with observables on each. |
228
+
229
+ **`pygfmc/hamiltonian/lattice.py`**
230
+
231
+ | Name | Kind | Description |
232
+ |---|---|---|
233
+ | `chain` | function | Nearest-neighbour chain of `n_sites` sites. |
234
+ | `kagome` | function | Kagome lattice of `Lx` x `Ly` unit cells (O(N)). |
235
+ | `Lattice` | class | A finite lattice: a site count, an edge list and optional metadata. |
236
+ | `pyrochlore` | function | Pyrochlore lattice built from explicit FCC unit-cell edge templates (O(N)). |
237
+
238
+ **`pygfmc/hamiltonian/observables.py`**
239
+
240
+ | Name | Kind | Description |
241
+ |---|---|---|
242
+ | `SzSzStructureFactor` | class | `S^{zz}(\vec k)` for one or many wavevectors, from positions. |
243
+ | `is_valid_k` | function | Whether each wavevector lies in the reciprocal lattice of the system. |
244
+
245
+ **`pygfmc/hamiltonian/plaquette.py`**
246
+
247
+ | Name | Kind | Description |
248
+ |---|---|---|
249
+ | `PlaquetteModel` | class | Plaquette ring-exchange / Rokhsar–Kivelson Hamiltonian. |
250
+
251
+ **`pygfmc/hamiltonian/spin.py`**
252
+
253
+ | Name | Kind | Description |
254
+ |---|---|---|
255
+ | `Spin` | class | Spin-S Hamiltonian; see the module docstring for H and the rate layout. |
256
+
257
+ **`pygfmc/hamiltonian/SpinHalf.py`**
258
+
259
+ | Name | Kind | Description |
260
+ |---|---|---|
261
+ | `SpinHalf` | class | Spin-1/2 XYZ model with longitudinal and transverse fields. |
262
+ | `StructureFactor` | function | The k-resolved correlator `AB(0) + AB(k)` as ONE `SpinHalf`. |
263
+
264
+ **`pygfmc/hamiltonian/toric.py`**
265
+
266
+ | Name | Kind | Description |
267
+ |---|---|---|
268
+ | `ToricCode` | class | Toric code Hamiltonian on an Lx × Ly torus. |
269
+
270
+ ### `pygfmc.wavefunction`
271
+
272
+ **`pygfmc/wavefunction/cluster_cps.py`**
273
+
274
+ | Name | Kind | Description |
275
+ |---|---|---|
276
+ | `ClusterCPS` | class | Cluster-CPS guide composed from one or more patch groups. |
277
+
278
+ **`pygfmc/wavefunction/cluster_mlp.py`**
279
+
280
+ | Name | Kind | Description |
281
+ |---|---|---|
282
+ | `ClusterMLP` | class | Per-cluster MLP guide for SpinHalf, with one shared tanh MLP per cluster group. |
283
+
284
+ **`pygfmc/wavefunction/exact_ground_state.py`**
285
+
286
+ | Name | Kind | Description |
287
+ |---|---|---|
288
+ | `ExactGroundState` | class | Guiding wavefunction with amplitudes from the exact ground state. |
289
+
290
+ **`pygfmc/wavefunction/generic_netket_training.py`**
291
+
292
+ | Name | Kind | Description |
293
+ |---|---|---|
294
+ | `make_hilbert` | function | A NetKet Hilbert space whose local states are exactly these values. |
295
+ | `train_with_netket` | function | Train `guide` on `hamiltonian` with NetKet VMC and return a new guide. |
296
+
297
+ **`pygfmc/wavefunction/jastrow_bose_hubbard.py`**
298
+
299
+ | Name | Kind | Description |
300
+ |---|---|---|
301
+ | `JastrowBoseHubbard` | class | Jastrow guide for boson occupations, with an on-site (Gutzwiller) term. |
302
+
303
+ **`pygfmc/wavefunction/jastrow_spin_half.py`**
304
+
305
+ | Name | Kind | Description |
306
+ |---|---|---|
307
+ | `JastrowSpinHalf` | class | Jastrow guiding wavefunction with sparse two-body couplings. |
308
+
309
+ **`pygfmc/wavefunction/jastrow_spin.py`**
310
+
311
+ | Name | Kind | Description |
312
+ |---|---|---|
313
+ | `JastrowSpin` | class | Jastrow guide for spin-S configurations, with a single-ion term. |
314
+
315
+ ## License
316
+
317
+ Apache-2.0, see [`LICENSE`](https://github.com/robin-schaefer/PyGFMC/blob/main/codes/LICENSE) and [`NOTICE`](https://github.com/robin-schaefer/PyGFMC/blob/main/codes/NOTICE).