hamon 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.
- hamon-0.1.0/LICENSE +202 -0
- hamon-0.1.0/NOTICE +22 -0
- hamon-0.1.0/PKG-INFO +240 -0
- hamon-0.1.0/README.md +180 -0
- hamon-0.1.0/hamon/__init__.py +51 -0
- hamon-0.1.0/hamon/block_management.py +496 -0
- hamon-0.1.0/hamon/block_sampling.py +677 -0
- hamon-0.1.0/hamon/boundary_energy.py +322 -0
- hamon-0.1.0/hamon/conditional_samplers.py +198 -0
- hamon-0.1.0/hamon/dynamic_blocks.py +436 -0
- hamon-0.1.0/hamon/factor.py +112 -0
- hamon-0.1.0/hamon/graph_utils.py +172 -0
- hamon-0.1.0/hamon/interaction.py +71 -0
- hamon-0.1.0/hamon/models/__init__.py +18 -0
- hamon-0.1.0/hamon/models/discrete_ebm.py +406 -0
- hamon-0.1.0/hamon/models/ebm.py +122 -0
- hamon-0.1.0/hamon/models/ising.py +316 -0
- hamon-0.1.0/hamon/nrpt.py +657 -0
- hamon-0.1.0/hamon/observers.py +293 -0
- hamon-0.1.0/hamon/pgm.py +92 -0
- hamon-0.1.0/hamon/py.typed +0 -0
- hamon-0.1.0/hamon/round_trips.py +202 -0
- hamon-0.1.0/hamon.egg-info/PKG-INFO +240 -0
- hamon-0.1.0/hamon.egg-info/SOURCES.txt +43 -0
- hamon-0.1.0/hamon.egg-info/dependency_links.txt +1 -0
- hamon-0.1.0/hamon.egg-info/requires.txt +34 -0
- hamon-0.1.0/hamon.egg-info/top_level.txt +1 -0
- hamon-0.1.0/pyproject.toml +109 -0
- hamon-0.1.0/setup.cfg +4 -0
- hamon-0.1.0/tests/test_block_management.py +358 -0
- hamon-0.1.0/tests/test_block_sampling.py +453 -0
- hamon-0.1.0/tests/test_boundary_energy.py +252 -0
- hamon-0.1.0/tests/test_comprehensive.py +699 -0
- hamon-0.1.0/tests/test_discover_chain_count.py +273 -0
- hamon-0.1.0/tests/test_discrete_ebm.py +1140 -0
- hamon-0.1.0/tests/test_dynamic_blocks.py +344 -0
- hamon-0.1.0/tests/test_ebm.py +94 -0
- hamon-0.1.0/tests/test_factor.py +66 -0
- hamon-0.1.0/tests/test_interaction.py +46 -0
- hamon-0.1.0/tests/test_ising.py +231 -0
- hamon-0.1.0/tests/test_nrpt.py +339 -0
- hamon-0.1.0/tests/test_observers.py +199 -0
- hamon-0.1.0/tests/test_readme.py +25 -0
- hamon-0.1.0/tests/test_round_trips.py +219 -0
- hamon-0.1.0/tests/test_train_mnist.py +310 -0
hamon-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.
|
hamon-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Hamon
|
|
2
|
+
Copyright 2025 dek3rr
|
|
3
|
+
|
|
4
|
+
This project is a spiritual successor to thrml (https://github.com/Extropic-AI/thrml).
|
|
5
|
+
Portions of the block sampling, factor, and PGM infrastructure are derived from the
|
|
6
|
+
original thrml library:
|
|
7
|
+
|
|
8
|
+
thrml
|
|
9
|
+
Copyright 2025 Extropic AI
|
|
10
|
+
Licensed under the Apache License, Version 2.0
|
|
11
|
+
|
|
12
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
you may not use this file except in compliance with the License.
|
|
14
|
+
You may obtain a copy of the License at
|
|
15
|
+
|
|
16
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
|
|
18
|
+
Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
See the License for the specific language governing permissions and
|
|
22
|
+
limitations under the License.
|
hamon-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hamon
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: JAX-native thermal sampling for discrete energy-based models
|
|
5
|
+
Author: dek3rr
|
|
6
|
+
Maintainer: dek3rr
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Repository, https://github.com/dek3rr/hamon
|
|
9
|
+
Project-URL: Documentation, https://dek3rr.github.io/hamon
|
|
10
|
+
Project-URL: Issues, https://github.com/dek3rr/hamon/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/dek3rr/hamon/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: jax,mcmc,parallel-tempering,gibbs-sampling,energy-based-models,ising,probabilistic-graphical-models,sampling,gpu
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
License-File: NOTICE
|
|
29
|
+
Requires-Dist: equinox>=0.11.2
|
|
30
|
+
Requires-Dist: jaxtyping>=0.2.23
|
|
31
|
+
Provides-Extra: examples
|
|
32
|
+
Requires-Dist: jupyter>=1.0; extra == "examples"
|
|
33
|
+
Requires-Dist: matplotlib>=3.7.1; extra == "examples"
|
|
34
|
+
Requires-Dist: networkx>=2.6.3; extra == "examples"
|
|
35
|
+
Requires-Dist: dwave_networkx>=0.8.0; extra == "examples"
|
|
36
|
+
Requires-Dist: scikit-learn>=1.7.0; extra == "examples"
|
|
37
|
+
Provides-Extra: testing
|
|
38
|
+
Requires-Dist: coverage>=7.6; extra == "testing"
|
|
39
|
+
Requires-Dist: pytest>=8.3; extra == "testing"
|
|
40
|
+
Requires-Dist: nbmake>=1.5; extra == "testing"
|
|
41
|
+
Requires-Dist: networkx>=2.6.3; extra == "testing"
|
|
42
|
+
Requires-Dist: optax>=0.2.4; extra == "testing"
|
|
43
|
+
Requires-Dist: setuptools>=75.0; extra == "testing"
|
|
44
|
+
Provides-Extra: development
|
|
45
|
+
Requires-Dist: ruff>=0.15; extra == "development"
|
|
46
|
+
Requires-Dist: pyright>=1.1.400; extra == "development"
|
|
47
|
+
Requires-Dist: pytest-cov>=4.0; extra == "development"
|
|
48
|
+
Requires-Dist: build>=1.0; extra == "development"
|
|
49
|
+
Requires-Dist: twine>=6.0; extra == "development"
|
|
50
|
+
Provides-Extra: docs
|
|
51
|
+
Requires-Dist: hippogriffe>=0.2.0; extra == "docs"
|
|
52
|
+
Requires-Dist: griffe>=1.7; extra == "docs"
|
|
53
|
+
Requires-Dist: mkdocs>=1.6; extra == "docs"
|
|
54
|
+
Requires-Dist: mkdocs-include-exclude-files>=0.1.0; extra == "docs"
|
|
55
|
+
Requires-Dist: mkdocs-ipynb>=0.1.0; extra == "docs"
|
|
56
|
+
Requires-Dist: mkdocs-material>=9.6; extra == "docs"
|
|
57
|
+
Requires-Dist: mkdocstrings[python]>=0.28; extra == "docs"
|
|
58
|
+
Requires-Dist: pymdown-extensions>=10.14; extra == "docs"
|
|
59
|
+
Dynamic: license-file
|
|
60
|
+
|
|
61
|
+
<h1 align="center">Hamon</h1>
|
|
62
|
+
|
|
63
|
+
<p align="center">
|
|
64
|
+
JAX-native thermal sampling for discrete energy-based models.
|
|
65
|
+
</p>
|
|
66
|
+
|
|
67
|
+
<p align="center">
|
|
68
|
+
<a href="https://pypi.org/project/hamon"><img src="https://img.shields.io/pypi/v/hamon" alt="PyPI"></a>
|
|
69
|
+
<a href="https://pypi.org/project/hamon"><img src="https://img.shields.io/pypi/pyversions/hamon" alt="Python"></a>
|
|
70
|
+
<a href="https://github.com/dek3rr/hamon/blob/main/LICENSE"><img src="https://img.shields.io/github/license/dek3rr/hamon" alt="License"></a>
|
|
71
|
+
</p>
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
Hamon is a JAX library for sampling from discrete probabilistic graphical models.
|
|
76
|
+
It provides GPU-accelerated block Gibbs sampling, non-reversible parallel tempering
|
|
77
|
+
with adaptive schedule optimization, and tools for building and training Ising models,
|
|
78
|
+
RBMs, and other discrete energy-based models.
|
|
79
|
+
|
|
80
|
+
Built on [Extropic AI's thrml](https://github.com/Extropic-AI/thrml) foundation,
|
|
81
|
+
Hamon diverges as an independent library with original algorithmic contributions
|
|
82
|
+
and performance optimizations.
|
|
83
|
+
|
|
84
|
+
## Why "Hamon"?
|
|
85
|
+
|
|
86
|
+
In Japanese swordsmithing, the *hamon* (刃文, "blade pattern") is the visible
|
|
87
|
+
wave that appears along the edge of a katana after differential hardening. The
|
|
88
|
+
smith coats the blade in clay — thin along the cutting edge, thick along the
|
|
89
|
+
spine — then heats the steel to critical temperature and quenches it in water.
|
|
90
|
+
The edge cools fast into hard martensite; the spine cools slowly into tough
|
|
91
|
+
pearlite. The boundary between these two phases is the hamon: a pattern born
|
|
92
|
+
entirely from a thermal process, where controlled temperature gradients reveal
|
|
93
|
+
structure hidden in disordered steel.
|
|
94
|
+
|
|
95
|
+
The parallel to this library is direct. Hamon explores discrete energy
|
|
96
|
+
landscapes by running chains at different temperatures and exchanging
|
|
97
|
+
information across the thermal gradient. Structure emerges at the boundary
|
|
98
|
+
between mixing regimes — hot chains explore freely, cold chains resolve fine
|
|
99
|
+
detail, and the communication between them is what makes sampling work. The
|
|
100
|
+
hamon on a blade is proof that a thermal process found the right boundary.
|
|
101
|
+
The diagnostics in this library measure the same thing.
|
|
102
|
+
|
|
103
|
+
## Installation
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
pip install hamon
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
For development:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
git clone https://github.com/dek3rr/hamon.git
|
|
113
|
+
cd hamon
|
|
114
|
+
pip install -e ".[development,testing,examples]"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Requires Python ≥ 3.10 and a JAX installation ([GPU setup guide](https://jax.readthedocs.io/en/latest/installation.html)).
|
|
118
|
+
|
|
119
|
+
## Quick example
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
import jax
|
|
123
|
+
import jax.numpy as jnp
|
|
124
|
+
from hamon import SpinNode, Block, SamplingSchedule, sample_states
|
|
125
|
+
from hamon.models import IsingEBM, IsingSamplingProgram, hinton_init
|
|
126
|
+
|
|
127
|
+
nodes = [SpinNode() for _ in range(5)]
|
|
128
|
+
edges = [(nodes[i], nodes[i + 1]) for i in range(4)]
|
|
129
|
+
model = IsingEBM(nodes, edges, jnp.zeros(5), jnp.ones(4) * 0.5, jnp.array(1.0))
|
|
130
|
+
|
|
131
|
+
free_blocks = [Block(nodes[::2]), Block(nodes[1::2])]
|
|
132
|
+
program = IsingSamplingProgram(model, free_blocks, clamped_blocks=[])
|
|
133
|
+
|
|
134
|
+
key = jax.random.key(0)
|
|
135
|
+
k_init, k_samp = jax.random.split(key, 2)
|
|
136
|
+
init_state = hinton_init(k_init, model, free_blocks, ())
|
|
137
|
+
schedule = SamplingSchedule(n_warmup=100, n_samples=1000, steps_per_sample=2)
|
|
138
|
+
|
|
139
|
+
samples = sample_states(k_samp, program, schedule, init_state, [], [Block(nodes)])
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Non-reversible parallel tempering
|
|
143
|
+
|
|
144
|
+
Hamon implements adaptive NRPT based on
|
|
145
|
+
[Syed et al. (2021)](https://arxiv.org/abs/1905.02939), with vectorized swaps
|
|
146
|
+
that exploit the temperature-linearity of Ising energies:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from hamon.nrpt import nrpt_adaptive
|
|
150
|
+
|
|
151
|
+
def ebm_factory(betas):
|
|
152
|
+
return [IsingEBM(nodes, edges, biases, weights, jnp.array(float(b))) for b in betas]
|
|
153
|
+
|
|
154
|
+
def program_factory(ebms):
|
|
155
|
+
return [IsingSamplingProgram(e, free_blocks, []) for e in ebms]
|
|
156
|
+
|
|
157
|
+
states, _, stats = nrpt_adaptive(
|
|
158
|
+
jax.random.key(42),
|
|
159
|
+
ebm_factory,
|
|
160
|
+
program_factory,
|
|
161
|
+
init_states=[init_state] * 8,
|
|
162
|
+
clamp_state=[],
|
|
163
|
+
n_rounds=500,
|
|
164
|
+
gibbs_steps_per_round=5,
|
|
165
|
+
initial_betas=jnp.linspace(0.1, 2.0, 8),
|
|
166
|
+
n_tune=5,
|
|
167
|
+
rounds_per_tune=200,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
print(f"Final Λ: {stats['round_trip_diagnostics']['Lambda']:.3f}")
|
|
171
|
+
print(f"Round trip rate: {stats['round_trip_diagnostics']['tau_observed']:.4f}")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Key features of the NRPT implementation:
|
|
175
|
+
|
|
176
|
+
- **Vectorized swaps**: 1 energy evaluation per chain (not 4 per pair), all
|
|
177
|
+
non-overlapping swaps execute simultaneously via permutation indexing
|
|
178
|
+
- **Adaptive scheduling**: iteratively tunes β spacing to equalize rejection
|
|
179
|
+
rates, minimizing the global communication barrier Λ
|
|
180
|
+
- **Round trip tracking**: monitors the index process per machine, estimates
|
|
181
|
+
Λ and predicted optimal rate τ̄ = 1/(2+2Λ)
|
|
182
|
+
- **Chain count discovery**: iteratively probes to find the right number of
|
|
183
|
+
chains for a target acceptance rate
|
|
184
|
+
|
|
185
|
+
## What makes Hamon fast
|
|
186
|
+
|
|
187
|
+
**All chains run in one kernel.** Parallel tempering uses `jax.vmap` over chains
|
|
188
|
+
instead of a Python loop. Compile time is constant regardless of chain count.
|
|
189
|
+
|
|
190
|
+
**No redundant work in the sampler loop.** Global state is threaded through
|
|
191
|
+
`lax.scan` as a carry. Block updates use targeted scatters instead of rebuilding
|
|
192
|
+
the full state tensor each iteration.
|
|
193
|
+
|
|
194
|
+
**Energy evaluation skips unnecessary work.** Pre-built `BlockSpec` objects are
|
|
195
|
+
passed through directly — no reconstruction on every `energy()` call.
|
|
196
|
+
|
|
197
|
+
**Accumulator dtypes are explicit.** The moment accumulator pins its dtype at
|
|
198
|
+
construction, avoiding silent float64 promotion on GPU.
|
|
199
|
+
|
|
200
|
+
## Citing Hamon
|
|
201
|
+
|
|
202
|
+
If you use Hamon in your research, please cite:
|
|
203
|
+
|
|
204
|
+
```bibtex
|
|
205
|
+
@software{kerr2026hamon,
|
|
206
|
+
author = {Kerr, Douglas E. Jr.},
|
|
207
|
+
title = {Hamon: JAX-Native Thermal Sampling for Discrete Energy-Based Models},
|
|
208
|
+
year = {2026},
|
|
209
|
+
url = {https://github.com/dek3rr/hamon},
|
|
210
|
+
version = {0.1.0},
|
|
211
|
+
license = {Apache-2.0},
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Hamon's block sampling and PGM infrastructure is derived from
|
|
216
|
+
[thrml](https://github.com/Extropic-AI/thrml) (v0.1.3) by
|
|
217
|
+
[Extropic AI](https://extropic.ai), licensed under Apache 2.0.
|
|
218
|
+
See [NOTICE](NOTICE) for full attribution. If you use the underlying
|
|
219
|
+
block Gibbs framework, please also cite:
|
|
220
|
+
|
|
221
|
+
```bibtex
|
|
222
|
+
@misc{jelincic2025efficient,
|
|
223
|
+
title = {An efficient probabilistic hardware architecture for diffusion-like models},
|
|
224
|
+
author = {Andraž Jelinčič and Owen Lockwood and Akhil Garlapati and Guillaume Verdon and Trevor McCourt},
|
|
225
|
+
year = {2025},
|
|
226
|
+
eprint = {2510.23972},
|
|
227
|
+
archivePrefix= {arXiv},
|
|
228
|
+
primaryClass = {cs.LG},
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
The non-reversible parallel tempering implementation is based on:
|
|
233
|
+
|
|
234
|
+
> Syed, S., Bouchard-Côté, A., Deligiannidis, G., & Doucet, A. (2021).
|
|
235
|
+
> Non-Reversible Parallel Tempering: a Scalable Highly Parallel MCMC Scheme.
|
|
236
|
+
> [arXiv:1905.02939](https://arxiv.org/abs/1905.02939)
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
Apache 2.0. See [LICENSE](LICENSE).
|
hamon-0.1.0/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<h1 align="center">Hamon</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
JAX-native thermal sampling for discrete energy-based models.
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/hamon"><img src="https://img.shields.io/pypi/v/hamon" alt="PyPI"></a>
|
|
9
|
+
<a href="https://pypi.org/project/hamon"><img src="https://img.shields.io/pypi/pyversions/hamon" alt="Python"></a>
|
|
10
|
+
<a href="https://github.com/dek3rr/hamon/blob/main/LICENSE"><img src="https://img.shields.io/github/license/dek3rr/hamon" alt="License"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Hamon is a JAX library for sampling from discrete probabilistic graphical models.
|
|
16
|
+
It provides GPU-accelerated block Gibbs sampling, non-reversible parallel tempering
|
|
17
|
+
with adaptive schedule optimization, and tools for building and training Ising models,
|
|
18
|
+
RBMs, and other discrete energy-based models.
|
|
19
|
+
|
|
20
|
+
Built on [Extropic AI's thrml](https://github.com/Extropic-AI/thrml) foundation,
|
|
21
|
+
Hamon diverges as an independent library with original algorithmic contributions
|
|
22
|
+
and performance optimizations.
|
|
23
|
+
|
|
24
|
+
## Why "Hamon"?
|
|
25
|
+
|
|
26
|
+
In Japanese swordsmithing, the *hamon* (刃文, "blade pattern") is the visible
|
|
27
|
+
wave that appears along the edge of a katana after differential hardening. The
|
|
28
|
+
smith coats the blade in clay — thin along the cutting edge, thick along the
|
|
29
|
+
spine — then heats the steel to critical temperature and quenches it in water.
|
|
30
|
+
The edge cools fast into hard martensite; the spine cools slowly into tough
|
|
31
|
+
pearlite. The boundary between these two phases is the hamon: a pattern born
|
|
32
|
+
entirely from a thermal process, where controlled temperature gradients reveal
|
|
33
|
+
structure hidden in disordered steel.
|
|
34
|
+
|
|
35
|
+
The parallel to this library is direct. Hamon explores discrete energy
|
|
36
|
+
landscapes by running chains at different temperatures and exchanging
|
|
37
|
+
information across the thermal gradient. Structure emerges at the boundary
|
|
38
|
+
between mixing regimes — hot chains explore freely, cold chains resolve fine
|
|
39
|
+
detail, and the communication between them is what makes sampling work. The
|
|
40
|
+
hamon on a blade is proof that a thermal process found the right boundary.
|
|
41
|
+
The diagnostics in this library measure the same thing.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install hamon
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For development:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
git clone https://github.com/dek3rr/hamon.git
|
|
53
|
+
cd hamon
|
|
54
|
+
pip install -e ".[development,testing,examples]"
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Requires Python ≥ 3.10 and a JAX installation ([GPU setup guide](https://jax.readthedocs.io/en/latest/installation.html)).
|
|
58
|
+
|
|
59
|
+
## Quick example
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import jax
|
|
63
|
+
import jax.numpy as jnp
|
|
64
|
+
from hamon import SpinNode, Block, SamplingSchedule, sample_states
|
|
65
|
+
from hamon.models import IsingEBM, IsingSamplingProgram, hinton_init
|
|
66
|
+
|
|
67
|
+
nodes = [SpinNode() for _ in range(5)]
|
|
68
|
+
edges = [(nodes[i], nodes[i + 1]) for i in range(4)]
|
|
69
|
+
model = IsingEBM(nodes, edges, jnp.zeros(5), jnp.ones(4) * 0.5, jnp.array(1.0))
|
|
70
|
+
|
|
71
|
+
free_blocks = [Block(nodes[::2]), Block(nodes[1::2])]
|
|
72
|
+
program = IsingSamplingProgram(model, free_blocks, clamped_blocks=[])
|
|
73
|
+
|
|
74
|
+
key = jax.random.key(0)
|
|
75
|
+
k_init, k_samp = jax.random.split(key, 2)
|
|
76
|
+
init_state = hinton_init(k_init, model, free_blocks, ())
|
|
77
|
+
schedule = SamplingSchedule(n_warmup=100, n_samples=1000, steps_per_sample=2)
|
|
78
|
+
|
|
79
|
+
samples = sample_states(k_samp, program, schedule, init_state, [], [Block(nodes)])
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Non-reversible parallel tempering
|
|
83
|
+
|
|
84
|
+
Hamon implements adaptive NRPT based on
|
|
85
|
+
[Syed et al. (2021)](https://arxiv.org/abs/1905.02939), with vectorized swaps
|
|
86
|
+
that exploit the temperature-linearity of Ising energies:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from hamon.nrpt import nrpt_adaptive
|
|
90
|
+
|
|
91
|
+
def ebm_factory(betas):
|
|
92
|
+
return [IsingEBM(nodes, edges, biases, weights, jnp.array(float(b))) for b in betas]
|
|
93
|
+
|
|
94
|
+
def program_factory(ebms):
|
|
95
|
+
return [IsingSamplingProgram(e, free_blocks, []) for e in ebms]
|
|
96
|
+
|
|
97
|
+
states, _, stats = nrpt_adaptive(
|
|
98
|
+
jax.random.key(42),
|
|
99
|
+
ebm_factory,
|
|
100
|
+
program_factory,
|
|
101
|
+
init_states=[init_state] * 8,
|
|
102
|
+
clamp_state=[],
|
|
103
|
+
n_rounds=500,
|
|
104
|
+
gibbs_steps_per_round=5,
|
|
105
|
+
initial_betas=jnp.linspace(0.1, 2.0, 8),
|
|
106
|
+
n_tune=5,
|
|
107
|
+
rounds_per_tune=200,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
print(f"Final Λ: {stats['round_trip_diagnostics']['Lambda']:.3f}")
|
|
111
|
+
print(f"Round trip rate: {stats['round_trip_diagnostics']['tau_observed']:.4f}")
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Key features of the NRPT implementation:
|
|
115
|
+
|
|
116
|
+
- **Vectorized swaps**: 1 energy evaluation per chain (not 4 per pair), all
|
|
117
|
+
non-overlapping swaps execute simultaneously via permutation indexing
|
|
118
|
+
- **Adaptive scheduling**: iteratively tunes β spacing to equalize rejection
|
|
119
|
+
rates, minimizing the global communication barrier Λ
|
|
120
|
+
- **Round trip tracking**: monitors the index process per machine, estimates
|
|
121
|
+
Λ and predicted optimal rate τ̄ = 1/(2+2Λ)
|
|
122
|
+
- **Chain count discovery**: iteratively probes to find the right number of
|
|
123
|
+
chains for a target acceptance rate
|
|
124
|
+
|
|
125
|
+
## What makes Hamon fast
|
|
126
|
+
|
|
127
|
+
**All chains run in one kernel.** Parallel tempering uses `jax.vmap` over chains
|
|
128
|
+
instead of a Python loop. Compile time is constant regardless of chain count.
|
|
129
|
+
|
|
130
|
+
**No redundant work in the sampler loop.** Global state is threaded through
|
|
131
|
+
`lax.scan` as a carry. Block updates use targeted scatters instead of rebuilding
|
|
132
|
+
the full state tensor each iteration.
|
|
133
|
+
|
|
134
|
+
**Energy evaluation skips unnecessary work.** Pre-built `BlockSpec` objects are
|
|
135
|
+
passed through directly — no reconstruction on every `energy()` call.
|
|
136
|
+
|
|
137
|
+
**Accumulator dtypes are explicit.** The moment accumulator pins its dtype at
|
|
138
|
+
construction, avoiding silent float64 promotion on GPU.
|
|
139
|
+
|
|
140
|
+
## Citing Hamon
|
|
141
|
+
|
|
142
|
+
If you use Hamon in your research, please cite:
|
|
143
|
+
|
|
144
|
+
```bibtex
|
|
145
|
+
@software{kerr2026hamon,
|
|
146
|
+
author = {Kerr, Douglas E. Jr.},
|
|
147
|
+
title = {Hamon: JAX-Native Thermal Sampling for Discrete Energy-Based Models},
|
|
148
|
+
year = {2026},
|
|
149
|
+
url = {https://github.com/dek3rr/hamon},
|
|
150
|
+
version = {0.1.0},
|
|
151
|
+
license = {Apache-2.0},
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Hamon's block sampling and PGM infrastructure is derived from
|
|
156
|
+
[thrml](https://github.com/Extropic-AI/thrml) (v0.1.3) by
|
|
157
|
+
[Extropic AI](https://extropic.ai), licensed under Apache 2.0.
|
|
158
|
+
See [NOTICE](NOTICE) for full attribution. If you use the underlying
|
|
159
|
+
block Gibbs framework, please also cite:
|
|
160
|
+
|
|
161
|
+
```bibtex
|
|
162
|
+
@misc{jelincic2025efficient,
|
|
163
|
+
title = {An efficient probabilistic hardware architecture for diffusion-like models},
|
|
164
|
+
author = {Andraž Jelinčič and Owen Lockwood and Akhil Garlapati and Guillaume Verdon and Trevor McCourt},
|
|
165
|
+
year = {2025},
|
|
166
|
+
eprint = {2510.23972},
|
|
167
|
+
archivePrefix= {arXiv},
|
|
168
|
+
primaryClass = {cs.LG},
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The non-reversible parallel tempering implementation is based on:
|
|
173
|
+
|
|
174
|
+
> Syed, S., Bouchard-Côté, A., Deligiannidis, G., & Doucet, A. (2021).
|
|
175
|
+
> Non-Reversible Parallel Tempering: a Scalable Highly Parallel MCMC Scheme.
|
|
176
|
+
> [arXiv:1905.02939](https://arxiv.org/abs/1905.02939)
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
Apache 2.0. See [LICENSE](LICENSE).
|