faster-diffbloch 0.1.7__tar.gz → 0.2.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 (19) hide show
  1. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/.gitignore +8 -0
  2. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/PKG-INFO +30 -1
  3. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/README.md +29 -0
  4. faster_diffbloch-0.2.0/hatch_build.py +26 -0
  5. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/pyproject.toml +6 -1
  6. faster_diffbloch-0.2.0/src/faster_diffbloch/cli.py +57 -0
  7. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/native/metal_batch_cgemm.m +1 -2
  8. faster_diffbloch-0.1.7/src/faster_diffbloch/cli.py +0 -21
  9. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/LICENSE +0 -0
  10. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/__init__.py +0 -0
  11. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/backend.py +0 -0
  12. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/builder.py +0 -0
  13. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/native/batch_cgemm.c +0 -0
  14. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/native/batch_cgemm.h +0 -0
  15. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/native/batch_cgemm.metal +0 -0
  16. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/native/bridge_lib.c +0 -0
  17. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/native/native_scattering.c +0 -0
  18. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/native/native_scattering.h +0 -0
  19. {faster_diffbloch-0.1.7 → faster_diffbloch-0.2.0}/src/faster_diffbloch/scattering.py +0 -0
@@ -22,3 +22,11 @@ bench/build/
22
22
  *.metallib
23
23
  *.dylib
24
24
  *.so
25
+
26
+ # Flow build outputs.
27
+ build/
28
+ flow/.flow_cache/
29
+
30
+ # Staged by packages/faster-diffbloch/build_exact.sh; built files.
31
+ packages/faster-diffbloch/src/faster_diffbloch/exact/
32
+ packages/faster-diffbloch/dist/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: faster-diffbloch
3
- Version: 0.1.7
3
+ Version: 0.2.0
4
4
  Summary: Drop-in Metal GPU (macOS) and optimized CPU (macOS/Linux) acceleration for diffBloch
5
5
  Project-URL: Homepage, https://godofecht.github.io/diffFlow/
6
6
  Project-URL: Documentation, https://godofecht.github.io/diffFlow/
@@ -162,3 +162,32 @@ faster_diffbloch.enable(device="cpu")
162
162
  import diffBloch
163
163
  # All propagate and matrix_exp calls now route through faster-diffBloch
164
164
  ```
165
+
166
+ ### 3. Exact refinement (macOS Apple Silicon)
167
+
168
+ `refine --exact` runs diffBloch's refinement with its optimizer loop compiled from Flow.
169
+ Its output matches `diffbloch refine` in every bit: the loss, every parameter and every
170
+ gradient at every step, and the console line for line. The macOS arm64 wheel ships the prebuilt binary, so nothing is compiled on install.
171
+
172
+ ```bash
173
+ pip install faster-diffbloch "torch==2.14.*" \
174
+ "diffBloch @ git+https://github.com/Differentiable-Electron-Crystallography/diffBloch@12913566c7598f975b0529d0b2f11bc862dbffbc"
175
+ faster-diffbloch refine --exact path/to/experiment
176
+ ```
177
+
178
+ The bits were checked against that diffBloch commit on an M4 Max under macOS 26: torch
179
+ 2.14.0 for the table below, and torch 2.14.1 from a clean install of this wheel on both
180
+ quartz experiments. Another torch prints a warning, since its kernels round differently.
181
+ The diffBloch on PyPI (0.2.0rc1) is an older snapshot with a different refinement loop.
182
+ diffBloch writes its visualization notebook only from a source checkout, so an installed
183
+ diffBloch prints one line fewer, under `diffbloch refine` and `refine --exact` alike.
184
+
185
+ | Experiment (Colmey et al. 2026) | Steps compared | Result |
186
+ |---|---|---|
187
+ | quartz-absorption | 40 | every step bit-equal, console identical |
188
+ | quartz-no-abs | 40 | every step bit-equal, console identical |
189
+ | cspbbr3-absorption | 40 | every step bit-equal |
190
+
191
+ CsPbBr3 takes 6.3 h for 40 steps and peaks at 5.6 GB, against 12.8 h and 15.3 GB for
192
+ diffBloch on the CPU. `DIFFFLOW_THREADS` sets the worker threads, default 8; the count
193
+ cannot change a bit.
@@ -129,3 +129,32 @@ faster_diffbloch.enable(device="cpu")
129
129
  import diffBloch
130
130
  # All propagate and matrix_exp calls now route through faster-diffBloch
131
131
  ```
132
+
133
+ ### 3. Exact refinement (macOS Apple Silicon)
134
+
135
+ `refine --exact` runs diffBloch's refinement with its optimizer loop compiled from Flow.
136
+ Its output matches `diffbloch refine` in every bit: the loss, every parameter and every
137
+ gradient at every step, and the console line for line. The macOS arm64 wheel ships the prebuilt binary, so nothing is compiled on install.
138
+
139
+ ```bash
140
+ pip install faster-diffbloch "torch==2.14.*" \
141
+ "diffBloch @ git+https://github.com/Differentiable-Electron-Crystallography/diffBloch@12913566c7598f975b0529d0b2f11bc862dbffbc"
142
+ faster-diffbloch refine --exact path/to/experiment
143
+ ```
144
+
145
+ The bits were checked against that diffBloch commit on an M4 Max under macOS 26: torch
146
+ 2.14.0 for the table below, and torch 2.14.1 from a clean install of this wheel on both
147
+ quartz experiments. Another torch prints a warning, since its kernels round differently.
148
+ The diffBloch on PyPI (0.2.0rc1) is an older snapshot with a different refinement loop.
149
+ diffBloch writes its visualization notebook only from a source checkout, so an installed
150
+ diffBloch prints one line fewer, under `diffbloch refine` and `refine --exact` alike.
151
+
152
+ | Experiment (Colmey et al. 2026) | Steps compared | Result |
153
+ |---|---|---|
154
+ | quartz-absorption | 40 | every step bit-equal, console identical |
155
+ | quartz-no-abs | 40 | every step bit-equal, console identical |
156
+ | cspbbr3-absorption | 40 | every step bit-equal |
157
+
158
+ CsPbBr3 takes 6.3 h for 40 steps and peaks at 5.6 GB, against 12.8 h and 15.3 GB for
159
+ diffBloch on the CPU. `DIFFFLOW_THREADS` sets the worker threads, default 8; the count
160
+ cannot change a bit.
@@ -0,0 +1,26 @@
1
+ """Tag the wheel for macOS arm64 when build_exact.sh has staged the Flow binary.
2
+
3
+ Without src/faster_diffbloch/exact/_bin the wheel stays pure (py3-none-any), as before.
4
+ """
5
+
6
+ from pathlib import Path
7
+
8
+ from hatchling.builders.hooks.plugin.interface import BuildHookInterface
9
+
10
+ EXACT_BIN = Path(__file__).parent / "src" / "faster_diffbloch" / "exact" / "_bin"
11
+ EXACT_TAG = "py3-none-macosx_14_0_arm64"
12
+
13
+
14
+ class CustomBuildHook(BuildHookInterface):
15
+ def initialize(self, version, build_data):
16
+ if self.target_name != "wheel":
17
+ return
18
+ if (EXACT_BIN / "experiment_c").exists():
19
+ build_data["pure_python"] = False
20
+ build_data["tag"] = EXACT_TAG
21
+ # The staged tree is git-ignored, so name every file rather than rely on file selection.
22
+ exact = EXACT_BIN.parent
23
+ for path in sorted(exact.rglob("*")):
24
+ if path.is_file() and "__pycache__" not in path.parts:
25
+ rel = path.relative_to(exact.parent.parent) # faster_diffbloch/exact/...
26
+ build_data["force_include"][str(path)] = str(rel)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "faster-diffbloch"
7
- version = "0.1.7"
7
+ version = "0.2.0"
8
8
  description = "Drop-in Metal GPU (macOS) and optimized CPU (macOS/Linux) acceleration for diffBloch"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -52,9 +52,14 @@ piwheels = "https://www.piwheels.org/project/faster-diffbloch/"
52
52
  [tool.hatch.build.targets.wheel]
53
53
  packages = ["src/faster_diffbloch"]
54
54
 
55
+ # build_exact.sh stages faster_diffbloch.exact; the hook then tags that wheel macOS arm64.
56
+ [tool.hatch.build.hooks.custom]
57
+
55
58
  [tool.hatch.build.targets.sdist]
56
59
  include = [
57
60
  "src/faster_diffbloch",
61
+ "hatch_build.py",
58
62
  "README.md",
59
63
  "LICENSE",
60
64
  ]
65
+ exclude = ["src/faster_diffbloch/exact"]
@@ -0,0 +1,57 @@
1
+ """CLI wrapper enabling faster-diffbloch before running diffbloch commands.
2
+
3
+ faster-diffbloch <diffbloch command ...> Metal GPU acceleration, then diffBloch
4
+ faster-diffbloch refine --exact <experiment> diffBloch's refinement run in Flow,
5
+ bit for bit with `diffbloch refine`
6
+
7
+ --exact needs the macOS arm64 wheel, which ships the prebuilt Flow binary.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import sys
13
+
14
+ # The versions --exact was checked against, bit for bit, on an M4 Max under macOS 26.
15
+ EXACT_TORCH = "2.14."
16
+ EXACT_DIFFBLOCH = ("https://github.com/Differentiable-Electron-Crystallography/diffBloch",
17
+ "1291356")
18
+
19
+
20
+ def _exact(argv: list[str]) -> int:
21
+ try:
22
+ from .exact.cli import main as exact_main
23
+ from .exact.toolchain import bundled_backends
24
+ except ImportError as err:
25
+ print(f"faster-diffbloch: --exact is not in this install ({err}).\n"
26
+ "It ships in the macOS arm64 wheel only.", file=sys.stderr)
27
+ return 1
28
+ if not bundled_backends():
29
+ print("faster-diffbloch: --exact needs the macOS arm64 wheel, which ships the Flow binary.",
30
+ file=sys.stderr)
31
+ return 1
32
+ import torch
33
+ if not torch.__version__.startswith(EXACT_TORCH):
34
+ print(f"faster-diffbloch: warning: --exact matches diffBloch bit for bit under torch "
35
+ f"{EXACT_TORCH}x; this is torch {torch.__version__}, so the last bits may differ.",
36
+ file=sys.stderr)
37
+ return exact_main(argv)
38
+
39
+
40
+ def main() -> None:
41
+ argv = sys.argv[1:]
42
+ if argv[:1] == ["refine"] and "--exact" in argv:
43
+ # Exact mode runs diffBloch untouched apart from its optimizer loop: no acceleration.
44
+ sys.exit(_exact([a for a in argv if a != "--exact"]))
45
+ # Enable Metal GPU acceleration by default
46
+ from .backend import enable
47
+ enable(device="gpu")
48
+ try:
49
+ from diffBloch.app.cli import main as diffbloch_main
50
+ diffbloch_main()
51
+ except ImportError:
52
+ print("Error: diffbloch is not installed. Install diffbloch or run 'pip install diffbloch'.", file=sys.stderr)
53
+ sys.exit(1)
54
+
55
+
56
+ if __name__ == "__main__":
57
+ main()
@@ -114,8 +114,7 @@ static NSString* get_metallib_path(void) {
114
114
  @"bench/build/batch_cgemm.metallib",
115
115
  @"src/batch_gemm/batch_cgemm.metallib",
116
116
  @"../bench/build/batch_cgemm.metallib",
117
- @"../../bench/build/batch_cgemm.metallib",
118
- @"/Users/abhishekshivakumar/diffFlow/bench/build/batch_cgemm.metallib"
117
+ @"../../bench/build/batch_cgemm.metallib"
119
118
  ];
120
119
  for (NSString* p in candidates) {
121
120
  if ([[NSFileManager defaultManager] fileExistsAtPath:p]) {
@@ -1,21 +0,0 @@
1
- """CLI wrapper enabling faster-diffbloch before running diffbloch commands."""
2
-
3
- from __future__ import annotations
4
-
5
- import sys
6
- from .backend import enable
7
-
8
-
9
- def main() -> None:
10
- # Enable Metal GPU acceleration by default
11
- enable(device="gpu")
12
- try:
13
- from diffBloch.app.cli import main as diffbloch_main
14
- diffbloch_main()
15
- except ImportError:
16
- print("Error: diffbloch is not installed. Install diffbloch or run 'pip install diffbloch'.", file=sys.stderr)
17
- sys.exit(1)
18
-
19
-
20
- if __name__ == "__main__":
21
- main()