GeezerVison is showing github.com — Merge remote-tracking branch 'origin/main' into feat/mps-backend · cslht11/diffct@0609753
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/ci.yml +39-2Lines changed: 39 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,8 +14,39 @@ concurrency: | 14 | 14 | cancel-in-progress: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} | 15 | 15 |
| 16 | 16 | jobs: | | 17 | + changes: | | 18 | + name: Changed files | | 19 | + runs-on: ubuntu-latest | | 20 | + timeout-minutes: 5 | | 21 | + outputs: | | 22 | + code: ${{ steps.filter.outputs.code }} | | 23 | + steps: | | 24 | + - uses: actions/checkout@v7 | | 25 | + with: | | 26 | + persist-credentials: false | | 27 | + fetch-depth: 0 | | 28 | + # A pull request that changes only files under docs/ skips the package and test jobs. | | 29 | + # Pushes to main and release tags run every job. | | 30 | + - id: filter | | 31 | + env: | | 32 | + EVENT: ${{ github.event_name }} | | 33 | + BASE: ${{ github.event.pull_request.base.sha }} | | 34 | + HEAD: ${{ github.event.pull_request.head.sha }} | | 35 | + run: | | | 36 | + if [ "$EVENT" != pull_request ]; then | | 37 | + echo code=true >> "$GITHUB_OUTPUT" | | 38 | + exit 0 | | 39 | + fi | | 40 | + # Renames list both paths. Paths with non-ASCII bytes stay unquoted. | | 41 | + git -c core.quotePath=false diff --no-renames --name-only "$BASE...$HEAD" > changed.txt | | 42 | + cat changed.txt | | 43 | + if grep -qv '^docs/' changed.txt; then code=true; else code=false; fi | | 44 | + echo "code=$code" >> "$GITHUB_OUTPUT" | | 45 | +
| 17 | 46 | lint: | 18 | 47 | name: Python error checks | | 48 | + needs: changes | | 49 | + if: needs.changes.outputs.code == 'true' | 19 | 50 | runs-on: ubuntu-latest | 20 | 51 | timeout-minutes: 5 | 21 | 52 | steps: | | 33 | 64 |
| 34 | 65 | package: | 35 | 66 | name: Release metadata and distributions | | 67 | + needs: changes | | 68 | + if: needs.changes.outputs.code == 'true' | 36 | 69 | runs-on: ubuntu-latest | 37 | 70 | timeout-minutes: 10 | 38 | 71 | steps: | @@ -321,7 +354,7 @@ jobs: | 321 | 354 | required: | 322 | 355 | name: CI passed | 323 | 356 | if: always() | 324 | | - needs: [lint, package, cpu, clean-cpu, docs] | | 357 | + needs: [changes, lint, package, cpu, clean-cpu, docs] | 325 | 358 | runs-on: ubuntu-latest | 326 | 359 | timeout-minutes: 2 | 327 | 360 | steps: | @@ -333,6 +366,10 @@ jobs: | 333 | 366 | import json | 334 | 367 | import os | 335 | 368 | results = json.loads(os.environ['RESULTS']) | 336 | | - failed = {name: job['result'] for name, job in results.items() if job['result'] != 'success'} | | 369 | + # A documentation-only pull request skips these jobs on purpose. | | 370 | + docs_only = results['changes']['outputs'].get('code') == 'false' | | 371 | + skippable = {'lint', 'package', 'cpu', 'clean-cpu'} if docs_only else set() | | 372 | + failed = {name: job['result'] for name, job in results.items() | | 373 | + if job['result'] != 'success' and not (name in skippable and job['result'] == 'skipped')} | 337 | 374 | assert not failed, failed | 338 | 375 | PY |
Collapse file Copy file name to clipboardExpand all lines: .github/workflows/formal.yml +76Lines changed: 76 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,8 +15,84 @@ concurrency: | 15 | 15 | cancel-in-progress: true | 16 | 16 |
| 17 | 17 | jobs: | | 18 | + changes: | | 19 | + name: Changed files | | 20 | + runs-on: ubuntu-latest | | 21 | + timeout-minutes: 5 | | 22 | + outputs: | | 23 | + code: ${{ steps.filter.outputs.code }} | | 24 | + steps: | | 25 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | | 26 | + with: | | 27 | + persist-credentials: false | | 28 | + fetch-depth: 0 | | 29 | + # The models and property tests do not read the documentation. A pull request that | | 30 | + # changes only files under docs/ skips them. Every other event runs them. | | 31 | + - id: filter | | 32 | + env: | | 33 | + EVENT: ${{ github.event_name }} | | 34 | + BASE: ${{ github.event.pull_request.base.sha }} | | 35 | + HEAD: ${{ github.event.pull_request.head.sha }} | | 36 | + run: | | | 37 | + if [ "$EVENT" != pull_request ]; then | | 38 | + echo code=true >> "$GITHUB_OUTPUT" | | 39 | + exit 0 | | 40 | + fi | | 41 | + # Renames list both paths. Paths with non-ASCII bytes stay unquoted. | | 42 | + git -c core.quotePath=false diff --no-renames --name-only "$BASE...$HEAD" > changed.txt | | 43 | + cat changed.txt | | 44 | + if grep -qv '^docs/' changed.txt; then code=true; else code=false; fi | | 45 | + echo "code=$code" >> "$GITHUB_OUTPUT" | | 46 | +
| | 47 | + tla: | | 48 | + name: MODEL CHECK / TRACE VALIDATION | | 49 | + needs: changes | | 50 | + if: needs.changes.outputs.code == 'true' | | 51 | + runs-on: ubuntu-latest | | 52 | + timeout-minutes: 10 | | 53 | + env: | | 54 | + PYTHONDONTWRITEBYTECODE: "1" | | 55 | + NUMBA_ENABLE_CUDASIM: "1" | | 56 | + OMP_NUM_THREADS: "1" | | 57 | + TORCH_NCCL_TRACE_BUFFER_SIZE: "100000" | | 58 | + TORCH_FR_BUFFER_SIZE: "100000" | | 59 | + TORCH_DISTRIBUTED_DEBUG: DETAIL | | 60 | + steps: | | 61 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | | 62 | + - uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 | | 63 | + with: | | 64 | + distribution: temurin | | 65 | + java-version: "21" | | 66 | + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 | | 67 | + with: | | 68 | + python-version: "3.12" | | 69 | + cache: pip | | 70 | + cache-dependency-path: formal/requirements.txt | | 71 | + - name: Install CPU trace dependencies | | 72 | + run: | | | 73 | + python -m pip install torch==2.14.1 --index-url https://download.pytorch.org/whl/cpu | | 74 | + python -m pip install -r formal/requirements.txt | | 75 | + - name: Collect real CPU and Gloo executions | | 76 | + run: python formal/tla/collect_trace.py --out .validation/formal-tla/traces --hybrid | | 77 | + - name: Check protocols, mutations, and observed executions | | 78 | + run: >- | | 79 | + python formal/tla/check.py --large | | 80 | + --cache .cache/formal-tla --out .validation/formal-tla/checks | | 81 | + --trace-dir .validation/formal-tla/traces | | 82 | + - name: Retain model and trace evidence | | 83 | + if: always() | | 84 | + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | | 85 | + with: | | 86 | + name: formal-tla | | 87 | + path: | | | 88 | + .validation/formal-tla | | 89 | + !.validation/formal-tla/**/*.states/** | | 90 | + include-hidden-files: true | | 91 | + if-no-files-found: error | 18 | 92 | formal: | 19 | 93 | name: PROOF models / BOUNDED simulator / PROPERTY TEST | | 94 | + needs: changes | | 95 | + if: needs.changes.outputs.code == 'true' | 20 | 96 | runs-on: ubuntu-latest | 21 | 97 | timeout-minutes: 15 | 22 | 98 | env: | |
Collapse file Copy file name to clipboardExpand all lines: CHANGELOG.md +4Lines changed: 4 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | 7 | 7 |
| 8 | 8 | ## [Unreleased] | 9 | 9 |
| | 10 | +### Fixed | | 11 | + | | 12 | +- Trajectory constructors reject degenerate inputs instead of building NaN or empty geometry: zero or non-finite `ray_dir_fn` directions in `custom_trajectory_2d_parallel`, `random_trajectory_3d` sources at the isocenter, and view counts that are not positive integers (`TypeError` for floats and booleans, `ValueError` for counts below 1). Explicit angle tensors are still accepted. Thanks to @cslht11 ([#56](https://github.com/sypsyp97/diffct/pull/56)). | | 13 | + | 10 | 14 | ## [2.4.4] - 2026-10-25 | 11 | 15 |
| 12 | 16 | ### Added | |
Collapse file Copy file name to clipboardExpand all lines: diffct/geometry.py +45-3Lines changed: 45 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | """ | 6 | 6 |
| 7 | 7 | import math | | 8 | +import operator | 8 | 9 | import torch | 9 | 10 |
| 10 | 11 | from .utils import _work_dtype | @@ -93,22 +94,50 @@ def _circular_angles(n_views, start_angle, end_angle, device, dtype): | 93 | 94 | if not torch.isfinite(n_views).all().item(): | 94 | 95 | raise ValueError("angles must be finite") | 95 | 96 | return n_views, n_views.numel(), n_views.device, n_views.dtype | | 97 | + _check_n_views(n_views) | 96 | 98 | step = (end_angle - start_angle) / n_views | 97 | 99 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 98 | 100 | return angles, n_views, device, dtype | 99 | 101 |
| 100 | 102 |
| 101 | | -def _check_source_positions(src_pos): | | 103 | +def _check_source_positions(src_pos, what="source_path_fn"): | 102 | 104 | """Reject non-finite sources and sources at the isocenter, which have no viewing direction.""" | 103 | 105 | if not torch.isfinite(src_pos).all(): | 104 | | - raise ValueError("source_path_fn returned non-finite source positions") | | 106 | + raise ValueError(f"{what} returned non-finite source positions") | 105 | 107 | if (torch.linalg.vector_norm(src_pos.detach(), dim=1) == 0).any(): | 106 | 108 | raise ValueError( | 107 | | - "source_path_fn returned a source at the isocenter; every source needs a " | | 109 | + f"{what} returned a source at the isocenter; every source needs a " | 108 | 110 | "nonzero distance from the origin" | 109 | 111 | ) | 110 | 112 |
| 111 | 113 |
| | 114 | +def _check_n_views(n_views): | | 115 | + """Reject view counts that are not positive integers. | | 116 | +
| | 117 | + A float count would space ``arange(ceil(n))`` views by ``span / n``, and a | | 118 | + nonpositive count builds an empty trajectory or divides by zero. | | 119 | + """ | | 120 | + try: | | 121 | + count = operator.index(n_views) | | 122 | + except TypeError: | | 123 | + count = None | | 124 | + if count is None or isinstance(n_views, bool): | | 125 | + raise TypeError(f"n_views must be a positive integer, got {n_views!r}") | | 126 | + if count < 1: | | 127 | + raise ValueError(f"n_views must be a positive integer, got {n_views!r}") | | 128 | + | | 129 | + | | 130 | +def _check_ray_directions(ray_dir): | | 131 | + """Reject non-finite and zero ray directions, which normalize to NaN.""" | | 132 | + if not torch.isfinite(ray_dir).all(): | | 133 | + raise ValueError("ray_dir_fn returned non-finite ray directions") | | 134 | + if (torch.linalg.vector_norm(ray_dir.detach(), dim=1) == 0).any(): | | 135 | + raise ValueError( | | 136 | + "ray_dir_fn returned a zero ray direction; every view needs a " | | 137 | + "nonzero direction vector" | | 138 | + ) | | 139 | + | | 140 | + | 112 | 141 | def circular_trajectory_3d(n_views, sid, sdd, start_angle=0.0, end_angle=None, device='cuda', dtype=torch.float32): | 113 | 142 | """Generate circular trajectory geometry for cone-beam CT. | 114 | 143 |
| @@ -295,6 +324,8 @@ def random_trajectory_3d(n_views, sid_mean, sdd_mean, sid_std=0.0, pos_std=0.0, | 295 | 324 | det_u_vec = det_u_vec / torch.norm(det_u_vec, dim=1, keepdim=True) | 296 | 325 | det_v_vec = det_v_vec / torch.norm(det_v_vec, dim=1, keepdim=True) | 297 | 326 |
| | 327 | + _check_source_positions(src_pos, "random_trajectory_3d") | | 328 | + | 298 | 329 | return src_pos, det_center, det_u_vec, det_v_vec | 299 | 330 |
| 300 | 331 |
| @@ -343,6 +374,7 @@ def spiral_trajectory_3d(n_views, sid, sdd, z_range=100.0, n_turns=2.0, | 343 | 374 | """ | 344 | 375 | # Generate angles for spiral motion | 345 | 376 | end_angle = start_angle + 2 * math.pi * n_turns | | 377 | + _check_n_views(n_views) | 346 | 378 | step = (end_angle - start_angle) / n_views | 347 | 379 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 348 | 380 |
| @@ -428,6 +460,7 @@ def sinusoidal_trajectory_3d(n_views, sid, sdd, amplitude=50.0, frequency=2.0, | 428 | 460 | """ | 429 | 461 | # Generate angles | 430 | 462 | end_angle = start_angle + 2 * math.pi | | 463 | + _check_n_views(n_views) | 431 | 464 | step = (end_angle - start_angle) / n_views | 432 | 465 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 433 | 466 |
| @@ -514,6 +547,7 @@ def saddle_trajectory_3d(n_views, sid, sdd, z_amplitude=50.0, radial_amplitude=3 | 514 | 547 | """ | 515 | 548 | # Generate angles | 516 | 549 | end_angle = start_angle + 2 * math.pi | | 550 | + _check_n_views(n_views) | 517 | 551 | step = (end_angle - start_angle) / n_views | 518 | 552 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 519 | 553 |
| @@ -610,6 +644,7 @@ def custom_trajectory_3d(n_views, sid, sdd, | 610 | 644 | """ | 611 | 645 | # Generate angles | 612 | 646 | end_angle = start_angle + 2 * math.pi | | 647 | + _check_n_views(n_views) | 613 | 648 | step = (end_angle - start_angle) / n_views | 614 | 649 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 615 | 650 |
| @@ -755,6 +790,7 @@ def sinusoidal_trajectory_2d_fan(n_views, sid, sdd, amplitude=50.0, frequency=2. | 755 | 790 | """ | 756 | 791 | # Generate angles | 757 | 792 | end_angle = start_angle + 2 * math.pi | | 793 | + _check_n_views(n_views) | 758 | 794 | step = (end_angle - start_angle) / n_views | 759 | 795 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 760 | 796 |
| @@ -838,6 +874,7 @@ def custom_trajectory_2d_fan(n_views, sid, sdd, | 838 | 874 | """ | 839 | 875 | # Generate angles | 840 | 876 | end_angle = start_angle + 2 * math.pi | | 877 | + _check_n_views(n_views) | 841 | 878 | step = (end_angle - start_angle) / n_views | 842 | 879 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 843 | 880 |
| @@ -982,6 +1019,7 @@ def sinusoidal_trajectory_2d_parallel(n_views, amplitude=50.0, frequency=2.0, | 982 | 1019 | """ | 983 | 1020 | # Generate angles | 984 | 1021 | end_angle = start_angle + math.pi | | 1022 | + _check_n_views(n_views) | 985 | 1023 | step = (end_angle - start_angle) / n_views | 986 | 1024 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 987 | 1025 |
| @@ -1064,6 +1102,7 @@ def custom_trajectory_2d_parallel(n_views, | 1064 | 1102 | """ | 1065 | 1103 | # Generate angles | 1066 | 1104 | end_angle = start_angle + math.pi | | 1105 | + _check_n_views(n_views) | 1067 | 1106 | step = (end_angle - start_angle) / n_views | 1068 | 1107 | angles = start_angle + torch.arange(n_views, device=device, dtype=dtype) * step | 1069 | 1108 |
| @@ -1078,6 +1117,9 @@ def custom_trajectory_2d_parallel(n_views, | 1078 | 1117 | raise ValueError(f"det_origin_fn must return tensor of shape ({n_views}, 2), " | 1079 | 1118 | f"got {det_origin.shape}") | 1080 | 1119 |
| | 1120 | + # Reject degenerate directions before normalization turns them into NaN | | 1121 | + _check_ray_directions(ray_dir) | | 1122 | + | 1081 | 1123 | # Normalize ray directions | 1082 | 1124 | ray_dir = ray_dir / torch.norm(ray_dir, dim=1, keepdim=True) | 1083 | 1125 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/source/_static/custom.css +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,25 @@ html[data-theme="dark"] { | 10 | 10 | --pst-color-link-hover: #f2a541; | 11 | 11 | } | 12 | 12 |
| | 13 | +/* Every page keeps the same three columns, so the content does not move when the top navigation | | 14 | + switches pages. The two sidebars have the same width. */ | | 15 | +@media (min-width: 960px) { | | 16 | + html .bd-sidebar-primary { --pst-sidebar-primary-width: var(--pst-sidebar-secondary); } | | 17 | +} | | 18 | + | | 19 | +/* Site navigation: sections in the text color, pages below them muted, the current page in the primary color. */ | | 20 | +.site-nav .toctree-l1 { margin-bottom: 0.15rem; } | | 21 | +.site-nav .toctree-l1 > a { font-weight: 600; color: var(--pst-color-text-base); } | | 22 | +.site-nav .toctree-l2 > a, .site-nav .toctree-l3 > a { color: var(--pst-color-text-muted); } | | 23 | +.site-nav li > a:hover { color: var(--pst-color-link-hover); } | | 24 | +.site-nav li.current > a, .site-nav li > a.current { color: var(--pst-color-primary); } | | 25 | +/* The search page has no secondary sidebar and no article element. Keep its column empty and | | 26 | + give it the article padding on wide screens. */ | | 27 | +@media (min-width: 1200px) { | | 28 | + .bd-content:not(:has(> .bd-sidebar-secondary)) > .bd-article-container { margin-right: var(--pst-sidebar-secondary); } | | 29 | + .bd-main .bd-content .bd-article-container .bd-search-container { padding-left: 2rem; padding-top: 1.5rem; } | | 30 | +} | | 31 | + | 13 | 32 | /* Landing page search box */ | 14 | 33 | .landing-search { margin: 0.5rem 0 1.75rem; } | 15 | 34 | .landing-search input { | |
Collapse file Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{# The whole documentation tree, so that every page shows the same sidebar. The branch of the current page is open. #} | | 2 | +<nav class="bd-docs-nav bd-links site-nav" aria-label="{{ _('Site Navigation') }}"> | | 3 | + <div class="bd-toc-item navbar-nav"> | | 4 | + {{- generate_toctree_html( | | 5 | + "sidebar", | | 6 | + startdepth=0, | | 7 | + show_nav_level=1, | | 8 | + maxdepth=3, | | 9 | + collapse=False, | | 10 | + includehidden=True, | | 11 | + titles_only=True | | 12 | + ) | | 13 | + -}} | | 14 | + </div> | | 15 | +</nav> |
Collapse file Copy file name to clipboardExpand all lines: docs/source/conf.py +2-6Lines changed: 2 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 75 | 75 | 'footer_start': ['copyright', 'llms-links'], | 76 | 76 | 'footer_end': ['sphinx-version', 'theme-version'], | 77 | 77 | } | 78 | | -html_sidebars = { | 79 | | - 'index': [], | 80 | | - 'examples': [], | 81 | | - 'getting_started': [], | 82 | | - 'changelog': [], | 83 | | -} | | 78 | +# Every page shows the whole documentation tree, so the layout does not change between sections. | | 79 | +html_sidebars = {'**': ['sidebar-site-nav.html']} | 84 | 80 |
| 85 | 81 |
| 86 | 82 | def setup(app): | |
Collapse file Copy file name to clipboardExpand all lines: docs/source/index.rst -2Lines changed: 0 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -:html_theme.sidebar_secondary.remove: | 2 | | - | 3 | 1 | diffct | 4 | 2 | ====== | 5 | 3 |
| |
|