Skip to content

Commit 3fdc13c

Browse files
committed
adding docker file and update readme
1 parent ad417c2 commit 3fdc13c

File tree

6 files changed

+91
-24
lines changed

6 files changed

+91
-24
lines changed

README.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,49 @@
2121

2222
</div>
2323

24-
---
2524

26-
This program is designed to simulate the behavior of spins under a specific MR sequence within a microvascular network or digitally generated phantom. Breifly, the susceptibility variation between blood and tissue leads to local field inhomogeneity which accordingly can be used to generate an MR contrast. The program tries to perform a Monte-Carlo simulation over range of spins which are randomly or regularly distributed and diffuse in presence of user defined magnetic field. SpinWalk is a versatile Monte Carlo simulator. While its primary goal is to simulate BOLD fMRI, it can also be utilized for a wide range of diffusion applications.
25+
SpinWalk is a Monte Carlo diffusion simulator. Spinwalk simulates spins (particles) random walk under a specific MR sequence within a digital phantom mimicing e.g., microvascular network, cells, axons, etc.
2726

28-
Here are example plots obtained from SpinWalk where show BOLD sensitivity as a function of vessel size for Gradient Echo (GRE) and Spin Echo (SE) seqeuences.
27+
---
28+
### Key features
29+
- runs in GPU (massively parallel) or CPU
30+
- off-resonance: local field inhomogeneity because of susceptibility variation is accepted
31+
- T1 and T2 relxation times: Each substrate can have own relaxation defined
32+
- permeability: permeability between individual substrate can be defined with a probablity value
33+
- RF pulses: optinonal number of RF (with magnitude and phase)
34+
- Gradients: Gradient waveform in mT/m for each axis (X, Y, Z) can be defined
35+
- Recording trajectory of random walks in 3D
36+
- simulating steady state condition with given phase cycling and dummy scans
37+
- Boundry condition for crossing FoV
38+
- predefined or random spins placement
39+
- predefined or equlibrium for initial spins magnetization
40+
- FoV can be internally scaled, allows simulating range of vessel size for BOLD fMRI contrast
2941

30-
![](./docs/img/gre_se.jpg)
42+
---
43+
### Demo
3144

32-
Some [literature](#Literature) are provided as reference to get a better feeling of what are intended to get from this kind of simulations.
45+
Jupyter notebooks that demonstrate the basic functionality of the SpinWalk for [BOLD fMRI contrast](./demo/spinwalk_example.ipynb) and [free diffusion](./demo/spinwalk_dwi.ipynb) simulation can be found in [**demo**]([/demo](./demo)) folder
3346

34-
Simulator is written in C++ and utilizes CUDA to run in GPU. Therefore, it is possible to run a simulation within a short period of time provided that a good GPU presents. Simulator can detect all GPU cards, if there is more than one, and can distribute the task to run in parallel in multiple GPUs. This is helpful if you wan to run the simulator in HPC cluster with mutliple GPUs available in a node.
47+
Here are example plots obtained from SpinWalk where show BOLD sensitivity as a function of vessel size for Gradient Echo (GRE) and Spin Echo (SE) seqeuences. Some [literature](#Literature) are provided as reference to get a better feeling of what are intended to get from this kind of simulations.
3548

49+
![](./docs/img/gre_se.jpg)
3650

37-
## How to build
51+
---
52+
### How to build
3853
You can either use the supplied Dockerfile for a consistent build that includes all dependencies, or install the dependencies separately and compile using CMake.
3954

40-
### Docker
41-
We suggest utilizing the provided Dockerfile, which automates the installation of all dependencies, as well as the cloning and building of the program. Download the [Dockerfile](./Dockerfile) to your current directory and then execute the following commands:
55+
#### Docker
56+
We suggest utilizing the provided Dockerfile, which automates the installation of all dependencies, as well as the cloning and building of the program. Clone SpinWalk and build using the provided [Dockerfile](./containers/Dockerfile) with:
4257

43-
```
44-
docker build --no-cache -t spinwalk .
58+
```shell
59+
git clone https://github.com/aghaeifar/SpinWalk
60+
cd containers
61+
docker build --no-cache -t spinwalk ..
4562
docker run --gpus all --rm -it --runtime=nvidia spinwalk bash
4663
```
47-
### CMake
64+
#### CMake
4865

49-
#### Dependencies
66+
**Dependencies**
5067

5168
- A C++ compiler supprting C++20
5269
- CUDA toolkit newer than v12.0 that supports C++20 ([+](https://developer.nvidia.com/blog/cuda-toolkit-12-0-released-for-general-availability/)). Nvidia driver must support your CUDA release ([+](https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html)). Check driver and cuda version with *nvidia-smi* and *nvcc --version* in terminal.
@@ -56,35 +73,36 @@ docker run --gpus all --rm -it --runtime=nvidia spinwalk bash
5673

5774
If you prefer to install the program without using Docker, follow these steps (tested in Ubuntu 22.04):
5875

59-
```
76+
```shell
6077
sudo apt-get update && apt-get install -y libboost-all-dev libhdf5-dev libtbb-dev
6178
git clone https://github.com/aghaeifar/SpinWalk.git
6279
cd SpinWalk
6380
cmake -B ./build
6481
cmake --build ./build --config Release
6582
```
83+
---
6684

67-
## Quick test after build
68-
After building the program, simply launch `spinwalk` in the terminal to view the help menu with all available options. If a GPU is avaialbe and CUDA is installed, launch `spinwalk -g` to display GPU and driver version.
85+
### How to simulate
6986

70-
## How to simulate
87+
After building the program, simply launch `spinwalk` in the terminal to view the help menu with all available options. If a GPU is avaialbe and CUDA is installed, launch `spinwalk -g` to display GPU and driver version. SpinWalk has four subcommands. Subcommand `sim` is used for random walk simulations. The settings for simulation is provided through a configuration file. An example could be as:
7188

72-
```
89+
```shell
7390
spinwalk sim -c my_config.ini
7491
```
7592

7693
Several configuration files can be simulated sequentially:
7794

78-
```
95+
```shell
7996
spinwalk sim -c config1.ini config2.ini ...
8097
```
8198

82-
83-
## Configuration files
99+
---
100+
### Configuration files
84101

85102
Configruation file is a text based [ini file](https://en.wikipedia.org/wiki/INI_file) used to provide simulation parameters for simulator. Simulator can accept more than one configuration to simulation several configurations. A configuration file can inherit from another configuration file to avoid writing repetitive simulation parmeters. All the possible parameters are provided in [config_default.ini](./config/config_default.ini) with definition and expected unit.
86103

87-
## Input/Output file format
104+
---
105+
### Input/Output file format
88106
Spinwalk processes three distinct input files and produces a single output file. All files are stored on disk in _Hierarchical Data Format version 5_ ([HDF5](https://en.wikipedia.org/wiki/Hierarchical_Data_Format)) format. Reading and writing HDF5 file is natively supported by [MATLAB](https://www.mathworks.com/help/matlab/hdf5-files.html). Pythonic interface to work with HDF5 files is also avaialbe through [H5py](https://pypi.org/project/h5py/) package. Input files can be specified within the [FILES] section of the configuration file, while output filename is automatically generated and is stored in the output folder defined under the same [FILES] section in the configuration file.
89107

90108
### Inputs
File renamed without changes.
File renamed without changes.

containers/apptainer.def

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Bootstrap: docker
2+
From: nvidia/cuda:12.2.0-devel-ubuntu22.04
3+
4+
%post
5+
apt-get update && apt-get install -y --no-install-recommends \
6+
software-properties-common \
7+
build-essential \
8+
cmake \
9+
libtbb-dev \
10+
gcc-11 \
11+
g++-11 \
12+
wget \
13+
libboost-all-dev \
14+
libhdf5-dev
15+
16+
apt-get clean && apt-get -y autoremove && rm -rf /var/lib/apt/lists/*
17+
18+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \
19+
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
20+
21+
CMAKE_VERSION=3.30.1
22+
CMAKE_DIR=cmake-${CMAKE_VERSION}-linux-x86_64
23+
24+
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_DIR}.tar.gz && \
25+
tar -zxvf ${CMAKE_DIR}.tar.gz && \
26+
mv ${CMAKE_DIR} /opt/cmake && \
27+
ln -s /opt/cmake/bin/* /usr/local/bin && \
28+
rm ${CMAKE_DIR}.tar.gz
29+
30+
mkdir -p /opt/SpinWalk
31+
cd /opt/SpinWalk
32+
33+
%files
34+
. /opt/SpinWalk
35+
36+
%post
37+
cd /opt/SpinWalk
38+
cmake -B ./build && cmake --build ./build --config Release && cmake --install ./build
39+
40+
%labels
41+
org.opencontainers.image.authors="Ali Aghaeifar"
42+
43+
# apptainer build --disable-cache spinwalk.sif apptainer.def
44+

tests/create_dockers.sh renamed to containers/create_dockers.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/bin/bash
2+
13
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
24
pushd "$SCRIPT_DIR" > /dev/null
35

@@ -13,7 +15,7 @@ for VERSION in "${CUDA_VERSIONS[@]}"; do
1315
echo "Image $IMAGE_NAME already exists. Deleting it..."
1416
docker rmi -f "$IMAGE_NAME"
1517
fi
16-
docker build --no-cache -f ../Dockerfile -t "$IMAGE_NAME" --build-arg CUDA_VERSION=$VERSION ..
18+
docker build --no-cache -f ./Dockerfile -t "$IMAGE_NAME" --build-arg CUDA_VERSION=$VERSION ..
1719
done
1820

1921

@@ -23,4 +25,4 @@ if docker image inspect "$IMAGE_NAME" > /dev/null 2>&1; then
2325
echo "Image $IMAGE_NAME already exists. Deleting it..."
2426
docker rmi -f "$IMAGE_NAME"
2527
fi
26-
docker build --no-cache -f ../Dockerfile_CPU -t "$IMAGE_NAME" ..
28+
docker build --no-cache -f ./Dockerfile_CPU -t "$IMAGE_NAME" ..

tests/create_apptainer.sh renamed to containers/docker_to_apptainer.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
pushd "$SCRIPT_DIR" > /dev/null
5+
36
# Exit immediately if a command exits with a non-zero status
47
set -e
58
# Get a list of Docker images starting with "spinwalk"

0 commit comments

Comments
 (0)