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 miniforge.
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] 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.
- 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 and environment name
: ${DEVELROOT:=~/devel}
: ${ENV:=sirfetc}
: ${BUILDDIR:=${DEVELROOT}/build_${ENV}}
: ${SBDIR:=${DEVELROOT}/SIRF-SuperBuild}
mkdir -p "$BUILDDIR"
cd "$BUILDDIR"
# Create requirements.yml
cp "$SBDIR"/docker/requirements.yml .
eval "$(conda shell.bash hook)"
PACKAGES=""
if command -v nvcc >& /dev/null
then
PACKAGES="cuda-driver-dev cuda-cudart-dev cuda-nvcc"
fi
PACKAGES="$PACKAGES ninja go ccache cmake=3.* cxx-compiler \
armadillo=12.8.4 dcmtk howardhinnant_date eigen libcurl mkl mkl-include range-v3 libblas=*=*mkl gtest gmock plplot pugixml \
python-wget six boost libitk-devel libitk nlohmann_json libparallelproj fftw niftyreg"
for package in ${PACKAGES}; do
echo " - $package" >> requirements.yml
done
# KT experiences a problem with ccpi-regulariser (rattler solver does not find it), so remove it
sed -i /ccpi-regulariser/d requirements.yml
# create conda env and activate
conda env create -n ${ENV} --solver rattler -f requirements.yml
conda activate ${ENV}
# CMake and build
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_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_CIL=ON
cmake --build . --config Release
# If you csh or so, modify the following line
cp "$CONDA_PREFIX"/bin/env_sirf.sh "$CONDA_PREFIX"/etc/conda/activate.d/
conda deactivate
conda activate ${ENV}
Install more packages via conda.
You can add stir to the list of packages (and then set USE_SYSTEM_STIR=ON). However, at the time of writing, this installs on the (old) 6.2 version of STIR, due to conda solver resolution.
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 requirements.yml, and hope that versions can be resolved... We haven't tried this ourselves yet.
Building on non-Linux systems
Windows Subsystem for Linux
The above should work. See also SIRF-Superbuild-with-WSL-on-Windows-11
Windows and Powershell/Visual Studio
Note: these instructions are when using PowerShell and the Visual Studio compiler.
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:
-
If you have problems with a component that you don't need, you could of course switch it off, e.g. add to the
cmakeline-DBUILD_Gadgetron=OFF -DBUILD_CIL=ON. If you have problems building the ISMRMRD examples, you could just switch them off:cmake -DISMRMRD_EXTRA_CMAKE_ARGS:STRING="-DBUILD_EXAMPLES:BOOL=OFF" -B . -
When using clang (e.g. on MacOS), add
llvm-openmp. On other systems, if OpenMP support is not found, you could try to addlibgomp. -
On older Linux, e.g. Ubuntu 20.04, you might have some linking problems. You can try the following work-arounds:
- add
sysroot_linux-64to 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 isundefined 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" - add
-
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)