-
Notifications
You must be signed in to change notification settings - Fork 120
Update ASTRA integration #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
askorikov
wants to merge
16
commits into
PyLops:dev
Choose a base branch
from
askorikov:update-astra-integration
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8cd0eeb
tests: enabled fanflat geometry test
askorikov 1c96727
fix: type annotation
askorikov f8c7f1e
fix: deleter failing if object initialization failed before
askorikov 84e2d1e
feat: add support for CUDA backend of ASTRA
askorikov e3996ca
tests: make parameter sets named
askorikov 1a08cd8
doc: fix argument description wording
askorikov 0eaf364
fix: add missing type annotation
askorikov e1a9eb8
fix: catch unsupported engine types
askorikov 0a5666d
doc: add docstring to the hack used to enable zero-copy GPU data exch…
askorikov c8ccfa5
fix: type annotations
askorikov 4729f73
fix: projector types for fanflat geometry and cuda
askorikov f8e4c48
minor: change default dtype and add a note
askorikov 29cbdec
fix: ensure compatibility with ASTRA in terms of dtype and contiguity
askorikov 8714cb1
tests: refactor CT2D operator tests
askorikov 0b8d73b
tests: increase tolerance in astra dottests
askorikov 7599a3e
ci: add bound on astra version in the requirements
askorikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ dependencies: | |
| - scipy>=1.13.0 | ||
| - cupy | ||
| - sympy | ||
| - astra-toolbox>=2.3.0 | ||
| - matplotlib | ||
| - ipython | ||
| - pytest | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,73 @@ | ||
| import os | ||
| import platform | ||
|
|
||
| import numpy as np | ||
| if int(os.environ.get("TEST_CUPY_PYLOPS", 0)): | ||
| import cupy as np | ||
|
|
||
| backend = "cupy" | ||
| else: | ||
| import numpy as np | ||
|
|
||
| backend = "numpy" | ||
| import pytest | ||
|
|
||
| from pylops.medical import CT2D | ||
| from pylops.utils import dottest | ||
|
|
||
| par1 = { | ||
| "ny": 51, | ||
| "nx": 30, | ||
| "ntheta": 20, | ||
| "proj_geom_type": "parallel", | ||
| "projector_type": "strip", | ||
| "dtype": "float64", | ||
| } # parallel, strip | ||
|
|
||
| par2 = { | ||
| "ny": 51, | ||
| "nx": 30, | ||
| "ntheta": 20, | ||
| "proj_geom_type": "parallel", | ||
| "projector_type": "line", | ||
| "dtype": "float64", | ||
| } # parallel, line | ||
|
|
||
| par3 = { | ||
| "ny": 51, | ||
| "nx": 30, | ||
| "ntheta": 20, | ||
| "proj_geom_type": "fanflat", | ||
| "projector_type": "strip", | ||
| "dtype": "float64", | ||
| } # fanflat, strip | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| int(os.environ.get("TEST_CUPY_PYLOPS", 0)) == 1, reason="Not CuPy enabled" | ||
| ) | ||
| @pytest.mark.skipif(platform.system() == "Darwin", reason="Not OSX enabled") | ||
| @pytest.mark.parametrize("par", [(par1), (par2)]) | ||
| def test_CT2D(par): | ||
| """Dot-test for CT2D operator""" | ||
| theta = np.linspace(0.0, np.pi, par["ntheta"], endpoint=False) | ||
|
|
||
| Cop = CT2D( | ||
| (par["ny"], par["nx"]), | ||
| @pytest.fixture | ||
| def operator(request): | ||
| geometry_type = request.param | ||
| nx = 51 | ||
| ny = 30 | ||
| ntheta = 20 | ||
| theta = np.linspace(0.0, np.pi, ntheta, endpoint=False) | ||
| source_origin_dist = 100 if geometry_type == "fanflat" else None | ||
| origin_detector_dist = 0 if geometry_type == "fanflat" else None | ||
| return CT2D( | ||
| (ny, nx), | ||
| 1.0, | ||
| par["ny"], | ||
| ny, | ||
| theta, | ||
| proj_geom_type=par["proj_geom_type"], | ||
| projector_type=par["projector_type"], | ||
| geometry_type, | ||
| source_origin_dist, | ||
| origin_detector_dist, | ||
| engine="cpu" if backend == "numpy" else "cuda", | ||
| ) | ||
| assert dottest( | ||
| Cop, | ||
| par["ny"] * par["ntheta"], | ||
| par["ny"] * par["nx"], | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def x(operator): | ||
| return np.ones(operator.dims, dtype=np.float32) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def y(operator): | ||
| return np.ones((len(operator.thetas), operator.det_count), dtype=np.float32) | ||
|
|
||
|
|
||
| @pytest.mark.skipif(platform.system() == "Darwin", reason="Not OSX enabled") | ||
| @pytest.mark.parametrize("operator", ["parallel", "fanflat"], indirect=True) | ||
| class TestCT2D: | ||
| def test_basic(self, operator, x, y): | ||
| assert not np.allclose(operator @ x, 0.0) | ||
| assert not np.allclose(operator.T @ y, 0.0) | ||
|
|
||
| @pytest.mark.skipif( | ||
| backend == "cupy", | ||
| reason="CUDA tests are failing because of severely mismatched adjoint.", | ||
| ) | ||
| def test_adjointess(self, operator): | ||
| assert dottest(operator, rtol=1e-5) | ||
|
|
||
| def test_non_astra_native_dtype(self, operator, x, y): | ||
| x = x.astype(np.float64) | ||
| y = y.astype(np.float64) | ||
| assert not np.allclose(operator @ x, 0.0) | ||
| assert not np.allclose(operator.T @ y, 0.0) | ||
|
|
||
| def test_non_contiguous_input(self, operator, x, y): | ||
| x = x[:, ::-1] # non-contiguous view | ||
| y = y[:, ::-1] | ||
| assert not np.allclose(operator @ x, 0.0) | ||
| assert not np.allclose(operator.T @ y, 0.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ cupy-cuda12x | |
| torch | ||
| numba | ||
| sympy | ||
| astra-toolbox>=2.3.0 | ||
| matplotlib | ||
| ipython | ||
| pytest | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.