stringjax-tools 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,215 @@
1
+ Metadata-Version: 2.4
2
+ Name: stringjax-tools
3
+ Version: 0.1.0
4
+ Summary: Reusable JAX transform, vectorisation, cache, and pytree helpers for StringJAX packages.
5
+ Author-email: Andreas Schachner <as3475@cornell.edu>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/StringJAX/stringjax-tools
8
+ Project-URL: Issues, https://github.com/StringJAX/stringjax-tools/issues
9
+ Keywords: jax,vmap,jit,pytrees,automatic-vectorisation,scientific-computing
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: jax>=0.4.26
23
+ Requires-Dist: numpy>=1.24
24
+ Provides-Extra: dev
25
+ Requires-Dist: build; extra == "dev"
26
+ Requires-Dist: nbclient; extra == "dev"
27
+ Requires-Dist: nbformat; extra == "dev"
28
+ Requires-Dist: ipykernel; extra == "dev"
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Requires-Dist: twine; extra == "dev"
31
+ Provides-Extra: docs
32
+ Requires-Dist: matplotlib; extra == "docs"
33
+ Requires-Dist: myst-nb; extra == "docs"
34
+ Requires-Dist: roman; extra == "docs"
35
+ Requires-Dist: sphinx; extra == "docs"
36
+ Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
37
+ Requires-Dist: sphinx-book-theme; extra == "docs"
38
+ Requires-Dist: sphinx-copybutton; extra == "docs"
39
+ Requires-Dist: sphinx-design; extra == "docs"
40
+ Requires-Dist: sphinx-togglebutton; extra == "docs"
41
+ Requires-Dist: sphinxcontrib-mermaid; extra == "docs"
42
+ Dynamic: license-file
43
+
44
+ # StringJAX Tools
45
+
46
+ `stringjax_tools` is a small utility package for reusable JAX transform
47
+ patterns used across StringJAX projects. It currently focuses on:
48
+
49
+ - conservative rank-checked automatic vectorisation;
50
+ - manual cached `jax.jit(jax.vmap(...))` wrappers;
51
+ - small helpers for explicit static-argument JIT compilation;
52
+ - explicit JAX persistent-compilation-cache setup;
53
+ - configurable pytree registration for stateful model classes.
54
+
55
+ The package keeps reusable transformation and pytree machinery separate from
56
+ domain-specific StringJAX model code.
57
+
58
+ ## Installation
59
+
60
+ From this directory:
61
+
62
+ ```bash
63
+ pip install -e ".[dev,docs]"
64
+ ```
65
+
66
+ The intended published package name is:
67
+
68
+ ```bash
69
+ pip install stringjax-tools
70
+ ```
71
+
72
+ The Python import name is:
73
+
74
+ ```python
75
+ import stringjax_tools
76
+ ```
77
+
78
+ ## Documentation
79
+
80
+ The Sphinx documentation lives in `documentation/`:
81
+
82
+ ```bash
83
+ make -C documentation html
84
+ ```
85
+
86
+ For strict local validation:
87
+
88
+ ```bash
89
+ make -C documentation html SPHINXOPTS="-W -q"
90
+ ```
91
+
92
+ The feature notebooks are included under `documentation/source/notebooks/` and
93
+ are linked from the Sphinx tutorials page.
94
+
95
+ ## Automatic Vectorisation
96
+
97
+ Keep the single-sample function explicit, then wrap it at the boundary where
98
+ callers may pass either one sample or a paired leading-axis batch.
99
+
100
+ ```python
101
+ import jax.numpy as jnp
102
+ from stringjax_tools.auto_vectorise import auto_vmap
103
+
104
+
105
+ def observable_single(moduli, tau, fluxes, scale=1.0):
106
+ return scale * (jnp.sum(jnp.abs(moduli) ** 2) + tau + jnp.sum(fluxes**2))
107
+
108
+
109
+ observable = auto_vmap(moduli=1, tau=0, fluxes=1)(observable_single)
110
+ ```
111
+
112
+ With these declarations:
113
+
114
+ - `moduli` has sample rank `1`, so `(h,)` is one sample and `(N, h)` is a batch.
115
+ - `tau` has sample rank `0`, so `()` is one sample and `(N,)` is a batch.
116
+ - `fluxes` has sample rank `1`, so `(n,)` is one sample and `(N, n)` is a batch.
117
+
118
+ If several checked arguments are batched, all leading batch sizes must agree.
119
+ Checked arguments without a batch axis are broadcast with `in_axes=None`.
120
+
121
+ ## Exact Shape Validation
122
+
123
+ Ranks decide batching. Exact trailing dimensions are optional:
124
+
125
+ ```python
126
+ class Model:
127
+ def __init__(self, h12, n_fluxes):
128
+ self.h12 = h12
129
+ self.n_fluxes = n_fluxes
130
+
131
+ @auto_vmap(
132
+ sample_ranks={"moduli": 1, "fluxes": 1},
133
+ sample_shapes={
134
+ "moduli": "h12",
135
+ "fluxes": lambda bound: (2 * bound["self"].n_fluxes,),
136
+ },
137
+ validate_shapes=True,
138
+ )
139
+ def diagnostic(self, moduli, fluxes):
140
+ return jnp.sum(jnp.abs(moduli) ** 2) + 0.01 * jnp.sum(fluxes**2)
141
+ ```
142
+
143
+ String dimensions are resolved from a bound object, usually `self`. Derived
144
+ dimensions should be callables rather than expression strings.
145
+
146
+ ## Manual Transform Helpers
147
+
148
+ When a function already has a deliberate `in_axes` structure, use:
149
+
150
+ ```python
151
+ from stringjax_tools.vmap import vmapping_func_cached
152
+
153
+ batched = vmapping_func_cached(single_sample_function, in_axes=(0, None, 0))
154
+ ```
155
+
156
+ Static keyword configuration is snapshotted when the cached wrapper is built.
157
+ Prefer immutable configuration objects, such as tuples, for values that should
158
+ participate in wrapper caching.
159
+
160
+ For explicit static positional arguments:
161
+
162
+ ```python
163
+ from stringjax_tools.jit import jit_with_static_args
164
+
165
+ jit_f = jit_with_static_args(f, static_argnums=(2,))
166
+ ```
167
+
168
+ ## Pytree Policies
169
+
170
+ Each StringJAX package should define its own static and ignored attribute policy
171
+ locally. The tool package supplies only generic registration machinery.
172
+
173
+ ```python
174
+ from stringjax_tools.pytrees import PytreePolicy
175
+
176
+ PACKAGE_PYTREE_POLICY = PytreePolicy(
177
+ static_keys=("h11", "h12", "model_ID", "_user_Q"),
178
+ ignore_defaults={"_sampler": None, "_cache": dict},
179
+ )
180
+
181
+ PACKAGE_PYTREE_POLICY.register(MyModelClass)
182
+ ```
183
+
184
+ Semantic model state belongs in `static_keys` when it is hashable and immutable,
185
+ or in traced children when it is array-like. Ignored attributes should be
186
+ limited to recomputable caches, scratch state, and eager-only helpers. Since
187
+ JAX reconstruction bypasses `__init__`, ignored caches that may be read after a
188
+ round trip should be declared through `ignore_defaults`; callable defaults such
189
+ as `dict` are called for each reconstructed object. Do not ignore user-supplied
190
+ configuration such as physical bounds or tadpole values.
191
+ Static and ignored attribute names must be disjoint. Static values are
192
+ validated by default: they must be hashable and have scalar, self-equal
193
+ comparison semantics, so array-like and `NaN`-like values are rejected unless a
194
+ package deliberately opts out with `validate_static=False`.
195
+ Leave `validate_static=True` unless the consuming package deliberately stores
196
+ non-hashable metadata in JAX pytree auxiliary data.
197
+
198
+ ## Compilation Cache
199
+
200
+ `configure_compilation_cache(...)` is opt-in and has no import-time side
201
+ effects. Call it before the first JAX compilation in a process:
202
+
203
+ ```python
204
+ from stringjax_tools.cache import configure_compilation_cache
205
+
206
+ configure_compilation_cache(
207
+ cache_dir=".jax-cache",
208
+ max_size_bytes=10_000_000_000,
209
+ )
210
+ ```
211
+
212
+ ## License
213
+
214
+ StringJAX Tools is distributed under the GNU General Public License v3.0 or
215
+ later.
@@ -0,0 +1,14 @@
1
+ stringjax_tools/__init__.py,sha256=hbpBc5H2UdIcaH3t7YvLik4aksJ_itMUiPJ_zS10YMQ,2083
2
+ stringjax_tools/__main__.py,sha256=syzBGU0YdHoJywQKfq7GxSzvZgNAQ6mh-_bpaeeitp4,881
3
+ stringjax_tools/_utils.py,sha256=tZad_PGV7sSVtdgTSvNc3DrLIA6gPNp5w_4EGfvb51I,6580
4
+ stringjax_tools/auto_vectorise.py,sha256=dax2nXmmSIVR5G1tj_KBTCucx-8AYWPC2B86Z14jllg,20604
5
+ stringjax_tools/cache.py,sha256=4KvelK6c7jWzGiSubArIc0IC4P0fqEgy8KNPd72kpSA,3310
6
+ stringjax_tools/jit.py,sha256=u9umUF_31eHwEv7gYSC25pHrwHFBA4O9J4gBJb9vLgw,2613
7
+ stringjax_tools/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
8
+ stringjax_tools/pytrees.py,sha256=6wJXxGSBRRnHBfIGftK4XIa0CkntkLnukGl-KaWF7mU,11952
9
+ stringjax_tools/vmap.py,sha256=9VhmTaTNI0wRYfHAc53yrXwSnDeu0QqbHog9WVPUTpo,3539
10
+ stringjax_tools-0.1.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
11
+ stringjax_tools-0.1.0.dist-info/METADATA,sha256=eUldDTGx1fy7EGJV2j6DeOdapiQHUU0WxG71ifFOMi0,6914
12
+ stringjax_tools-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
13
+ stringjax_tools-0.1.0.dist-info/top_level.txt,sha256=i2zKBNLJ0IqvM1p9U77pcITsENj5peoTGYobjhiLLFo,16
14
+ stringjax_tools-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+