Skip to content
Merged
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
14 changes: 3 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ jobs:
name: build
run: |
conda activate "${{ steps.reqs.outputs.envname }}"
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX"
cmake --build ./build --target install
pip install .
- name: test
run: |
conda activate "${{ steps.reqs.outputs.envname }}"
Expand Down Expand Up @@ -81,10 +80,7 @@ jobs:
python-version: ${{ matrix.python-version }}
environment-file: scripts/requirements-test.yml
activate-environment: cil_dev
- name: build
run: |
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX"
cmake --build ./build --target install
- run: pip install .
- name: test
run: python -m unittest discover -v ./Wrappers/Python/test
conda-matrix:
Expand Down Expand Up @@ -179,11 +175,7 @@ jobs:
conda-merge ../scripts/requirements-test.yml docs_environment.yml > environment.yml
conda env update -n test
conda list
- name: build cil
working-directory: .
run: |
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX"
cmake --build ./build --target install
- run: pip install ..
- name: checkout docs
uses: actions/checkout@v4
with:
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/build/
/build*
__pycache__/
/Wrappers/Python/build/
/Wrappers/Python/cil/version.py
/build*
/Wrappers/Python/cil-*.dist-info/
/Wrappers/Python/cil/include/
/Wrappers/Python/cil/lib/
*.vscode*
*.egg*
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Added tests for Normaliser processor
- Update minimum cmake version to 3.5
- Dependencies:
- Move from CMake to `pip install` (#2145)
- matplotlib-base is an optional dependency, instead of required (#2093)
- `unittest-parametrize has been added as a dependency for tests (#1990)
- olefile and dxchange are an optional dependency, instead of required (#2149)
Expand Down
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ else()
cmake_minimum_required(VERSION 3.5)
endif()

project(cil LANGUAGES CXX)
if(NOT SKBUILD_PROJECT_NAME)
set(SKBUILD_PROJECT_NAME cil)
endif()
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)

cmake_policy(PUSH)

Expand All @@ -46,6 +49,5 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
endif()

add_subdirectory(src/Core)
add_subdirectory(Wrappers/Python)

cmake_policy(POP)
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@ ENV TENSORBOARD_PROXY_URL=/user-redirect/proxy/6006/

# build & install CIL
COPY --chown="${NB_USER}" . src
RUN cmake -S ./src -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="${CONDA_DIR}" \
&& cmake --build ./build --target install \
&& rm -rf src build \
RUN pip install ./src && rm -rf src \
&& fix-permissions "${CONDA_DIR}" /home/${NB_USER}
47 changes: 15 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ conda create --name cil -c conda-forge -c https://software.repos.intel.com/pytho
```

where:

- `astra-toolbox=*=py*` enables CIL support for [ASTRA toolbox](http://www.astra-toolbox.com) CPU projector (2D Parallel beam only) (GPLv3 license)
- `astra-toolbox=*=cuda*` (requires an NVIDIA GPU) enables CIL support for [ASTRA toolbox](http://www.astra-toolbox.com) GPU projectors (GPLv3 license)
- `tigre` (requires an NVIDIA GPU) enables support for [TIGRE](https://github.com/CERN/TIGRE) toolbox projectors (BSD license)
Expand Down Expand Up @@ -86,7 +87,8 @@ docker run --rm --gpus all -p 8888:8888 -it ghcr.io/tomographicimaging/cil:lates
## Getting Started with CIL

### CIL Training
We typically run training courses at least twice a year - check https://ccpi.ac.uk/training/ for our upcoming events!

We typically run training courses at least twice a year - check <https://ccpi.ac.uk/training/> for our upcoming events!

### CIL on binder

Expand Down Expand Up @@ -116,60 +118,45 @@ The use of `--recurse-submodule` is necessary if the user wants the examples dat
git submodule update --init --recursive
```

### Build dependencies
### Building with `pip`

#### Install Dependencies

To create a conda environment with all the dependencies for building CIL run the following shell script:

```sh
bash scripts/create_local_env_for_cil_development.sh
bash ./scripts/create_local_env_for_cil_development.sh
```

Or with the CIL build and test dependencies:

```sh
bash scripts/create_local_env_for_cil_development.sh -t
bash ./scripts/create_local_env_for_cil_development.sh -t
```

And then install CIL in to this environment using CMake.
And then install CIL in to this environment using `pip`.

Alternatively, one can use the `scripts/requirements-test.yml` to create a conda environment with all the
appropriate dependencies on any OS, using the following command:

```sh
conda env create -f scripts/requirements-test.yml
conda env create -f ./scripts/requirements-test.yml
```

### Build with CMake

CMake and a C++ compiler are required to build the source code. Let's suppose that the user is in the source directory, then the following commands should work:
#### Build CIL

```sh
cmake -S . -B ./build -DCMAKE_INSTALL_PREFIX=<install_directory> -DPython_EXECUTABLE=<path_to_python_executable>
cmake --build ./build --target install
```
A C++ compiler is required to build the source code. Let's suppose that the user is in the source directory, then the following commands should work:

If targeting an active conda environment then the `<install_directory>` can be set to the `CONDA_PREFIX` environment variable (e.g. `${CONDA_PREFIX}` in Bash, or `%CONDA_PREFIX%` in the Anaconda Prompt on Windows). Similarly, `<path_to_python_executable>` can be set to the active conda environment by passing `${CONDA_PREFIX}/bin/python` on linux or `%CONDA_PREFIX%\python` in windows.

#### Linux
```sh
cmake -S . -B ./build -DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} -DPython_EXECUTABLE=${CONDA_PREFIX}/bin/python
```
#### Windows
```sh
cmake -S . -B .\build -DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX% -DPython_EXECUTABLE=%CONDA_PREFIX%\python
pip install --no-deps .
```

If not installing to a conda environment then the user will also need to set the locations of the IPP library and includes, and the path to CIL.

By default the location of the IPP library and includes is `${CMAKE_INSTALL_PREFIX}/lib` and `${CMAKE_INSTALL_PREFIX}/include` respectively. To pass the location of the IPP library and headers please pass the following parameters:
If not installing inside a conda environment, then the user might need to set the locations of optional libraries:

```sh
cmake -S . -B ./build -DCMAKE_INSTALL_PREFIX=<install_directory> -DPython_EXECUTABLE=<path_to_python_executable> -DIPP_ROOT=<path_to_ipp>
pip install . -Ccmake.define.IPP_ROOT="<path_to_ipp>" -Ccmake.define.OpenMP_ROOT="<path_to_openmp>"
```

The user will then need to add the path `<install_directory>/lib` to the environment variable `PATH` or `LD_LIBRARY_PATH`, depending on system OS.


### Building with Docker

In the repository root, simply update submodules and run `docker build`:
Expand All @@ -179,7 +166,6 @@ git submodule update --init --recursive
docker build . -t ghcr.io/tomographicimaging/cil
```


### Testing

One installed, CIL functionality can be tested using the following command:
Expand All @@ -189,18 +175,15 @@ export TESTS_FORCE_GPU=1 # optional, makes GPU test failures noisy
python -m unittest discover -v ./Wrappers/Python/test
```


## Citing CIL


If you use CIL in your research, please include citations to **both** the software on Zenodo, and a CIL paper:

E. Pasca, J. S. Jørgensen, E. Papoutsellis, E. Ametova, G. Fardell, K. Thielemans, L. Murgatroyd, M. Duff and H. Robarts (2023) <br>
Core Imaging Library (CIL) <br>
Zenodo [software archive] <br>
**DOI:** https://doi.org/10.5281/zenodo.4746198 <br>


In most cases, the first CIL paper will be the appropriate choice:

J. S. Jørgensen, E. Ametova, G. Burca, G. Fardell, E. Papoutsellis, E. Pasca, K. Thielemans, M. Turner, R. Warr, W. R. B. Lionheart and P. J. Withers (2021) <br>
Expand Down
30 changes: 0 additions & 30 deletions Wrappers/Python/CMakeLists.txt

This file was deleted.

20 changes: 6 additions & 14 deletions Wrappers/Python/cil/framework/cilacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@
# Authors:
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt
import ctypes
import platform
from ctypes import util
# check for the extension
from pathlib import Path

if platform.system() == 'Linux':
dll = 'libcilacc.so'
elif platform.system() == 'Windows':
dll_file = 'cilacc.dll'
dll = util.find_library(dll_file)
elif platform.system() == 'Darwin':
dll = 'libcilacc.dylib'
else:
raise ValueError('Not supported platform, ', platform.system())

cilacc = ctypes.cdll.LoadLibrary(dll)
try:
cilacc_path = next((Path(__file__).parent.parent / 'lib').resolve().glob("*cilacc.*"))
except StopIteration:
raise FileNotFoundError("cilacc library not found")
cilacc = ctypes.cdll.LoadLibrary(str(cilacc_path))
22 changes: 4 additions & 18 deletions Wrappers/Python/cil/optimisation/operators/GradientOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from cil.optimisation.operators import LinearOperator
from cil.optimisation.operators import FiniteDifferenceOperator
from cil.framework import BlockGeometry, ImageGeometry
from cil.framework import BlockGeometry, ImageGeometry, cilacc
import logging
from cil.utilities.multiprocessing import NUM_THREADS
import numpy as np
Expand Down Expand Up @@ -258,7 +258,7 @@ def adjoint(self, x, out=None):
out.fill(tmp)
else:
out += tmp
return out
return out
else:
tmp = self.domain_geometry().allocate()
for i, axis_index in enumerate(self.ind):
Expand All @@ -267,20 +267,7 @@ def adjoint(self, x, out=None):
tmp += self.FD.adjoint(x.get_item(i))
return tmp

import ctypes, platform
from ctypes import util
# check for the extension
if platform.system() == 'Linux':
dll = 'libcilacc.so'
elif platform.system() == 'Windows':
dll_file = 'cilacc.dll'
dll = util.find_library(dll_file)
elif platform.system() == 'Darwin':
dll = 'libcilacc.dylib'
else:
raise ValueError('Not supported platform, ', platform.system())

cilacc = ctypes.cdll.LoadLibrary(dll)
import ctypes

c_float_p = ctypes.POINTER(ctypes.c_float)

Expand Down Expand Up @@ -457,7 +444,7 @@ def adjoint(self, x, out=None):
status = self.fd(out_p, *args)
if status != 0:
raise RuntimeError('Call to C gradient operator failed')

out.fill(ndout)

#reset input data
Expand All @@ -466,4 +453,3 @@ def adjoint(self, x, out=None):
ndx[i]*= el

return out

3 changes: 1 addition & 2 deletions docs/source/developer_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ Example:
cd CIL
sh scripts/create_local_env_for_cil_development_tests.sh -n NUMPY_VERSION -p PYTHON_VERSION -e ENVIRONMENT_NAME
conda activate ENVIRONMENT_NAME
cmake -S . -B ./build -DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX}
cmake --build ./build --target install
pip install .
cd docs
conda update -n base -c defaults conda
conda env update -f docs_environment.yml # with the name field set to ENVIRONMENT_NAME
Expand Down
18 changes: 16 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=64",
"setuptools_scm>=8",
"scikit-build-core>=0.10",
#"ipp-devel==2021.12.*", # PyPI conflicts with conda package
]
build-backend = "scikit_build_core.build"

[tool.scikit-build]
minimum-version = "build-system.requires"
cmake.version = ">=3.16"
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.include = ["Wrappers/Python/cil/version.py"]
sdist.exclude = ["scripts", "docs", "Wrappers/Python/data", "Wrappers/Python/test", ".*"]
[tool.scikit-build.wheel.packages]
cil = "Wrappers/Python/cil"

[tool.setuptools_scm]
version_file = "Wrappers/Python/cil/version.py"
Expand Down
10 changes: 1 addition & 9 deletions recipe/bld.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,5 @@ set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION%
if not "%GIT_DESCRIBE_NUMBER%"=="0" (
set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION%.dev%GIT_DESCRIBE_NUMBER%+%GIT_DESCRIBE_HASH%
)

:: -G "Visual Studio 16 2019" specifies the the generator
:: -T v142 specifies the toolset

cmake -S "%RECIPE_DIR%\.." -B "%SRC_DIR%\build_framework" -G "Visual Studio 16 2019" -T "v142" -DCONDA_BUILD=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBRARY_LIB=%CONDA_PREFIX%\lib -DLIBRARY_INC=%CONDA_PREFIX% -DCMAKE_INSTALL_PREFIX=%PREFIX% -DPython_EXECUTABLE=%CONDA_PREFIX%\python

if errorlevel 1 exit 1

cmake --build "%SRC_DIR%\build_framework" --target install --config RelWithDebInfo
pip install . --no-deps
if errorlevel 1 exit 1
13 changes: 3 additions & 10 deletions recipe/build.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
#!/usr/bin/env bash
set -euxo pipefail

extra_args="-G Ninja"
if test $(python -c "from __future__ import print_function; import platform; print(platform.system())") = Darwin ; then
echo "Darwin"
extra_args="-DOPENMP_LIBRARIES=${CONDA_PREFIX}/lib -DOPENMP_INCLUDES=${CONDA_PREFIX}/include"
extra_args="$extra_args -DOPENMP_LIBRARIES=${CONDA_PREFIX}/lib -DOPENMP_INCLUDES=${CONDA_PREFIX}/include"
else
echo "something else"
extra_args=""
fi

export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL="${PKG_VERSION}"
if test "${GIT_DESCRIBE_NUMBER}" != "0"; then
export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL="${PKG_VERSION}.dev${GIT_DESCRIBE_NUMBER}+${GIT_DESCRIBE_HASH}"
fi
cmake ${RECIPE_DIR}/../ ${extra_args} \
-DCONDA_BUILD=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DLIBRARY_LIB=${CONDA_PREFIX}/lib \
-DLIBRARY_INC=${CONDA_PREFIX}/include \
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DPython_EXECUTABLE=${CONDA_PREFIX}/bin/python
cmake --build . --target install
pip install . --no-deps -Ccmake.args="${extra_args}"
Loading
Loading