flashdiffusion 0.2.1__tar.gz → 0.2.2__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 (28) hide show
  1. {flashdiffusion-0.2.1/src/flashdiffusion.egg-info → flashdiffusion-0.2.2}/PKG-INFO +1 -1
  2. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/pyproject.toml +4 -3
  3. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2/src/flashdiffusion.egg-info}/PKG-INFO +1 -1
  4. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion.egg-info/SOURCES.txt +7 -1
  5. flashdiffusion-0.2.2/src/manifolds/__init__.py +5 -0
  6. flashdiffusion-0.2.2/src/manifolds/manifold_demo.py +256 -0
  7. flashdiffusion-0.2.2/src/manifolds/manifolds.py +1524 -0
  8. flashdiffusion-0.2.2/src/manifolds/quintic.py +627 -0
  9. flashdiffusion-0.2.2/src/manifolds/scoring.py +145 -0
  10. flashdiffusion-0.2.2/src/manifolds/spectra.py +540 -0
  11. flashdiffusion-0.2.2/src/manifolds/spectral_api.py +98 -0
  12. flashdiffusion-0.2.1/src/flashdiffusion/heuristics.py +0 -88
  13. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/LICENSE +0 -0
  14. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/README.md +0 -0
  15. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/setup.cfg +0 -0
  16. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion/__init__.py +0 -0
  17. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion/bandwidth.py +0 -0
  18. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion/dense.py +0 -0
  19. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion/energy.py +0 -0
  20. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion/flashdiffusion.py +0 -0
  21. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion/knn.py +0 -0
  22. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion/mfstar.py +0 -0
  23. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion/spectral.py +0 -0
  24. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion.egg-info/dependency_links.txt +0 -0
  25. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion.egg-info/requires.txt +0 -0
  26. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/src/flashdiffusion.egg-info/top_level.txt +0 -0
  27. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/tests/test_bandwidth.py +0 -0
  28. {flashdiffusion-0.2.1 → flashdiffusion-0.2.2}/tests/test_simple.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flashdiffusion
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Matrix-free bandwidth optimization and diffusion geometry on the GPU
5
5
  Author: Sparse Trace LLC
6
6
  License: MIT
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "flashdiffusion"
8
- version = "0.2.1"
8
+ version = "0.2.2"
9
9
  description = "Matrix-free bandwidth optimization and diffusion geometry on the GPU"
10
10
  readme = "README.md"
11
11
  requires-python = ">=3.11,<3.14"
@@ -41,8 +41,9 @@ examples = ["matplotlib"]
41
41
  Repository = "https://github.com/sparsetrace/FlashDiffusion"
42
42
 
43
43
  [tool.setuptools]
44
- package-dir = {"" = "src"}
45
- packages = ["flashdiffusion"]
44
+ # src/manifolds/ ships inside the wheel as flashdiffusion.manifolds; the folder stays where it is.
45
+ package-dir = {"" = "src", "flashdiffusion.manifolds" = "src/manifolds"}
46
+ packages = ["flashdiffusion", "flashdiffusion.manifolds"]
46
47
 
47
48
  [tool.pytest.ini_options]
48
49
  testpaths = ["tests"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flashdiffusion
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Matrix-free bandwidth optimization and diffusion geometry on the GPU
5
5
  Author: Sparse Trace LLC
6
6
  License: MIT
@@ -6,7 +6,6 @@ src/flashdiffusion/bandwidth.py
6
6
  src/flashdiffusion/dense.py
7
7
  src/flashdiffusion/energy.py
8
8
  src/flashdiffusion/flashdiffusion.py
9
- src/flashdiffusion/heuristics.py
10
9
  src/flashdiffusion/knn.py
11
10
  src/flashdiffusion/mfstar.py
12
11
  src/flashdiffusion/spectral.py
@@ -15,5 +14,12 @@ src/flashdiffusion.egg-info/SOURCES.txt
15
14
  src/flashdiffusion.egg-info/dependency_links.txt
16
15
  src/flashdiffusion.egg-info/requires.txt
17
16
  src/flashdiffusion.egg-info/top_level.txt
17
+ src/manifolds/__init__.py
18
+ src/manifolds/manifold_demo.py
19
+ src/manifolds/manifolds.py
20
+ src/manifolds/quintic.py
21
+ src/manifolds/scoring.py
22
+ src/manifolds/spectra.py
23
+ src/manifolds/spectral_api.py
18
24
  tests/test_bandwidth.py
19
25
  tests/test_simple.py
@@ -0,0 +1,5 @@
1
+ # src/manifolds/__init__.py
2
+ """Synthetic manifolds, exact Laplace–Beltrami spectra, and scoring."""
3
+ from .manifolds import ManifoldSample, Sphere, SwissRoll, SCurve, Torus
4
+
5
+ __all__ = ['ManifoldSample', 'Sphere', 'SwissRoll', 'SCurve', 'Torus']
@@ -0,0 +1,256 @@
1
+ """Generate all SwissRoll, Sphere, SCurve and Torus demo figures.
2
+
3
+ Run from the folder containing ``manifolds.py``:
4
+
5
+ python manifold_demo.py
6
+ python manifold_demo.py --output-dir ./figures --n 1800 --dpi 160
7
+ python manifold_demo.py --only torus
8
+
9
+ Figures are saved to the *current working directory* by default (or to
10
+ --output-dir), rather than to a hard-coded notebook or /mnt/data path.
11
+
12
+ Requires numpy, scipy and matplotlib. Uses Agg backend; no GUI required.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import argparse
18
+ from pathlib import Path
19
+
20
+ import matplotlib
21
+ matplotlib.use('Agg')
22
+ import matplotlib.pyplot as plt
23
+ import numpy as np
24
+
25
+ from manifolds import SwissRoll, SCurve, Sphere, Torus
26
+
27
+
28
+ def _save(fig, name: str, folder: Path, dpi: int):
29
+ path = folder / name
30
+ fig.savefig(path, dpi=dpi, bbox_inches='tight')
31
+ plt.close(fig)
32
+ print(f'Saved {path}')
33
+
34
+
35
+ def _set_equal_3d(ax, xyz):
36
+ """Fit a 3D scatter without distorting Euclidean aspect ratios."""
37
+ lo, hi = np.min(xyz, axis=0), np.max(xyz, axis=0)
38
+ middle = .5*(lo+hi)
39
+ half = .55*np.max(hi-lo)
40
+ if half == 0:
41
+ half = 1.
42
+ ax.set_xlim(middle[0]-half, middle[0]+half)
43
+ ax.set_ylim(middle[1]-half, middle[1]+half)
44
+ ax.set_zlim(middle[2]-half, middle[2]+half)
45
+ ax.set_box_aspect((1, 1, 1))
46
+
47
+
48
+ def demo_swiss_sampling(folder, n, dpi):
49
+ swiss = SwissRoll([10., 18.])
50
+ levels = (0., .02, .1, .7, np.inf)
51
+ fig = plt.figure(figsize=(17, 7.5), layout='constrained')
52
+ gs = fig.add_gridspec(2, 5, height_ratios=(1, .85))
53
+ ax_rdf = fig.add_subplot(gs[1, :])
54
+ for j, T in enumerate(levels):
55
+ sample = swiss.sample(n, seed=777, temperature=T)
56
+ U = sample.latent_base
57
+ ax = fig.add_subplot(gs[0, j])
58
+ ax.scatter(U[:, 1], U[:, 0], s=3, c=U[:, 1], cmap='viridis', linewidths=0)
59
+ ax.set_aspect('equal')
60
+ ax.set(xlim=(0, swiss.width), ylim=(0, swiss.height), xlabel='arc length s')
61
+ if j == 0:
62
+ ax.set_ylabel('height h')
63
+ ax.set_title('T = ∞ (uniform)' if np.isinf(T) else f'T = {T:g}')
64
+ radii, g = swiss.radial_distribution(U, bins=75, r_max=1.7)
65
+ ax_rdf.plot(radii, g, label=('T = ∞' if np.isinf(T) else f'T = {T:g}'))
66
+ ax_rdf.axhline(1., lw=1, ls='--', c='gray')
67
+ ax_rdf.set(xlabel='intrinsic separation', ylabel='g(r)',
68
+ title='Exact finite-rectangle-corrected pair correlation', ylim=(0, 7))
69
+ ax_rdf.legend(ncol=5, fontsize=9)
70
+ fig.suptitle('Swiss roll: triangular reference → diffusive disorder → uniform sheet')
71
+ _save(fig, 'swiss_roll_sampling_temperature.png', folder, dpi)
72
+
73
+
74
+ def demo_swiss_dimensions(folder, n, dpi):
75
+ shapes = ((10., 6.), (10., 6., .1), (10., 6., .1, .001), (10., 6., 1.))
76
+ fig, axs = plt.subplots(2, 4, figsize=(15, 8.5), layout='constrained')
77
+ for j, shape in enumerate(shapes):
78
+ swiss = SwissRoll(shape)
79
+ for row, T in enumerate((0., np.inf)):
80
+ sample = swiss.sample(n, seed=777, temperature=T)
81
+ U = sample.latent_base
82
+ color = U[:, 2] if len(shape) > 2 else U[:, 1]
83
+ ax = axs[row, j]
84
+ ax.scatter(U[:, 1], U[:, 0], s=3, c=color, cmap='viridis', linewidths=0)
85
+ ax.set_aspect('equal')
86
+ ax.set(xlim=(0, shape[1]), ylim=(0, shape[0]), xlabel='s')
87
+ ax.set_title(f'{shape}\n' + ('T=0 crystal' if row == 0 else 'T=∞ uniform'))
88
+ if j == 0:
89
+ ax.set_ylabel('height h')
90
+ fig.suptitle('Swiss roll: extra intrinsic dimensions and crystal/random sampling')
91
+ _save(fig, 'swiss_roll_dimensions.png', folder, dpi)
92
+
93
+
94
+ def demo_scurve(folder, n, dpi):
95
+ scurve = SCurve([10., 6.])
96
+ fig = plt.figure(figsize=(14, 4.8), layout='constrained')
97
+ for j, T in enumerate((0., .07, np.inf)):
98
+ sample = scurve.sample(n, seed=777, temperature=T)
99
+ ax = fig.add_subplot(1, 3, j+1, projection='3d')
100
+ X = sample.ambient_clean
101
+ ax.scatter(*X.T, s=3, c=sample.latent[:, 1], cmap='viridis', alpha=.85)
102
+ _set_equal_3d(ax, X)
103
+ ax.set(xlabel='x', ylabel='h', zlabel='z',
104
+ title='T = ∞ (uniform)' if np.isinf(T) else f'T = {T:g}')
105
+ ax.view_init(elev=19, azim=-62)
106
+ fig.suptitle('Arc-length S-curve: same geometry, three sample distributions')
107
+ _save(fig, 'scurve_sampling.png', folder, dpi)
108
+
109
+
110
+ def demo_sphere(folder, n, dpi):
111
+ sphere = Sphere(d=2, radius=1.)
112
+ levels = (0., .08, .6, np.inf)
113
+ fig = plt.figure(figsize=(15, 8), layout='constrained')
114
+ for j, T in enumerate(levels):
115
+ sample = sphere.sample(n, seed=777, temperature=T)
116
+ X = sample.ambient_clean
117
+ ax = fig.add_subplot(2, 4, j+1, projection='3d')
118
+ ax.scatter(*X.T, s=3, c=sample.latent[:, 0], cmap='viridis', alpha=.85)
119
+ ax.set(xlim=(-1.04, 1.04), ylim=(-1.04, 1.04), zlim=(-1.04, 1.04))
120
+ ax.set_box_aspect((1, 1, 1))
121
+ ax.set(xticks=[], yticks=[], zticks=[])
122
+ ax.view_init(elev=22, azim=40)
123
+ ax.set_title('T = ∞ (Haar)' if np.isinf(T) else f'T = {T:g}')
124
+ r, g = sphere.radial_distribution(sample.latent_base, bins=70)
125
+ ax2 = fig.add_subplot(2, 4, j+5)
126
+ ax2.plot(r, g, lw=1.4)
127
+ ax2.axhline(1., lw=1, ls='--', c='gray')
128
+ ax2.set(xlabel='geodesic radius', ylim=(0, 3.5))
129
+ if j == 0:
130
+ ax2.set_ylabel('g(r), sphere')
131
+ ax2.grid(alpha=.2)
132
+ fig.suptitle('Sphere S²: Fibonacci reference → disorder → Haar sampling')
133
+ _save(fig, 'sphere_melting.png', folder, dpi)
134
+
135
+
136
+ def demo_torus(folder, n, dpi):
137
+ torus = Torus(major_radius=2., minor_radius=.65, measure='haar')
138
+ levels = (0., .004, .05, np.inf)
139
+ fig = plt.figure(figsize=(15, 8.2), layout='constrained')
140
+ for j, T in enumerate(levels):
141
+ sample = torus.sample(n, seed=777, temperature=T)
142
+ X = sample.ambient_clean
143
+ ax = fig.add_subplot(2, 4, j+1, projection='3d')
144
+ ax.scatter(*X.T, s=3, c=sample.latent[:, 0], cmap='viridis', alpha=.82)
145
+ _set_equal_3d(ax, X)
146
+ ax.set(xticks=[], yticks=[], zticks=[])
147
+ ax.view_init(elev=31, azim=-60)
148
+ ax.set_title('T = ∞ (Haar)' if np.isinf(T) else f'T = {T:g}')
149
+ ell = (np.prod(torus._period_lengths)/n)**.5
150
+ r, g = torus.radial_distribution(sample.latent_base, bins=70,
151
+ r_max=min(5.*ell, .49*min(torus._period_lengths)))
152
+ ax2 = fig.add_subplot(2, 4, j+5)
153
+ ax2.plot(r/ell, g, lw=1.4)
154
+ ax2.axhline(1., lw=1, ls='--', c='gray')
155
+ ax2.set(xlabel='periodic reference r / mean spacing', ylim=(0, 5))
156
+ if j == 0:
157
+ ax2.set_ylabel('g(r), flat reference')
158
+ ax2.grid(alpha=.2)
159
+ fig.suptitle('Ring torus T²: periodic crystal → wrapped Gaussian disorder → Haar')
160
+ _save(fig, 'torus_melting.png', folder, dpi)
161
+
162
+
163
+ def demo_torus_measure(folder, dpi):
164
+ """Show that Haar-uniform angles differ from uniform area on a ring."""
165
+ R, r = 2., .65
166
+ sample_size = 35000
167
+ fig, axes = plt.subplots(1, 2, figsize=(12, 4.1), layout='constrained')
168
+ theta = np.linspace(0, 2*np.pi, 500)
169
+ expected_haar = np.full_like(theta, 1/(2*np.pi))
170
+ expected_area = (R+r*np.cos(theta))/(2*np.pi*R)
171
+ for measure, ax in zip(('haar', 'area'), axes):
172
+ torus = Torus(major_radius=R, minor_radius=r, measure=measure)
173
+ U = torus.sample(sample_size, seed=777).latent_base
174
+ ax.hist(U[:, 0], bins=60, density=True, alpha=.65,
175
+ label=f'sampled {measure}')
176
+ ax.plot(theta, expected_haar, label='Haar density')
177
+ ax.plot(theta, expected_area, label='surface-area density')
178
+ ax.set(xlim=(0, 2*np.pi), xlabel='poloidal angle θ', ylabel='density',
179
+ title=('Uniform angular Haar' if measure == 'haar' else 'Uniform surface area'))
180
+ ax.legend(fontsize=9)
181
+ fig.suptitle('On a ring torus, Haar measure ≠ induced Riemannian area')
182
+ _save(fig, 'torus_haar_vs_area.png', folder, dpi)
183
+
184
+
185
+ def sanity_checks():
186
+ """Check the intended shape, inversion, repeatability, and metric contracts."""
187
+ for shape in ((10., 6.), (10., 6., .1), (10., 6., .1, .001)):
188
+ for geometry in ('tube', 'product'):
189
+ for Cls in (SwissRoll, SCurve):
190
+ obj = Cls(shape, geometry=geometry)
191
+ sample = obj.sample(120, seed=17, temperature=.09,
192
+ latent_noise=.0001, ambient_noise=.001)
193
+ assert sample.latent.shape == (120, len(shape))
194
+ assert sample.ambient.shape == (120, obj.ambient_dim)
195
+ np.testing.assert_allclose(obj.inverse(sample.ambient_clean),
196
+ sample.latent, atol=1.e-8, rtol=1.e-8)
197
+ for d in (1, 2, 3, 4):
198
+ obj = Sphere(d=d)
199
+ sample = obj.sample(100, seed=17, temperature=.1,
200
+ latent_noise=.001, tangent_noise=.003, ambient_noise=.01)
201
+ np.testing.assert_allclose(obj.embed(sample.latent), sample.ambient_clean,
202
+ atol=1.e-10)
203
+ np.testing.assert_allclose(obj.inverse(sample.ambient_clean), sample.latent,
204
+ atol=1.e-8)
205
+ toruses = (Torus(), Torus(measure='area'), Torus(geometry='product'),
206
+ Torus(d=3, extra_radii=(.3,)),
207
+ Torus(d=4, geometry='product', radii=(.7, 2., .4, .2)))
208
+ for obj in toruses:
209
+ for T in (0., .12, np.inf):
210
+ sample = obj.sample(200, seed=17, temperature=T,
211
+ latent_noise=.01, tangent_noise=.003, ambient_noise=.01)
212
+ assert sample.latent.shape == (200, obj.dim)
213
+ assert sample.ambient.shape == (200, obj.ambient_dim)
214
+ np.testing.assert_allclose(obj.embed(sample.latent), sample.ambient_clean,
215
+ atol=1.e-10)
216
+ err = np.angle(np.exp(1j*(obj.inverse(sample.ambient_clean)-sample.latent)))
217
+ assert np.max(np.abs(err)) < 1.e-10
218
+ if obj.geometry == 'product':
219
+ D = obj.geodesic_distances(sample.latent[:12])
220
+ np.testing.assert_allclose(D, D.T, atol=1.e-12)
221
+ np.testing.assert_allclose(np.diag(D), 0., atol=1.e-12)
222
+ print('All manifold round-trip, dimensionality, and noise tests passed.')
223
+
224
+
225
+ def main():
226
+ parser = argparse.ArgumentParser(description=__doc__)
227
+ parser.add_argument('--output-dir', type=Path, default=Path('.'),
228
+ help='directory for PNGs (default: current working directory)')
229
+ parser.add_argument('--n', type=int, default=1200,
230
+ help='number of points per plotted sample (default: 1200)')
231
+ parser.add_argument('--dpi', type=int, default=150)
232
+ parser.add_argument('--only', choices=('all','swiss','sphere','scurve','torus'),
233
+ default='all', help='only generate one manifold family')
234
+ parser.add_argument('--skip-checks', action='store_true')
235
+ args = parser.parse_args()
236
+ if args.n < 12 or args.dpi < 50:
237
+ parser.error('--n must be >=12 and --dpi must be >=50')
238
+ folder = args.output_dir.expanduser().resolve()
239
+ folder.mkdir(parents=True, exist_ok=True)
240
+ if not args.skip_checks:
241
+ sanity_checks()
242
+ if args.only in ('all', 'swiss'):
243
+ demo_swiss_sampling(folder, args.n, args.dpi)
244
+ demo_swiss_dimensions(folder, args.n, args.dpi)
245
+ if args.only in ('all', 'sphere'):
246
+ demo_sphere(folder, args.n, args.dpi)
247
+ if args.only in ('all', 'scurve'):
248
+ demo_scurve(folder, args.n, args.dpi)
249
+ if args.only in ('all', 'torus'):
250
+ demo_torus(folder, args.n, args.dpi)
251
+ demo_torus_measure(folder, args.dpi)
252
+ print('Done.')
253
+
254
+
255
+ if __name__ == '__main__':
256
+ main()