Skip to content

SageMath on Hopper

Installing Sage with Conda Environments

To install Sage in your /home directory, the fastest way is to use Conda environments as in the steps below:

  1. Install the latest miniconda:

    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda3.sh
    bash miniconda3.sh -u -b -p $PWD/miniconda3
    
    2. Activate the installed miniconda to use conda and install mamba:
    source miniconda/bin/activate
    
    conda install mamba -c conda-forge
    
  2. With the installed mamba, create a conda environment for sage

    mamba create -n sage sage -c conda-forge
    
  3. After the sage environment is created, activate it and add the kernel so you can use it in Jupyter Lab from Open OnDemand

    conda activate sage
    
    conda install ipykernel
    python -m ipykernel install --user --name=SageMath
    

From the Command Line Interface

To run Sage from the command line:

  1. Log on to Hopper from the command line

     ssh userid@hopper.orc.gmu.edu
    
    2. Connect to a compute node with the salloc command
     salloc -p normal  -q normal --nodes=1 --cpus-per-task=12 --mem=15GB
    
  2. Activate the Sage environment with the lines:

     source miniconda3/bin/activate
     conda activate sage
    
  3. Run it with

    ```

    sage

    ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 10.2, Release Date: 2023-12-03 │ │ Using Python 3.11.6. Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘

    sage: 1+2 3

    sage: exit

```

Once you exit sage, you can deactivate the environments, first the sage environment:

conda deactivate

then the main environment:

conda deactivate 

And exit the compute node with:

exit

You should also be able to run sage scripts with SLURM in batch mode:

Example script, test.sage:

var('x')
assume(x > 0)
print (bool(sqrt(x^2) == x))

Example SLURM script, run.slurm:

#!/bin/bash
#SBATCH --job-name=sage_job
#SBATCH --qos=normal
#SBATCH --partition=normal

#SBATCH --output=sage_job-%j.out
#SBATCH --error=sage_job-%j.err

#SBATCH --nodes=1
#SBATCH --cpus-per-task=12

#SBATCH --mem=10G
#SBATCH --time=0-00:30:00

#Load needed modules/activate environment
module load gnu10 openmpi
source miniconda/bin/activate
conda activate sage


#Execute
sage test.sage

Submit it with:

sbatch run.slurm

and it will run in batch mode on the requested resources in the SLURM script. The outputs for this test script will be in the .out file and any error messages will be in the .err file.