Skip to content
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

Update CCPi-Regularisation plugin for version 24.0.0 #1761

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
runs-on: [self-hosted, python, cuda]
strategy:
matrix:
python-version: [3.9]
numpy-version: [1.22]
python-version: [3.11]
numpy-version: [1.25]
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0, submodules: recursive}
Expand Down Expand Up @@ -80,10 +80,10 @@ jobs:
strategy:
matrix:
include:
- python-version: 3.8
numpy-version: 1.21
- python-version: '3.10'
numpy-version: 1.24
numpy-version: 1.23
- python-version: 3.12
numpy-version: 1.26
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0, submodules: recursive}
Expand All @@ -105,8 +105,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
numpy-version: [1.22]
python-version: [3.11]
numpy-version: [1.25]
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0, submodules: recursive}
Expand All @@ -132,7 +132,7 @@ jobs:
- uses: actions/checkout@v4
with: {fetch-depth: 0, submodules: recursive}
- uses: conda-incubator/setup-miniconda@v3
with: {python-version: '3.10'}
with: {python-version: 3.11}
- name: install dependencies
run: |
cd docs
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* x.x.x
- Update to new CCPi-Regularisation toolkit v24.0.0. This is a backward incompatible release of the toolkit.
- Set CMake Policy CMP0148 to OLD to avoid warnings in CMake 3.27
- AcquisitionGeometry prints the first and last 10 angles, or all if there are 30 or less, rather than the first 20
- Added a weight argument to the L1Norm function
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where:

- `astra-toolbox` (requires an NVIDIA GPU) enables CIL support for [ASTRA toolbox](http://www.astra-toolbox.com) projectors (GPLv3 license)
- `tigre` (requires an NVIDIA GPU) enables support for [TIGRE](https://github.com/CERN/TIGRE) toolbox projectors (BSD license)
- `ccpi-regulariser` is the [CCPi Regularisation Toolkit](https://github.com/vais-ral/CCPi-Regularisation-Toolkit)
- `ccpi-regulariser` is the [CCPi Regularisation Toolkit](https://github.com/TomographicImaging/CCPi-Regularisation-Toolkit)
- `tomophantom` can generate phantoms to use as test data [Tomophantom](https://github.com/dkazanc/TomoPhantom)

### Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

try:
from ccpi.filters import regularisers
from ccpi.filters.cpu_regularisers import TV_ENERGY
from ccpi.filters.TV import TV_ENERGY
except ImportError as exc:
raise ImportError('Please `conda install "ccpi::ccpi-regulariser>=20.04"`') from exc
raise ImportError('Please `conda install "ccpi::ccpi-regulariser>=24"`') from exc


from cil.framework import DataOrder
Expand Down Expand Up @@ -229,14 +229,17 @@ def _fista_on_dual_rof(self, in_arr, tau):

"""

res , info = regularisers.FGP_TV(\
info = np.zeros((2,), dtype=np.float32)

res = regularisers.FGP_TV(\
in_arr,\
self.alpha * tau,\
self.max_iteration,\
self.tolerance,\
self.methodTV,\
self.nonnegativity,\
self.device)
infovector = info,
device = self.device)

return res, info

Expand Down Expand Up @@ -315,14 +318,18 @@ def alpha1(self):
return 1.

def proximal_numpy(self, in_arr, tau):
res , info = regularisers.TGV(in_arr,

info = np.zeros((2,), dtype=np.float32)

res = regularisers.TGV(in_arr,
self.alpha * tau,
self.alpha1,
self.alpha2,
self.max_iteration,
self.LipshitzConstant,
self.tolerance,
self.device)
infovector = info,
device = self.device)

# info: return number of iteration and reached tolerance
# https://github.com/vais-ral/CCPi-Regularisation-Toolkit/blob/master/src/Core/regularisers_CPU/TGV_core.c#L168
Expand Down Expand Up @@ -400,7 +407,10 @@ def __call__(self,x):
return np.nan

def proximal_numpy(self, in_arr, tau):
res , info = regularisers.FGP_dTV(\

info = np.zeros((2,), dtype=np.float32)

res = regularisers.FGP_dTV(\
in_arr,\
self.reference,\
self.alpha * tau,\
Expand All @@ -409,7 +419,8 @@ def proximal_numpy(self, in_arr, tau):
self.eta,\
self.methodTV,\
self.nonnegativity,\
self.device)
infovector = info,
device = self.device)
return res, info

def convex_conjugate(self, x):
Expand Down Expand Up @@ -454,7 +465,7 @@ def __call__(self,x):
def proximal_numpy(self, in_arr, tau):
# remove any dimension of size 1
in_arr = np.squeeze(in_arr)

res = regularisers.TNV(in_arr,
self.alpha * tau,
self.max_iteration,
Expand Down
44 changes: 22 additions & 22 deletions Wrappers/Python/test/test_DataProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,21 +572,21 @@ def test_process_acquisition(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, geometry_gold,
self.assertEqual(geometry_out, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, geometry_gold))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))


Expand All @@ -606,21 +606,21 @@ def test_process_image(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, geometry_gold,
self.assertEqual(geometry_out, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, geometry_gold))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Binner failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))


Expand Down Expand Up @@ -1343,21 +1343,21 @@ def test_process_acquisition(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, geometry_gold,
self.assertEqual(geometry_out, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, geometry_gold))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))


Expand All @@ -1375,21 +1375,21 @@ def test_process_image(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, geometry_gold,
self.assertEqual(geometry_out, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, geometry_gold))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold, data_out.array)
self.assertEquals(data_out.geometry, geometry_gold,
self.assertEqual(data_out.geometry, geometry_gold,
msg="Slicer failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, geometry_gold))


Expand Down Expand Up @@ -1770,7 +1770,7 @@ def test_process_acquisition_geometry(self):
proc.set_input(geometry)
geometry_padded = proc._process_acquisition_geometry()

self.assertEquals(geometry_padded, self.ag_padded,
self.assertEqual(geometry_padded, self.ag_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_padded, self.ag_padded))


Expand All @@ -1784,7 +1784,7 @@ def test_process_acquisition_geometry(self):
0., 90., 180., 270.,\
360., 450., 540., 630., 720.]

self.assertEquals(geometry_padded, geometry_gold,
self.assertEqual(geometry_padded, geometry_gold,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_padded, geometry_gold))


Expand All @@ -1795,7 +1795,7 @@ def test_process_acquisition_geometry_origin(self):
proc.set_input(geometry)
geometry_padded = proc._process_acquisition_geometry()

self.assertEquals(geometry_padded, self.ag2_padded,
self.assertEqual(geometry_padded, self.ag2_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_padded, self.ag2_padded))


Expand All @@ -1807,7 +1807,7 @@ def test_process_image_geometry(self):
proc.set_input(geometry)
geometry_padded = proc._process_image_geometry()

self.assertEquals(geometry_padded, self.ig_padded,
self.assertEqual(geometry_padded, self.ig_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_padded, self.ig_padded))


Expand Down Expand Up @@ -1846,21 +1846,21 @@ def test_process_acquisition(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, self.ag_padded,
self.assertEqual(geometry_out, self.ag_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, self.ag_padded))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold.array, data_out.array)
self.assertEquals(data_out.geometry, self.ag_padded,
self.assertEqual(data_out.geometry, self.ag_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, self.ag_padded))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold.array, data_out.array)
self.assertEquals(data_out.geometry, self.ag_padded,
self.assertEqual(data_out.geometry, self.ag_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, self.ag_padded))


Expand All @@ -1880,21 +1880,21 @@ def test_process_image(self):

proc.set_input(data_in.geometry)
geometry_out = proc.process()
self.assertEquals(geometry_out, self.ig_padded,
self.assertEqual(geometry_out, self.ig_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(geometry_out, self.ig_padded))

proc.set_input(data_in)
data_out = proc.process()

numpy.testing.assert_array_equal(data_gold.array, data_out.array)
self.assertEquals(data_out.geometry, self.ig_padded,
self.assertEqual(data_out.geometry, self.ig_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, self.ig_padded))

data_out.fill(0)
proc.process(out=data_out)

numpy.testing.assert_array_equal(data_gold.array, data_out.array)
self.assertEquals(data_out.geometry, self.ig_padded,
self.assertEqual(data_out.geometry, self.ig_padded,
msg="Padder failed with geometry mismatch. Got:\n{0}\nExpected:\n{1}".format(data_out.geometry, self.ig_padded))


Expand Down
6 changes: 3 additions & 3 deletions Wrappers/Python/test/test_PluginsRegularisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_functionality_FGP_TV(self):
fcil = FGP_TV()
outcil = fcil.proximal(data, tau=tau)
# use CIL defaults
outrgl, info = regularisers.FGP_TV(datarr, fcil.alpha*tau, fcil.max_iteration, fcil.tolerance, 0, 1, 'cpu' )
outrgl = regularisers.FGP_TV(datarr, fcil.alpha*tau, fcil.max_iteration, fcil.tolerance, 0, 1, device='cpu' )
np.testing.assert_almost_equal(outrgl, outcil.as_array())


Expand All @@ -118,7 +118,7 @@ def test_functionality_TGV(self):
fcil = TGV()
outcil = fcil.proximal(data, tau=tau)
# use CIL defaults
outrgl, info = regularisers.TGV(datarr, fcil.alpha*tau, 1,1, fcil.max_iteration, 12, fcil.tolerance, 'cpu' )
outrgl = regularisers.TGV(datarr, fcil.alpha*tau, 1,1, fcil.max_iteration, 12, fcil.tolerance, device='cpu' )

np.testing.assert_almost_equal(outrgl, outcil.as_array())

Expand All @@ -133,7 +133,7 @@ def test_functionality_FGP_dTV(self):
fcil = FGP_dTV(ref)
outcil = fcil.proximal(data, tau=tau)
# use CIL defaults
outrgl, info = regularisers.FGP_dTV(datarr, ref.as_array(), fcil.alpha*tau, fcil.max_iteration, fcil.tolerance, 0.01, 0, 1, 'cpu' )
outrgl = regularisers.FGP_dTV(datarr, ref.as_array(), fcil.alpha*tau, fcil.max_iteration, fcil.tolerance, 0.01, 0, 1, device='cpu' )
np.testing.assert_almost_equal(outrgl, outcil.as_array())


Expand Down
12 changes: 6 additions & 6 deletions Wrappers/Python/test/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ def test_PDHG_strongly_convex_gamma_g(self):
pdhg = PDHG(f=f, g=g, operator=operator, sigma = sigma, tau=tau,
max_iteration=5, gamma_g=0.5)
pdhg.run(1, verbose=0)
self.assertAlmostEquals(pdhg.theta, 1.0/ np.sqrt(1 + 2 * pdhg.gamma_g * tau))
self.assertAlmostEquals(pdhg.tau, tau * pdhg.theta)
self.assertAlmostEquals(pdhg.sigma, sigma / pdhg.theta)
self.assertAlmostEqual(pdhg.theta, 1.0/ np.sqrt(1 + 2 * pdhg.gamma_g * tau))
self.assertAlmostEqual(pdhg.tau, tau * pdhg.theta)
self.assertAlmostEqual(pdhg.sigma, sigma / pdhg.theta)
pdhg.run(4, verbose=0)
self.assertNotEqual(pdhg.sigma, sigma)
self.assertNotEqual(pdhg.tau, tau)
Expand Down Expand Up @@ -557,9 +557,9 @@ def test_PDHG_strongly_convex_gamma_fcong(self):
pdhg = PDHG(f=f, g=g, operator=operator, sigma = sigma, tau=tau,
max_iteration=5, gamma_fconj=0.5)
pdhg.run(1, verbose=0)
self.assertEquals(pdhg.theta, 1.0/ np.sqrt(1 + 2 * pdhg.gamma_fconj * sigma))
self.assertEquals(pdhg.tau, tau / pdhg.theta)
self.assertEquals(pdhg.sigma, sigma * pdhg.theta)
self.assertEqual(pdhg.theta, 1.0/ np.sqrt(1 + 2 * pdhg.gamma_fconj * sigma))
self.assertEqual(pdhg.tau, tau / pdhg.theta)
self.assertEqual(pdhg.sigma, sigma * pdhg.theta)
pdhg.run(4, verbose=0)
self.assertNotEqual(pdhg.sigma, sigma)
self.assertNotEqual(pdhg.tau, tau)
Expand Down
Loading
Loading