Container
This guide covers using the MicroMagnetic.jl container with Docker and Singularity/Apptainer.
Image Overview
The container image includes:
Julia 1.10 with CUDA.jl pre-installed
MicroMagnetic.jl (development version from
master)CairoMakie (simplied version) for visualization
Image size: ~4.2 GB
Docker Usage
Prerequisites
NVIDIA Container Toolkit for GPU support
Commands
Pull the image:
docker pull ghcr.io/magneticsimulation/micromagnetic.jl:latestAlternatively, you can pull the image from ghcr.nju.edu.cn to speed up the download:
<<<<<<< HEAD
docker pull ghcr.nju.edu.cn/magneticsimulation/micromagnetic.jl:latest
=======
docker pull docker://ghcr.nju.edu.cn/magneticsimulation/micromagnetic.jl:latest
>>>>>>> 33832f35f6700d5947e12a8dd596d2a3003a38cbRun a simulation script:
docker run --rm --gpus all -v $(pwd):/workspace \
ghcr.io/magneticsimulation/micromagnetic.jl:latest \
julia /workspace/run_simulation.jlStart an interactive Julia session:
docker run -it --rm --gpus all -v $(pwd):/workspace \
ghcr.io/magneticsimulation/micromagnetic.jl:latestPersistent cache (recommended for faster repeated runs):
To reuse precompiled packages across multiple runs, bind a persistent directory to /depot:
mkdir -p ~/julia_depot
docker run --rm --gpus all \
-v ~/julia_depot:/depot \
-v $(pwd):/workspace \
ghcr.io/magneticsimulation/micromagnetic.jl:latest \
julia /workspace/run_simulation.jlWithout this, precompiled packages are discarded after each run, causing slower startup.
Singularity Usage
Singularity/Apptainer is the standard container runtime on HPC clusters. It runs without root privileges and integrates with SLURM.
Important: Singularity mounts containers as read-only by default. You must bind a writable directory to /depot for Julia to function.
Prerequisites
SingularityCE 3.0+ or Apptainer 1.0+
GPU support requires the
--nvflag
Commands
Pull the image:
singularity pull micromagnetic.sif docker://ghcr.io/magneticsimulation/micromagnetic.jl:latestAlternatively, you can pull the image from ghcr.nju.edu.cn to speed up the download:
singularity pull micromagnetic.sif docker://ghcr.nju.edu.cn/magneticsimulation/micromagnetic.jl:latestRun a script (with required depot binding):
mkdir -p /work/${USER}/julia_depot
singularity exec \
--bind /work/${USER}/julia_depot:/depot \
--nv \
micromagnetic.sif \
julia /path/to/script.jlInteractive session:
singularity shell \
--bind /work/${USER}/julia_depot:/depot \
--nv \
micromagnetic.sifSLURM Job Example
#!/bin/bash
#SBATCH --gpus=1
#SBATCH --time=01:00:00
export JULIA_DEPOT=/work/${USER}/julia_depot
mkdir -p $JULIA_DEPOT
singularity exec \
--bind $JULIA_DEPOT:/depot \
--bind $(pwd):/workspace \
--nv \
micromagnetic.sif \
julia /workspace/run_simulation.jlCommon Issues
Singularity: read-only file system
Error: read-only file system when running Julia.
Solution: Bind a writable directory to /depot:
mkdir -p ~/julia_depot
singularity exec --bind ~/julia_depot:/depot ...GPU not detected
Docker: Ensure
--gpus allis includedSingularity: Ensure
--nvis includedVerify NVIDIA drivers are installed on the host system
singularity not found in HPC clusters
try
module load singularityto load the Singularity moduleinstall it by following the instructions on the https://apptainer.org/