diffct-mlx 1.0.2__tar.gz → 2.0.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 (130) hide show
  1. diffct_mlx-2.0.0/.github/workflows/docs.yml +37 -0
  2. diffct_mlx-2.0.0/.github/workflows/publish.yml +30 -0
  3. diffct_mlx-2.0.0/.github/workflows/release.yml +20 -0
  4. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/.gitignore +6 -16
  5. diffct_mlx-2.0.0/ATTRIBUTION.md +60 -0
  6. diffct_mlx-2.0.0/CHANGELOG.md +344 -0
  7. diffct_mlx-2.0.0/PKG-INFO +468 -0
  8. diffct_mlx-2.0.0/README.md +443 -0
  9. diffct_mlx-2.0.0/diffct/__init__.py +78 -0
  10. diffct_mlx-2.0.0/diffct/analytical.py +521 -0
  11. diffct_mlx-2.0.0/diffct/constants.py +66 -0
  12. diffct_mlx-2.0.0/diffct/differentiable.py +74 -0
  13. diffct_mlx-2.0.0/diffct/footprint.py +503 -0
  14. diffct_mlx-2.0.0/diffct/geometry.py +1004 -0
  15. diffct_mlx-2.0.0/diffct/kernels/__init__.py +35 -0
  16. diffct_mlx-2.0.0/diffct/kernels/cone_beam.py +577 -0
  17. diffct_mlx-2.0.0/diffct/kernels/cone_footprint.py +376 -0
  18. diffct_mlx-2.0.0/diffct/kernels/fan_beam.py +415 -0
  19. diffct_mlx-2.0.0/diffct/kernels/fan_footprint.py +187 -0
  20. diffct_mlx-2.0.0/diffct/kernels/parallel_beam.py +376 -0
  21. diffct_mlx-2.0.0/diffct/kernels/parallel_footprint.py +135 -0
  22. diffct_mlx-2.0.0/diffct/projectors.py +1087 -0
  23. diffct_mlx-2.0.0/diffct/utils.py +298 -0
  24. diffct_mlx-2.0.0/diffct_mlx/__init__.py +380 -0
  25. diffct_mlx-2.0.0/diffct_mlx/analytical.py +29 -0
  26. diffct_mlx-2.0.0/diffct_mlx/backend/__init__.py +70 -0
  27. diffct_mlx-2.0.0/diffct_mlx/backend/_mlx.py +141 -0
  28. diffct_mlx-2.0.0/diffct_mlx/backend/_torch.py +383 -0
  29. diffct_mlx-2.0.0/diffct_mlx/backend/metal/__init__.py +13 -0
  30. {diffct_mlx-1.0.2/diffct_mlx → diffct_mlx-2.0.0/diffct_mlx/backend/metal}/geometry.py +1 -1
  31. {diffct_mlx-1.0.2/diffct_mlx → diffct_mlx-2.0.0/diffct_mlx/backend/metal}/kernels/__init__.py +2 -0
  32. {diffct_mlx-1.0.2/diffct_mlx → diffct_mlx-2.0.0/diffct_mlx/backend/metal}/kernels/cone_beam.py +180 -77
  33. {diffct_mlx-1.0.2/diffct_mlx → diffct_mlx-2.0.0/diffct_mlx/backend/metal}/kernels/fan_beam.py +6 -43
  34. {diffct_mlx-1.0.2/diffct_mlx → diffct_mlx-2.0.0/diffct_mlx/backend/metal}/kernels/parallel_beam.py +6 -45
  35. {diffct_mlx-1.0.2/diffct_mlx → diffct_mlx-2.0.0/diffct_mlx/backend/metal}/projectors.py +87 -5
  36. diffct_mlx-2.0.0/diffct_mlx/calibration.py +127 -0
  37. diffct_mlx-2.0.0/diffct_mlx/filters.py +368 -0
  38. diffct_mlx-2.0.0/diffct_mlx/functionals.py +311 -0
  39. diffct_mlx-2.0.0/diffct_mlx/geometry.py +226 -0
  40. diffct_mlx-2.0.0/diffct_mlx/operators.py +461 -0
  41. diffct_mlx-2.0.0/diffct_mlx/orchestration/__init__.py +47 -0
  42. diffct_mlx-2.0.0/diffct_mlx/orchestration/out_of_core.py +1146 -0
  43. diffct_mlx-2.0.0/diffct_mlx/phantoms/__init__.py +12 -0
  44. diffct_mlx-2.0.0/diffct_mlx/phantoms/engine.py +201 -0
  45. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/phantoms/shepp_logan.py +6 -1
  46. diffct_mlx-2.0.0/diffct_mlx/physics/__init__.py +80 -0
  47. diffct_mlx-2.0.0/diffct_mlx/physics/corrections.py +174 -0
  48. diffct_mlx-2.0.0/diffct_mlx/physics/data/spectra.npz +0 -0
  49. diffct_mlx-2.0.0/diffct_mlx/physics/pipeline.py +137 -0
  50. diffct_mlx-2.0.0/diffct_mlx/physics/simulate.py +295 -0
  51. diffct_mlx-2.0.0/diffct_mlx/physics/spectra.py +149 -0
  52. diffct_mlx-2.0.0/diffct_mlx/projectors.py +84 -0
  53. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/real_measured_data_helper.py +17 -5
  54. diffct_mlx-2.0.0/diffct_mlx/rebinning.py +347 -0
  55. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/__init__.py +93 -27
  56. diffct_mlx-2.0.0/diffct_mlx/reconstruction_algorithms/_analytic.py +133 -0
  57. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/_core.py +263 -156
  58. diffct_mlx-2.0.0/diffct_mlx/reconstruction_algorithms/_solver.py +214 -0
  59. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/asd_pocs.py +10 -6
  60. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/awtv_pocs.py +14 -10
  61. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/cases.py +84 -64
  62. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/dart.py +28 -18
  63. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/fbp.py +1 -3
  64. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/fdk.py +1 -1
  65. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/sart.py +22 -19
  66. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/sirt.py +19 -15
  67. diffct_mlx-2.0.0/diffct_mlx/reconstruction_algorithms/solvers.py +404 -0
  68. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/reconstruction_algorithms/tv_pocs.py +10 -6
  69. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/regularizers.py +14 -11
  70. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/diffct_mlx/tv_gradients.py +13 -11
  71. diffct_mlx-2.0.0/docs/Makefile +20 -0
  72. diffct_mlx-2.0.0/docs/source/_static/.gitkeep +0 -0
  73. diffct_mlx-2.0.0/docs/source/api.rst +314 -0
  74. diffct_mlx-2.0.0/docs/source/conf.py +36 -0
  75. diffct_mlx-2.0.0/docs/source/examples.rst +30 -0
  76. diffct_mlx-2.0.0/docs/source/fbp_fan_example.rst +84 -0
  77. diffct_mlx-2.0.0/docs/source/fbp_parallel_example.rst +69 -0
  78. diffct_mlx-2.0.0/docs/source/fdk_cone_example.rst +99 -0
  79. diffct_mlx-2.0.0/docs/source/getting_started.rst +88 -0
  80. diffct_mlx-2.0.0/docs/source/index.rst +90 -0
  81. diffct_mlx-2.0.0/docs/source/iterative_reco_cone_example.rst +131 -0
  82. diffct_mlx-2.0.0/docs/source/iterative_reco_fan_example.rst +90 -0
  83. diffct_mlx-2.0.0/docs/source/iterative_reco_parallel_example.rst +96 -0
  84. diffct_mlx-2.0.0/examples/circular_trajectory/fbp_fan.py +291 -0
  85. diffct_mlx-2.0.0/examples/circular_trajectory/fbp_parallel.py +143 -0
  86. diffct_mlx-2.0.0/examples/circular_trajectory/fdk_cone.py +337 -0
  87. diffct_mlx-2.0.0/examples/circular_trajectory/iterative_reco_cone.py +183 -0
  88. diffct_mlx-2.0.0/examples/circular_trajectory/iterative_reco_fan.py +151 -0
  89. diffct_mlx-2.0.0/examples/circular_trajectory/iterative_reco_parallel.py +146 -0
  90. diffct_mlx-2.0.0/examples/non_circular_trajectory/iterative_reco_cone.py +313 -0
  91. diffct_mlx-2.0.0/examples/non_circular_trajectory/iterative_reco_fan.py +270 -0
  92. diffct_mlx-2.0.0/examples/non_circular_trajectory/iterative_reco_parallel.py +284 -0
  93. diffct_mlx-2.0.0/examples/plot_trajectory.py +326 -0
  94. diffct_mlx-2.0.0/pyproject.toml +47 -0
  95. diffct_mlx-2.0.0/pytest.ini +14 -0
  96. diffct_mlx-2.0.0/requirements.txt +9 -0
  97. diffct_mlx-2.0.0/tests/__init__.py +0 -0
  98. diffct_mlx-2.0.0/tests/_phantoms.py +77 -0
  99. diffct_mlx-2.0.0/tests/benchmarks/README.md +56 -0
  100. diffct_mlx-2.0.0/tests/benchmarks/__init__.py +0 -0
  101. diffct_mlx-2.0.0/tests/benchmarks/_common.py +57 -0
  102. diffct_mlx-2.0.0/tests/benchmarks/test_bench_cone.py +137 -0
  103. diffct_mlx-2.0.0/tests/benchmarks/test_bench_fan.py +121 -0
  104. diffct_mlx-2.0.0/tests/benchmarks/test_bench_parallel.py +113 -0
  105. diffct_mlx-2.0.0/tests/test_adjoint_inner_product.py +170 -0
  106. diffct_mlx-2.0.0/tests/test_cone_projector_autograd.py +76 -0
  107. diffct_mlx-2.0.0/tests/test_cuda_smoke.py +121 -0
  108. diffct_mlx-2.0.0/tests/test_diffct_mlx_extensions.py +296 -0
  109. diffct_mlx-2.0.0/tests/test_fbp_fan_accuracy.py +92 -0
  110. diffct_mlx-2.0.0/tests/test_fbp_fan_offsets.py +117 -0
  111. diffct_mlx-2.0.0/tests/test_fbp_parallel_accuracy.py +72 -0
  112. diffct_mlx-2.0.0/tests/test_fdk_cone_accuracy.py +114 -0
  113. diffct_mlx-2.0.0/tests/test_fdk_cone_offsets.py +118 -0
  114. diffct_mlx-2.0.0/tests/test_gradcheck.py +125 -0
  115. diffct_mlx-2.0.0/tests/test_known_operator_gradflow.py +367 -0
  116. diffct_mlx-2.0.0/tests/test_ramp_filter_windows.py +98 -0
  117. diffct_mlx-2.0.0/tests/test_regressions.py +333 -0
  118. diffct_mlx-2.0.0/tests/test_siddon_centering.py +127 -0
  119. diffct_mlx-2.0.0/tests/test_weights.py +126 -0
  120. diffct_mlx-2.0.0/tools/generate_spectra.py +92 -0
  121. diffct_mlx-1.0.2/PKG-INFO +0 -320
  122. diffct_mlx-1.0.2/README.md +0 -290
  123. diffct_mlx-1.0.2/diffct_mlx/__about__.py +0 -3
  124. diffct_mlx-1.0.2/diffct_mlx/__init__.py +0 -223
  125. diffct_mlx-1.0.2/diffct_mlx/phantoms/__init__.py +0 -5
  126. diffct_mlx-1.0.2/diffct_mlx/reconstruction_algorithms/_analytic.py +0 -101
  127. diffct_mlx-1.0.2/pyproject.toml +0 -61
  128. {diffct_mlx-1.0.2 → diffct_mlx-2.0.0}/LICENSE +0 -0
  129. {diffct_mlx-1.0.2/diffct_mlx → diffct_mlx-2.0.0/diffct_mlx/backend/metal}/constants.py +0 -0
  130. {diffct_mlx-1.0.2/diffct_mlx → diffct_mlx-2.0.0/diffct_mlx/backend/metal}/utils.py +0 -0
@@ -0,0 +1,37 @@
1
+ name: Deploy Documentation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main # Or your default branch
7
+
8
+ jobs:
9
+ build-and-deploy:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: '3.x'
21
+
22
+ - name: Install dependencies
23
+ run: |
24
+ pip install sphinx-rtd-theme
25
+ pip install sphinx
26
+ pip install -r requirements.txt
27
+
28
+ - name: Build documentation
29
+ run: |
30
+ cd docs
31
+ make html
32
+
33
+ - name: Deploy to GitHub Pages
34
+ uses: peaceiris/actions-gh-pages@v4
35
+ with:
36
+ github_token: ${{ secrets.GITHUB_TOKEN }}
37
+ publish_dir: docs/build/html
@@ -0,0 +1,30 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ publish:
10
+ name: Build and publish
11
+ runs-on: ubuntu-latest
12
+ environment: pypi
13
+ permissions:
14
+ id-token: write # OIDC for PyPI trusted publishing — no API token needed
15
+ steps:
16
+ - name: Checkout code
17
+ uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: '3.12'
23
+
24
+ - name: Build sdist and wheel
25
+ run: |
26
+ pip install build
27
+ python -m build
28
+
29
+ - name: Publish to PyPI
30
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,20 @@
1
+ name: Create Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ release:
10
+ name: Create Release
11
+ runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: write
14
+ steps:
15
+ - name: Checkout code
16
+ uses: actions/checkout@v4
17
+ - name: Create Release
18
+ uses: softprops/action-gh-release@v2
19
+ with:
20
+ generate_release_notes: true
@@ -3,23 +3,9 @@ __pycache__/
3
3
  *.py[cod]
4
4
  *$py.class
5
5
 
6
- # Data
7
- *.csv
8
- *.tif
9
- *.rek
10
- *.npy
11
- *.npz
12
-
13
- # macOS Finder metadata
14
- .DS_Store
15
- **/.DS_Store
16
-
17
6
  # C extensions
18
7
  *.so
19
8
 
20
- # Notes
21
- notes/
22
-
23
9
  # Distribution / packaging
24
10
  .Python
25
11
  build/
@@ -84,7 +70,6 @@ instance/
84
70
 
85
71
  # Sphinx documentation
86
72
  docs/_build/
87
- docs/build/
88
73
 
89
74
  # PyBuilder
90
75
  .pybuilder/
@@ -200,4 +185,9 @@ cython_debug/
200
185
  projectBrief.md
201
186
  .kiro
202
187
  .claude
203
- examples/non_circular_trajectory/sample_data/reko/sim_obj_1_diffct.npy
188
+
189
+ # local reference clone (LLNL LEAP), not part of this package
190
+ LEAP/
191
+
192
+ # macOS Finder metadata
193
+ .DS_Store
@@ -0,0 +1,60 @@
1
+ # Attribution
2
+
3
+ This `cuda` branch of **DiffCT-MLX** is **adapted from the original
4
+ [diffct](https://github.com/sypsyp97/diffct)** by Yipeng Sun et al.
5
+
6
+ ## Source
7
+
8
+ | | |
9
+ |---|---|
10
+ | **Upstream project** | [diffct](https://github.com/sypsyp97/diffct) |
11
+ | **Original author** | Yipeng Sun (<yipeng.sun@fau.de>) |
12
+ | **License** | Apache License 2.0 — see [LICENSE](LICENSE) |
13
+ | **Imported from** | upstream `dev` branch (arbitrary-trajectory line), v1.3.3.dev0, commit `cb516cf` |
14
+ | **Import date** | 2026-07-06 |
15
+ | **Maintained here by** | Linda-Sophie Schneider (<linda-sophie.schneider@fau.de>) |
16
+
17
+ The `dev` branch was chosen as the basis (rather than `main`) because its
18
+ module layout (`projectors`, `geometry`, `analytical`, `kernels`) and its
19
+ per-view projector convention (`src_pos, det_center, det_u_vec[, det_v_vec]`)
20
+ match the DiffCT-MLX port, enabling a shared public API across backends.
21
+
22
+ ## Relationship between branches
23
+
24
+ - **`main`** — the Apple Silicon / MLX port of diffct (this repository, DiffCT-MLX).
25
+ - **`cuda`** — a clean snapshot of the CUDA / PyTorch implementation from the
26
+ original diffct, being grown into an **auto-backend** package: it detects the
27
+ available backend at import (MLX on Apple Silicon, Torch/CUDA otherwise) and
28
+ dispatches to it, so the same user code runs unchanged on both platforms.
29
+
30
+ This mirrors the historical relationship in which diffct's former `apple`
31
+ branch became the standalone DiffCT-MLX repository.
32
+
33
+ ## Notice of changes (Apache-2.0 §4)
34
+
35
+ This branch is a modified redistribution of diffct. The initial commit is a
36
+ clean snapshot of diffct `dev` (`cb516cf`) taken on 2026-07-06, **without**
37
+ upstream commit history. All subsequent modifications — including the
38
+ auto-backend restructuring and the ported high-level reconstruction layer —
39
+ are tracked in this repository's git history.
40
+
41
+ - The original `LICENSE` (Apache License 2.0) is retained unchanged.
42
+ - Any third-party data attribution shipped with examples is preserved in the
43
+ corresponding `NOTICE` files.
44
+
45
+ ## Embedded spectrum data (XrayPhysics)
46
+
47
+ The physically-based example X-ray spectra and material attenuation curves in
48
+ `diffct_mlx/physics/data/spectra.npz` were **generated offline** with the
49
+ LLNL **[XrayPhysics](https://github.com/kylechampley/XrayPhysics)** library
50
+ (Kyle Champley, LLNL; **MIT License**), whose tube-spectrum model is validated
51
+ against TASMICS. XrayPhysics is used **only** as an offline reference to produce
52
+ this static data — it is **not** a runtime dependency and is not imported by the
53
+ package. The generator that reproduces the data is committed at
54
+ [`tools/generate_spectra.py`](tools/generate_spectra.py). If you rely on these
55
+ spectra quantitatively, please also credit XrayPhysics and TASMICS.
56
+
57
+ ## Citation
58
+
59
+ Please cite the original work. See the citation section of the
60
+ [README](README.md) for the BibTeX entry.
@@ -0,0 +1,344 @@
1
+ # Changelog
2
+
3
+ All notable changes to DiffCT-MLX are documented in this file. Entries up to
4
+ 1.3.0.dev0 track the vendored ``diffct`` dev line this repository was adapted
5
+ from; entries from 2.0.0.dev0 on track the unified ``diffct_mlx`` package.
6
+
7
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
8
+ and the project follows [Semantic Versioning](https://semver.org/).
9
+
10
+ ## [Unreleased]
11
+
12
+ ## [2.0.0] - 2026-07-10
13
+
14
+ First stable release of the unified package. Includes everything in
15
+ [2.0.0.dev0] below; on top of it, the MLX backend is now runtime-validated
16
+ on Apple Silicon (the last open item of the unification) and the Torch
17
+ backend gains trainable projector geometry.
18
+
19
+ ### Added
20
+
21
+ - **Trainable geometry on the Torch backend**: the Siddon projectors
22
+ (parallel/fan/cone) return finite-difference VJPs for their per-view
23
+ geometry arrays (`src_pos`, `det_center`/`det_origin`, `det_u_vec`,
24
+ `det_v_vec`, `ray_dir`) — computed only for inputs that `requires_grad`,
25
+ with magnitude-relative step sizes (mm- and m-scale setups both work).
26
+ Enables pose/trajectory optimization and geometry-aware known-operator
27
+ networks; verified by an exact matched-step contraction test and a
28
+ pose-recovery integration test. Footprint projectors remain data-only;
29
+ the FD gradients are smoothed subgradients (Siddon is piecewise-linear
30
+ in geometry) and not second-order differentiable.
31
+ - `power_iteration` re-exported at the top level; README documents the
32
+ bounded step-size parametrization for unrolled networks
33
+ (`(1.8/L)*sigmoid(theta)`).
34
+ - Known-operator gradient-flow guarantees: torch `xp.grad` is composable
35
+ (`create_graph` when the input carries gradients — unrolled TV steps are
36
+ second-order differentiable, mirroring `mx.grad`), correct under
37
+ `torch.no_grad()`; pinned by `tests/test_known_operator_gradflow.py`.
38
+
39
+ ### Fixed (MLX runtime validation on Apple Silicon, 2026-07-10)
40
+
41
+ - **Metal Siddon kernels aligned with the CUDA reference** (parallel, fan
42
+ and cone, forward *and* adjoint): the vendored kernels interpolated the
43
+ image/volume bi-/trilinearly on nodes at **integer** indices — voxel
44
+ centers live at `k + 0.5 - c`, so every Siddon projection was shifted by
45
+ half a voxel per axis against the footprint kernels, the FBP/FDK gathers
46
+ and the analytic phantom projector (view-dependent detector shifts up to
47
+ ±1.24 px at fan/cone magnification 1.75). They now accumulate the
48
+ traversed cell (`image[cell] * seg_len`), exactly like the CUDA kernels.
49
+ **Geometry-affecting** for MLX-Siddon users: results shift by half a
50
+ voxel relative to earlier MLX builds. Siddon-vs-footprint cone
51
+ correlation on a 64³ Shepp-Logan rises from 0.972 to 0.994, case-builder
52
+ FDK from 0.923 to 0.986.
53
+ - **Metal cone Siddon forward had a stray `voxel_spacing` factor** its
54
+ adjoint lacked, breaking the forward/adjoint pairing (and CUDA parity)
55
+ for `voxel_spacing != 1`.
56
+ - Regression-pinned in the backend-neutral `tests/test_siddon_centering.py`
57
+ (centered-object centroid probes, anisotropic-spacing adjoint,
58
+ Siddon-vs-footprint agreement), which runs on MLX and torch/CUDA alike.
59
+
60
+
61
+ ## [2.0.0.dev0] - 2026-07-10
62
+
63
+ The unified, auto-backend **`diffct_mlx`** package: one API that runs on
64
+ Torch/numba-CUDA (NVIDIA) and MLX/Metal (Apple Silicon), selected at import
65
+ (`DIFFCT_BACKEND` overrides).
66
+
67
+ ### Added
68
+
69
+ - **Unified API** with full parity to the Apple-Silicon `main` package:
70
+ functional projectors (Siddon + separable footprint, all geometries,
71
+ sparse cone backprojection), trajectory generators (+ laminography),
72
+ FBP/FDK, SART/SIRT/normalized-SART, TV-/ASD-/AwTV-POCS, DART, case
73
+ builders for simulated/measured/npy data, measured-data helpers.
74
+ - **Native CUDA footprint kernels** for parallel/fan/cone plus a sparse cone
75
+ footprint backprojection (`indices=` → 1D vector).
76
+ - **Operator/functional/solver framework**: differentiable `LinearOperator`
77
+ algebra with `ProjectionOperator.subset`, functionals
78
+ (L1/Lp/Huber/TV/AwTV/Box/...), solver registry (`cgls`, `pcg`,
79
+ `ls`/`wls`/`rls`/`rwls`, `dls`/`rdls`, `mlem`/`osem`, `mltr`,
80
+ `landweber`) and Plug-and-Play denoisers (bilateral, guided, median,
81
+ histogram-sparsity, azimuthal, dictionary).
82
+ - **Physics & simulation**: GPU-native preprocessing (flat field, rings, bad
83
+ pixels, beam hardening, Wiener deblur, scatter, MAR inpainting) with a
84
+ `PreprocessingPipeline`; forward simulation (`simulate_scan`) with an
85
+ embedded, offline-generated X-ray spectrum + material-attenuation library
86
+ (W anode, 40–225 kVp).
87
+ - **Sinogram-domain tools**: Parker short-scan and offset-detector
88
+ weighting, truncation extension, fan→parallel and curved↔flat rebinning —
89
+ backend-neutral.
90
+ - **Analytic phantom engine** (`Ellipsoid`/`Phantom`, exact cone-beam line
91
+ integrals) and center-of-rotation self-calibration.
92
+ - **Out-of-core + multi-GPU orchestration** (CUDA): chunked
93
+ forward/backward/FDK/SIRT/OS-SART with z-slab / v-band shadow geometry,
94
+ async disk↔GPU conveyor, automatic RAM/disk spill (memmap or zarr),
95
+ GPU-FFT streaming ramp filter; validated to 2048³ with a bounded working
96
+ set.
97
+ - **MLX backend wiring**: the Metal kernels + `mx.custom_function`
98
+ projectors from `main` are vendored under `diffct_mlx/backend/metal/` and
99
+ adapted in `backend/_mlx.py`; the `xp` namespace is attribute-identical to
100
+ the torch shim (pinned by a static parity test). Runtime validation on
101
+ Apple hardware pending.
102
+
103
+ ### Fixed (review/debug session, 2026-07-10)
104
+
105
+ - **Detector/voxel grid conventions standardized** to `(k - n/2) * spacing`
106
+ package-wide: the CUDA *and* Metal cone footprint kernels (and the Metal
107
+ cone Siddon kernels) used `(n-1)/2` — a half-pixel shift whenever kernel
108
+ families were mixed; the FBP/FDK gather kernels placed voxel centers at
109
+ `ix - c` instead of `ix + 0.5 - c` — a half-voxel shift of analytic
110
+ volumes against iterative ones. Rebinning helpers aligned to the same
111
+ grid. **Geometry-affecting** for cone-footprint / FDK-gather /
112
+ MLX-cone-Siddon users: results shift by half a pixel/voxel relative to
113
+ earlier builds.
114
+ - **Parker weights** in `rebinning` had half the correct feathering
115
+ argument (conjugate-ray sums didn't normalize); now exactly matches the
116
+ validated `diffct.analytical` formula, and real per-view angles can be
117
+ passed via `betas`.
118
+ - Rebinning gathers build flat indices in int64 (float32 index math
119
+ silently corrupted arrays above 2^24 elements); `curved_to_flat` /
120
+ `flat_to_curved` resample the u axis (axis 1) of 3D stacks; single-view /
121
+ non-uniform `fan_to_parallel` inputs now raise instead of mis-rebinning.
122
+ - Warm-started SART/SIRT no longer skip their first iteration; `rls` no
123
+ longer discards `weights`; `rwls` rejects non-smooth regularizers instead
124
+ of silently ignoring them; AwTV-POCS actually anneals `alpha`; POCS
125
+ drivers reuse the geometry-only sweep cache; `normalized_sart_relaxation`
126
+ is honored (`backprojection_scale` defaults to `None`); DART's masked
127
+ subproblem no longer clips negative residual measurements.
128
+ - `build_npy_cone_3d_case` kept detector counts consistent with the data
129
+ axes under `transpose_uv` (non-square detectors crashed; the expected
130
+ stack order is now documented as `(views, v, u)` with the default
131
+ `transpose_uv=True`).
132
+ - `scatter_correction`/`add_scatter` blur per view in the detector plane
133
+ only (views used to mix); `box_filter` is separable (+`axes=`) and ~1000×
134
+ cheaper at radius 12 in 3D; `detector_deblur` has unit DC gain (values
135
+ were shrunk by ~`reg`); `auto_voxel_spacing_from_detector` bounds both
136
+ lateral axes by the horizontal FOV; `load_tiff_projections` applies
137
+ `revert` before the log transform; `estimate_cone_isocenter` survives a
138
+ single view.
139
+ - Out-of-core conveyor propagates worker exceptions (a failing thread used
140
+ to deadlock the run); auto disk scratch is cleaned up (TB-scale leaks);
141
+ zarr gather writes are serialized; the gather path uploads the filtered
142
+ sinogram once per GPU; `chunked_sirt` takes memmap/zarr inputs lazily;
143
+ memmap outputs are flushed; the caller's CUDA device is restored.
144
+ - Backend hardening: auto-detection picks MLX only when Metal is available
145
+ (Linux MLX wheels no longer shadow CUDA); `xp.grad` returns zeros for
146
+ disconnected objectives (single-slice `tv_gradient` crashed); `xp.clip`
147
+ with no bounds, `Box(-inf, inf).prox`, `xp.max(axis=...)` fixed;
148
+ `ProjectionOperator.subset(slice)` reports correct metadata; sparse cone
149
+ backprojection guards int32 overflow and empty index vectors.
150
+
151
+ ### Changed
152
+
153
+ - Package renamed/versioned as `diffct-mlx 2.0.0.dev0` with extras
154
+ `[cuda]` / `[mlx]` / `[zarr]`; docs (README, Sphinx) rewritten for the
155
+ unified package; dead code removed (unused `_trig_tables`, eager
156
+ deprecated-shim import, never-read parameters).
157
+
158
+ ## [1.3.0.dev0] - 2026-04-14
159
+
160
+ First sync of the dev (arbitrary-trajectory) branch against the main
161
+ branch's 1.2.10 / 1.2.11 analytical reconstruction overhaul. Brings
162
+ dev up to functional parity with main 1.2.11 except for the 1.3.0
163
+ separable-footprint (SF) projector backends, which rely on closed-form
164
+ circular-orbit geometry and are not yet generalised to arbitrary
165
+ trajectories.
166
+
167
+ ### Added
168
+
169
+ #### Analytical reconstruction helpers (``diffct.analytical``)
170
+
171
+ A new module exposes the following helpers, all trajectory-agnostic so
172
+ they work with both the circular trajectories and the arbitrary
173
+ ``(src_pos, det_center, det_u_vec[, det_v_vec])`` trajectory arrays
174
+ that dev-branch kernels already accept:
175
+
176
+ - ``detector_coordinates_1d`` — detector cell centre coordinates.
177
+ - ``angular_integration_weights`` — trapezoidal per-view weights for
178
+ the analytical FBP/FDK sum. Optional ``redundant_full_scan`` flag
179
+ absorbs the ``1/2`` redundancy factor for full scans.
180
+ - ``fan_cosine_weights`` / ``cone_cosine_weights`` — per-detector-cell
181
+ ``cos(gamma)`` pre-weight for fan / cone FBP pipelines.
182
+ - ``parker_weights`` — Parker short-scan redundancy weights for
183
+ circular fan geometries.
184
+ - ``ramp_filter_1d`` — generic 1D ramp filter with ``sample_spacing``,
185
+ ``pad_factor``, ``window`` (``"ram-lak"``, ``"hann"``, ``"hamming"``,
186
+ ``"cosine"``, ``"shepp-logan"``), and ``use_rfft`` options, rescaled
187
+ by ``1 / sample_spacing`` so the output is in physical units.
188
+ - ``parallel_weighted_backproject`` / ``fan_weighted_backproject`` /
189
+ ``cone_weighted_backproject`` — voxel-driven FBP / FDK backprojection
190
+ wrappers that dispatch to new dedicated gather kernels and apply the
191
+ analytical Fourier-convention constant (``1/(2*pi)`` for parallel,
192
+ ``sdd_mean/(2*pi*sid_mean)`` for fan and cone). These are the
193
+ **recommended path for analytical reconstruction** and replace the
194
+ previous pattern of passing a filtered sinogram through
195
+ ``*BackprojectorFunction.apply``.
196
+
197
+ #### Voxel-driven FBP / FDK gather kernels
198
+
199
+ Three new CUDA kernels, each under the dedicated ``fastmath=False``
200
+ ``_FDK_ACCURACY_DECORATOR`` added to ``diffct.constants``:
201
+
202
+ - ``_parallel_2d_fbp_backproject_kernel`` — no distance weighting.
203
+ - ``_fan_2d_fbp_backproject_kernel`` — ``(|S|/U_n)^2`` weighted,
204
+ where ``U_n`` is the signed distance from the per-view source to
205
+ the voxel along the detector normal.
206
+ - ``_cone_3d_fdk_backproject_kernel`` — same pattern in 3D.
207
+
208
+ Every kernel is voxel-driven: one thread per output pixel/voxel, loops
209
+ over views inside, projects the voxel onto the detector using the
210
+ per-view ``(src_pos, det_center, det_u_vec[, det_v_vec])`` arrays,
211
+ bilinearly samples the filtered sinogram, applies the per-view weight
212
+ and accumulates. They are completely separate from the pure Siddon
213
+ adjoint kernels that back the autograd path; autograd is untouched.
214
+
215
+ #### Tests (``tests/``)
216
+
217
+ The dev branch had no test directory at all prior to this change.
218
+ ``pytest.ini`` and ``tests/__init__.py`` are new, plus 58 tests across
219
+ 11 files that mirror the main-branch test layout:
220
+
221
+ - ``tests/test_adjoint_inner_product.py`` — ``<A x, y> = <x, A^T y>``
222
+ identity for parallel / fan / cone autograd pairs, plus an extra
223
+ ``test_cone_autograd_backward_matches_backprojector_forward`` that
224
+ protects the autograd ``ConeProjectorFunction.backward`` from
225
+ drifting away from the standalone ``ConeBackprojectorFunction``.
226
+ - ``tests/test_gradcheck.py`` — ``torch.autograd.gradcheck`` for every
227
+ projector Function with float32-calibrated tolerances.
228
+ - ``tests/test_weights.py`` — unit tests for ``detector_coordinates_1d``,
229
+ ``angular_integration_weights``, ``fan_cosine_weights``,
230
+ ``cone_cosine_weights`` and ``parker_weights``.
231
+ - ``tests/test_cuda_smoke.py`` — end-to-end smoke tests for every
232
+ Projector / Backprojector Function pair + the analytical
233
+ ``*_weighted_backproject`` wrappers.
234
+ - ``tests/test_cone_projector_autograd.py`` — gradient finiteness and
235
+ sparsity guard for the cone projector Function (circular + spiral
236
+ trajectories).
237
+ - ``tests/test_fbp_parallel_accuracy.py`` /
238
+ ``tests/test_fbp_fan_accuracy.py`` /
239
+ ``tests/test_fdk_cone_accuracy.py`` — quantitative RMSE and
240
+ amplitude bounds for a full Shepp-Logan FBP / FDK pipeline per
241
+ geometry. These would have tripped on the old dev reconstruction
242
+ path, which silently produced wrong-amplitude volumes.
243
+ - ``tests/test_fbp_fan_offsets.py`` /
244
+ ``tests/test_fdk_cone_offsets.py`` — adapted from main's offset
245
+ tests: dev's arbitrary-trajectory kernels have no scalar
246
+ ``detector_offset`` / ``center_offset_*`` parameters, so offsets
247
+ are applied by shifting the trajectory arrays directly. Verifies
248
+ that the FBP / FDK gather kernels handle non-centred trajectories.
249
+ - ``tests/test_ramp_filter_windows.py`` — 29 parametrised tests covering
250
+ every ``_ramp_window`` option (DC gain, Nyquist value, non-negativity)
251
+ and the full ``ramp_filter_1d`` end-to-end (shape, DC annihilation,
252
+ rfft vs complex-fft parity, ``sample_spacing`` scaling, high-frequency
253
+ pass-through).
254
+
255
+ #### Benchmark suite (``tests/benchmarks/``)
256
+
257
+ Opt-in ``pytest-benchmark`` suite covering every CUDA kernel in the
258
+ library (forward projector, pure-adjoint backprojector, and the full
259
+ analytical FBP / FDK pipeline) across three sizes for each of the
260
+ three geometries. 27 benchmarks total, excluded from the default
261
+ ``pytest tests/`` run via ``--ignore=tests/benchmarks`` in
262
+ ``pytest.ini``. Run explicitly with
263
+ ``pytest tests/benchmarks/ --benchmark-only``.
264
+
265
+ #### Parker short-scan demos in examples
266
+
267
+ ``examples/circular_trajectory/fbp_fan.py`` and
268
+ ``examples/circular_trajectory/fdk_cone.py`` now expose an
269
+ ``apply_parker`` switch. When enabled, the example switches the
270
+ trajectory to a minimal ``pi + 2*gamma_max`` short scan and applies
271
+ ``parker_weights`` to the sinogram before the ramp filter; when
272
+ disabled, the pipeline runs a full ``2*pi`` scan with the ``1/2``
273
+ redundancy factor absorbed by ``angular_integration_weights``. Both
274
+ branches produce correctly amplitude-calibrated reconstructions.
275
+
276
+ #### Documentation (``docs/source/api.rst``)
277
+
278
+ New "Analytical Reconstruction Helpers", "Ramp Filter Options", and
279
+ "Analytical FBP / FDK architecture" sections describe the new
280
+ ``diffct.analytical`` module, enumerate every ``ramp_filter_1d``
281
+ option, and explain the analytical scale factors used in each
282
+ ``*_weighted_backproject`` wrapper.
283
+
284
+ ### Fixed
285
+
286
+ #### FBP / FDK amplitude bugs in the ``circular_trajectory/*.py`` examples
287
+
288
+ Prior to this release the circular-trajectory FBP / FDK examples
289
+ (``examples/circular_trajectory/fbp_parallel.py``,
290
+ ``examples/circular_trajectory/fbp_fan.py``,
291
+ ``examples/circular_trajectory/fdk_cone.py``) produced amplitude-wrong
292
+ reconstructions because they:
293
+
294
+ - used ``*BackprojectorFunction.apply`` (the pure Siddon adjoint) as if
295
+ it were an FBP gather, so they missed the ``(sid/U)^2`` / ``(|S|/U_n)^2``
296
+ distance weight that the classical FBP / FDK formula requires;
297
+ - hand-rolled a ramp filter missing the ``1/sample_spacing`` scale;
298
+ - multiplied by a standalone ``pi/num_views`` normalisation that only
299
+ absorbs the angular step, not the ``1/(2*pi)`` Fourier-convention
300
+ constant.
301
+
302
+ All three examples now go through the new
303
+ ``parallel_weighted_backproject`` / ``fan_weighted_backproject`` /
304
+ ``cone_weighted_backproject`` wrappers and end-to-end produce raw MSE
305
+ matching the main branch's 1.2.11 release to within rounding:
306
+
307
+ | Example | Raw MSE | Range |
308
+ |-----------------------------------------|-----------|-------------------|
309
+ | ``circular_trajectory/fbp_parallel.py`` | ~0.00366 | ``[-0.02, 1.00]`` |
310
+ | ``circular_trajectory/fbp_fan.py`` | ~0.00220 | ``[-0.10, 1.01]`` |
311
+ | ``circular_trajectory/fdk_cone.py`` | ~0.00333 | ``[-0.07, 1.00]`` |
312
+
313
+ ### Notes on the sync from ``main``
314
+
315
+ The ``main`` branch's 1.2.10 / 1.2.11 / 1.3.0 releases introduced several
316
+ changes which this update brings to the dev branch, adapted where
317
+ necessary for the arbitrary-trajectory kernel API:
318
+
319
+ - ``1.2.10`` FDK / FBP voxel-driven gather, ``ramp_filter_1d`` options,
320
+ analytical constants, and the ``(sid/U)^2`` correctness fix: **ported**.
321
+ Because dev's kernels take per-view ``(src_pos, det_center, u_vec,
322
+ v_vec)`` arrays instead of closed-form ``sin(beta)/cos(beta)`` math,
323
+ the new gather kernels use ``U_n = (P - S) . n`` (where
324
+ ``n = u_vec x v_vec``) as the generalisation of the classical ``U``.
325
+ For a canonical circular orbit this reduces to the textbook
326
+ ``sid + x*sin(beta) - y*cos(beta)``.
327
+ - ``1.2.10`` cone / fan autograd ``distance_weight=1.0`` bug fix:
328
+ **not applicable**. The dev cone / fan backward kernels were
329
+ already correct (they never had that parameter), so the autograd
330
+ adjoint identity holds on dev and is now protected by
331
+ ``tests/test_adjoint_inner_product.py``.
332
+ - ``1.2.11`` gradcheck / ramp window tests / CHANGELOG: **ported**.
333
+ - ``1.2.11`` benchmark suite: **not ported yet** (dev's benchmarks
334
+ directory stays empty).
335
+ - ``1.3.0`` SF-TR / SF-TT projector backends: **not ported**. SF relies
336
+ on closed-form ``sin(beta)/cos(beta)`` math for the trapezoidal
337
+ transaxial / rectangular axial footprints. Generalising SF to
338
+ arbitrary per-view ``(S, C, u_vec, v_vec)`` trajectories is a
339
+ non-trivial research effort (the "separable" part is not separable
340
+ when the detector is not plane-aligned to the voxel axes) and will
341
+ be tackled in a dedicated follow-up.
342
+
343
+ [Unreleased]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0.0...HEAD
344
+ [2.0.0]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/releases/tag/v2.0.0