Building SIRF and CIL with conda - SyneRBI/SIRF GitHub Wiki

These are instructions to build SIRF, CIL and all prerequisites using conda for dependencies. It is recommended to do this if you use conda for your normal python development. The instructions are for a Linux system although minor variations should work on other systems (see also below).

First, install miniconda.

Then follow the instructions below (see end of the page for modifications if you encounter problems). This will download, build, & install all CIL & SIRF dependencies in $CONDA_PREFIX.

To run SIRF+CIL+STIR in the future, you will need to activate the conda environment

conda activate sirfetc

Note that ideally we'd have a requirements.yml to specify all of the requirements. Work in progress...

A note on extra packages: (It is generally recommended to install all conda packages when you create the environment, to give conda the opportunity to find matching versions.)

  • When using clang (e.g. on MacOS), add llvm-openmp. On other systems, if OpenMP support is not found, you could try to add libgomp.
  • You might want to add other packages as well, such as pytorch or whatever.

1. clone the SIRF-SuperBuild:

mkdir ~/devel
cd ~/devel
git clone https://github.com/SyneRBI/SIRF-SuperBuild

2. install conda packages and build: one script to do it all

You could copy this into a script, and modify for your own needs

# default locations
: ${DEVELROOT:=~/devel}
: ${BUILDDIR:=${DEVELROOT}/build_sirfetc}
: ${SBDIR:=${DEVELROOT}/SIRF-SuperBuild}
mkdir -p "$BUILDDIR"
cd "$BUILDDIR"
eval "$(conda shell.bash hook)"
conda env create -n sirfetc -f "$SBDIR"/docker/requirements.yml
conda activate sirfetc
# build CIL ourselves. Not necessary with https://github.com/SyneRBI/SIRF-SuperBuild/pull/946
conda remove -y cil ccpi-regulariser
conda install -y numpy\>=2
if command -v nvcc >& /dev/null
then
   conda install -y cuda-driver-dev cuda-cudart-dev cuda-nvcc
fi
conda install -y ninja swig go ccache cmake=3.* cxx-compiler=1.5.2 \
   armadillo=12.8.4 dcmtk howardhinnant_date eigen libcurl mkl mkl-include range-v3 libblas=*=*mkl gtest gmock plplot pugixml \
  python-wget cython six h5py boost libitk-devel libitk nlohmann_json libparallelproj fftw niftyreg -c conda-forge
cmake -GNinja -S "$SBDIR" -B . -DUSE_SYSTEM_Armadillo=ON -DUSE_SYSTEM_GTest=ON -DUSE_SYSTEM_range-v3=ON -DUSE_SYSTEM_Date=ON -DGadgetron_USE_MKL=ON -DCMAKE_INSTALL_PREFIX:PATH="$CONDA_PREFIX" -DCMAKE_PREFIX_PATH:PATH="$CONDA_PREFIX" -DUSE_SYSTEM_ACE=OFF -DUSE_SYSTEM_Boost=ON -DUSE_SYSTEM_ITK=ON -DUSE_SYSTEM_parallelproj=ON -DUSE_SYSTEM_FFTW3=ON -DUSE_SYSTEM_SWIG=ON -DUSE_SYSTEM_HDF5=ON -DUSE_SYSTEM_JSON=ON -DUSE_SYSTEM_NIFTYREG=ON -DUSE_ITK=ON -DBUILD_Gadgetron=ON -DBUILD_CIL=ON -DCCPi-Regularisation-Toolkit_USE_CUDA=OFF -DGadgetron_TAG=avoid_test_compilation_error -DGadgetron_URL=https://github.com/SyneRBI/gadgetron.git -DISMRMRD_TAG=v1.14.3
cmake --build . --config Release
cp "$CONDA_PREFIX"/bin/env_sirf.sh "$CONDA_PREFIX"/etc/conda/activate.d/
conda deactivate
conda activate sirfetc

Note that as https://github.com/SyneRBI/SIRF-SuperBuild/pull/946 has now been merged, you should be able to skip the "remove cil" step and set -DDBUILD_CIL=OFF. Let us know!

alternative for step 2: manual steps

This section does the above in steps with some extra explanation/flexibility.

Without Gadgetron

This will build SIRF without Gadgetron toolbox support (see below).

cd ~/devel
mkdir build_sirfetc
cd build_sirfetc

conda create --name sirfetc python=3 cxx-compiler cmake=3.* ninja swig setuptools pip wheel \
  scipy python-wget cython six pillow nose h5py numpy matplotlib pytest pytest-cov \
  boost pugixml libitk-devel libitk nlohmann_json libparallelproj fftw docopt deprecation niftyreg \
  tqdm pywavelets numba zenodo_get -c conda-forge

Extra packages:

  • If you have CUDA >= 12.0, add cuda-driver-dev cuda-cudart-dev cuda-nvcc to the above list.
  • When using clang (e.g. on MacOS), add llvm-openmp. On other systems, if OpenMP support is not found, you could try to add libgomp.
  • For some CIL functionality (including its tests), you will need to add olefile dxchange.

Now proceed with building. The instructions here are for Linux (and MacOS?). See below for modifications for Windows.

conda activate sirfetc

cmake -G Ninja -S ../SIRF-SuperBuild/ -B . -DCMAKE_INSTALL_PREFIX:PATH="$CONDA_PREFIX" -DCMAKE_PREFIX_PATH:PATH="$CONDA_PREFIX" -DUSE_SYSTEM_ACE=OFF -DUSE_SYSTEM_Boost=ON -DUSE_SYSTEM_ITK=ON -DUSE_SYSTEM_parallelproj=ON -DUSE_SYSTEM_FFTW3=ON -DUSE_SYSTEM_SWIG=ON -DUSE_SYSTEM_HDF5=ON -DUSE_SYSTEM_JSON=ON -DUSE_SYSTEM_NIFTYREG=ON -DUSE_ITK=ON -DBUILD_Gadgetron=OFF -DBUILD_CIL=ON -DCCPi-Regularisation-Toolkit_USE_CUDA=OFF

cmake --build . --config Release
cp -p $CONDA_PREFIX/bin/env_sirf.sh $CONDA_PREFIX/etc/conda/activate.d/
conda deactivate
conda activate sirfetc

Note: See https://github.com/SyneRBI/SIRF-SuperBuild/issues/948 for why we do -DCCPi-Regularisation-Toolkit_USE_CUDA=OFF at the moment.

Usual CMake build instructions apply. For instance, if you prefer to use a build tool such as make over Ninja, you will have to install it, and use that for the -G option of cmake above.

Building Gadgetron

The above lines don't have all dependencies for Gadgetron. You have 2 options

Build Gadgetron via the SIRF-SuperBuild

This is likely hard, as the Gadgetron version we are using currently (8 Mar 2025) supports g++-11, while conda currently uses g++-13 or more recent, while Gadgetron is no longer actively maintained. The following lines could work (to be executed after the above lines, but before building):

conda install armadillo=12.8.4 dcmtk howardhinnant_date eigen libcurl mkl mkl-include range-v3 libblas=*=*mkl gtest gmock plplot go cxx-compiler=1.5.2
export CGO_ENABLED=1 # make sure the C interface for "go" is enabled.
cmake -DBUILD_Gadgetron=ON -DGadgetron_TAG=avoid_test_compilation_error -DGadgetron_URL=https://github.com/SyneRBI/gadgetron.git -DISMRMRD_TAG=origin/master -DUSE_SYSTEM_Armadillo=ON -DUSE_SYSTEM_GTest=ON -DUSE_SYSTEM_range-v3=ON -DUSE_SYSTEM_Date=ON -DGadgetron_USE_MKL=ON -B .
cmake --build . --config Release

Please note that this downgrades the g++ version to g++-11.

Install Gadgetron via conda.

You could try to use conda to install Gadgetron as well. Please check the Gadgetron conda instructions. Essentially, you'd have to add gadgetron and its channel to the original conda install line, and hope that versions can be resolved... We haven't tried this ourselves yet.

Building on non-Linux systems

Windows

Note: these instructions are when using PowerShell and the Visual Studio compiler. It might be easier to use WSL instead and follow the Linux instructions above.

WARNING: Do not use the Ninja generator nor the clang compiler with conda builds, as conda libraries are compiled with Visual Studio.

You will need some obvious changes from the above to accommodate for the shell syntax of course. Surprisingly, you also have to substitute $CONDA_PREFIX with $Env:CONDA_PREFIX/Library (when using Powershell).

It is highly recommended to use -DCMAKE_INSTALL_PREFIX:PATH=$Env:CONDA_PREFIX/Library -DPYTHON_DEST_DIR:PATH=$Env:CONDA_PREFIX/lib/site-packages to avoid problems with Python permissions, see https://github.com/SyneRBI/SIRF-SuperBuild/issues/729#issuecomment-1173548769

cmake -S ../SIRF-SuperBuild/ -B . -DCMAKE_INSTALL_PREFIX:PATH=$Env:CONDA_PREFIX/Library -DPYTHON_DEST_DIR:PATH=$Env:CONDA_PREFIX/lib/site-packages` -DCMAKE_PREFIX_PATH:PATH=$Env:CONDA_PREFIX <copy options from above>

At the time of writing, you will still need to do

Move-Item $Env:CONDA_PREFIX/Library/Library/bin/*.* $Env:CONDA_PREFIX/Library/bin

check https://github.com/TomographicImaging/CIL/issues/2141 for latest updates on this problem.

Problems and potential solutions:

On older Linux, e.g. Ubuntu 20.04, you might have some linking problems. You can try the following work-arounds:

  • add sysroot_linux-64 to the list of conda packages. This could resolve linking problems with the system GLIBC being older than what was used to build certain conda packages. An example error is undefined reference to memcpy@GLIBC_2.14 (arguably, this should have been solved by conda or the relevant packages, but adding the dependency yourself could work around this problem).
  • add the envs lib folder directly to the path of the run-time loader of shared libraries. This could resolve linking problems finding the correct openmp library for instance:
    export LD_LIBRARY_PATH="$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH"
    
  • If you still have problems building the ISMRMRD examples, you could just switch them off:
    cmake -DISMRMRD_EXTRA_CMAKE_ARGS:STRING="-DBUILD_EXAMPLES:BOOL=OFF" -B .
    cmake --build . --config Release
    
  • If you have problems with a conda package that we can build ourselves, you can do that as opposed to the above, e.g. when experiencing problems with parallelproj:
    # first remove the package that we installed
    conda remove --force libparallelproj
    # now reconfigure telling the SuperBuild to build it
    cmake -DUSE_SYSTEM_parallelproj:BOOL=OFF -B .
    cmake --build . --config Release
    
  • The conda packages might install an OpenSSL version that is more recent than your system one, leading to interesting failures about mismatches. Safest is to do
    conda install git openssh openssl
    
    (or add this to the list of dependencies for the environment)