From Wikipedia:
SageMath (previously Sage or SAGE, “System for Algebra and Geometry Experimentation”) is a computer algebra system (CAS) with features covering many aspects of mathematics, including algebra, combinatorics, graph theory, group theory, differentiable manifolds, numerical analysis, number theory, calculus and statistics.
SageMath can run on Clipper via Apptainer.
Obtaining the SageMath Container
Official SageMath container images are available from DockerHub. Please note, as of July 2024 the container image is nearly 13GB in size. Images can be stored in either your home or project folders.
Load the Apptainer module:
module load apptainer
Download the latest SageMath container to the current working directory and convert it to Singularity Image Format, which is used by Apptainer. This command will overwrite an existing container if it exists.
apptainer pull --force sagemath.sif docker://sagemath/sagemath:latest
Running SageMath Interactively
Request an interactive session via Slurm. GVSU ARC recommends the cpu
or bigmem
partitions be used for SageMath. In this example, we are requesting 8 CPU cores and 16 GB of memory from the cpu
partition:
srun --nodes=1 --partition=cpu --ntasks-per-node=1 --mem=16G --cpus-per-task=8 --time=01:00:00 --pty bash -i
For an interactive SageMath session, launch the container with no arguments:
[hpcuser1@c001 ~]$ apptainer run sagemath.sif
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.4, Release Date: 2024-07-19 │
│ Using Python 3.12.4. Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage:
To run a SageMath script, use Apptainer’s exec
command, passing the inputs sage
and the path to your SageMath script:
[hpcuser1@c001 ~]$ apptainer exec sagemath.sif sage hello.sage
Hello World
8
Our example hello.sage
script:
print("Hello World")
print(2^3)
Submit SageMath Slurm Job
Create a Slurm script, for example sage.sbatch
:
#!/bin/bash
#SBATCH --job-name=sage
#SBATCH --partition=cpu # or bigmem
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=8 # number of cpus to use
#SBATCH --mem=16G # amount of ram to request
#SBATCH --time=01:00:00 # time to run
#SBATCH --output=sage-%j.out # standard output location
#SBATCH --error=sage-%j.err # standard error location
# load apptainer
module load apptainer
# execute sage script via container
apptainer exec sagemath.sif sage hello.sage
Submit the job:
sbatch sage.sbatch
Additional Notes
As of July 2024 and the SageMath 10.4 container, two informational messages are printed to standard error when the Apptainer process finishes:
INFO: Terminating squashfuse_ll after timeout
INFO: Timeouts can be caused by a running background process
These can be ignored.