Use examples

It is now time to use the containers built in the Build examples section to compile some Rat C++ projects.

Hint

  • The content of the rat-containers/work directory is ignored by Git so feel free to use it as a playground to experiment.

  • Use the --nv flag to mount CUDA libraries from host and enable GPU acceleration when running calculaitons on HPC.

Rat-Template

A good exercise is to compile the Rat-Template repository from Project-Rat group. It defines a simple program to simulate a solenoid and calculate field values over its mesh.

This can be done with the rocky-cuda-project-rat.sif image.

  • From the root of the repository, enter an interactive shell:

singularity shell -B $(pwd):/io singularityCE/rocky-cuda-project-rat.sif

# Optional: colored prompt and aliases
source env.sh
  • Navigate into the work subdirectory:

cd work
git clone https://gitlab.com/project-rat/rat-template.git
cd rat-template
  • Configure the project using cmake following Rat-Template instructions, or following the definition files:

cmake -B build -S . -G Ninja

Note

One might need to modify the CMakeLists.txt configuration file in order to match the versions of the Rat libraries installed inside the container (e.g. v2.021.1).

  • Build the project:

cmake --build build
  • Run the project:

./bin/solenoid --od ./mydata

pyRat

The same can be done for the pyRat project with the rocky-cuda-pyrat image instead in order to build pyRat Python wheels.

  • From the root of the repository, enter an interactive shell:

singularity shell -B $(pwd):/io singularityCE/rocky-cuda-pyrat.sif

# Optional: colored prompt and aliases
source env.sh
  • Navigate into the work subdirectory:

cd work
  • Create a UV virtual environment to have access to Python and activate it:

uv venv venv --python=3.12
source ./venv/bin/activate

Note

The Python version of this environment is not important.

The later Python build script will create another virtual environment depending on the Python version requested to build the wheel for regardless.

  • Clone the pyRat repository and navigate into it:

git clone https://gitlab.com/project-rat-extras/pyrat.git
cd pyrat
  • Run the Python build script:

./scripts/py/make_wheel.py -p 3.14 -s