Oscar: Sage
Loading and Launching Sage
1. Once authenticated to Oscar, use the following commands at the command line.
2. Start an interactive job by using the interact
command. This command can take additional parameters to extend the resources and time allotted to the node as well as the partition that the node operates on.
3. The Sage module provides containers. To load them use module load sage-container/10.3
.
4. To start the container use apptainer shell /oscar/rt/9.2/software/0.20-generic/0.20.1/opt/spack/linux-rhel9-x86_64_v3/gcc-11.3.1/sage-container-10.3-avpqipfsnbneig726l72jrgdmlrivg4m/sage.sif
5. Once inside the container's shell use sage
to launch the Sage console.
Sage on Oscar OnDemand
The easiest way to run Sage on Oscar OcDemand is to run sage in an interactive job via the terminal in your OnDemand session.
Use the interact command with parameters for your specific job to start the interactive session, then load your modules and run the sage binary (steps 2-4 above).
interact -n 2 -m 32g -t 04:00:00 -f 'haswell|broadwell|skylake'
Using Sage with Batch Scripts
Thanks to Trevor Hyde from Summer@ICERM 2019 for these instructions.
One method for running computations with Sage on Oscar is to write a script and use the slurm batch scheduler to have Oscar run your script. This requires two pieces:
-
A shell script to configure and submit your batch job to the cluster.
-
Your Sage code/program you'd like to run.
Example Batch Script
- sage-batch.sh
#!/bin/bash
#SBATCH -J test_program
#SBATCH --array=0-9
#SBATCH -t 1:00:00
#SBATCH --mem=8G
#SBATCH -e data/<oscar-username>/test_output/test%a.err
#SBATCH -o data/<oscar-username>/test_output/test%a.out
module load sage-container/10.3
apptainer shell /oscar/rt/9.2/software/0.20-generic/0.20.1/opt/spack/linux-rhel9-x86_64_v3/gcc-11.3.1/sage-container-10.3-avpqipfsnbneig726l72jrgdmlrivg4m/sage.sif
sage test_program.sage $SLURM_ARRAY_TASK_ID
-
#!/bin/bash
tells the system this is a bash (shell) script. -
#SBATCH -J test_program
sets the name of the job which appears when you check the status of your jobs. -
#SBATCH –array=0-9
is an easy way of doing parallel computations. In this case it says our job will run on 10 different nodes, each node will be passed a parameter and we have specified that the parameters will take the values 0 through 9. You can specify several ranges or even list individual parameters if you prefer. -
#SBATCH -t 1:00:00
specifies a time limit inHH:MM:SS
for each node. Once this time runs out your program will stop running on that node. Be careful setting the time limit too high as doing so may make it take a long time for your job to get scheduled to run. Before starting a big computation try to do some smaller tests to see how long you expect to need. -
#SBATCH –mem=8G
specifies how much memory each node gets. Standard exploratory accounts get 123GB total to use at any one time. So if you allocate too much per job, fewer jobs will run at once. On the other hand, if you allocate too little and a computation needs more than it has, then it will terminate. If this happens an “out of memory” error will show up in the.err
file for that node. -
#SBATCH -e data/<ccv-username>/test_output/test%a.err
and#SBATCH -o data/<ccv-username>/test_output/test%a.out
specify where the error messages and output for each computation should be sent. You should store these files in your user folder, not on the submit node. We each have a folder inside thedata
directory which you can see from the submit node. In this example I have created a folder titledtest_output
where I’m putting both of these files. You need to make these folders before you run the computation otherwise the output will be dumped into the void! The%a
will get replaced with the array parameter. So for example, since we set our array parameters to be0-9
there will be 10 nodes running and each of them gets a number between 0 and 9; this node corresponding to the parameter 7 will create two filestest7.err
andtest7.out
. -
module load sage-container/10.3
loads the sage container into the node. apptainer shell /oscar/rt/9.2/software/0.20-generic/0.20.1/opt/spack/linux-rhel9-x86_64_v3/gcc-11.3.1/sage-container-10.3-avpqipfsnbneig726l72jrgdmlrivg4m/sage.sif
initiates the container's Sage console shell.
Everything after this in the script happens as if you typed it yourself onto the command line.
-
In our example, we want to run sage code, so the line
sage test_program.sage $SLURM_ARRAY_TASK_ID
runs our example sage programtest_program.sage
. -
The file needs to have the
.sage
extension. -
You should write this file in a text editor, not in a Jupyter notebook (although you can first write and test your program in a Jupyter notebook and then copy and paste it into a new file when it’s ready).
-
This program is written to accept one input and I have passed it
$SLURM_ARRAY_TASK_ID
which is the array parameter passed to each node. You can use this parameter to select which input parameters to run your program on.
Example Sage Program
- test_program.sage
import sys
def fun_math(message):
print message
sys.stdout.flush()
job_id = int(sys.argv[1])
fun_math('hi this is a test')
fun_math('my job id is' + str(job_id))
-
In the Sage program, you first define all of your functions and then you include the code you want to run.
-
Import
sys
so you can access the array parameter passed to your function from the node. This is accessed in this case bysys.argv[1]
. Make sure you explicitly coerce to be an integer if you want to use it as an integer; it's a string by default. -
The output of the
print
command is appended to the.out
file for this node as a new line. -
Notice the line
sys.stdout.flush()
included in the function. This makes the program immediately send whatever output it has to the output file when called. Otherwise the program won’t output anything until it has completely finished running. If each node is running 100 potentially long computations and it finishes the first 99 but then times out on the 100th computation, and you don’t include anysys.stdout.flush()
commands, everything will be lost when time runs out.
Submitting the Batch Job
-
To run this batch program go back to the submit node and type
sbatch <NAME_OF_BATCH_FILE>
. In our example here, our batch file is calledsage-batch.sh
, so we simply typesbatch sage-batch.sh
Slurm will return a line that tells you your job has been submitted together with a job id number. -
To check the progress of your jobs type
myq
from anywhere on Oscar. This will show you what jobs you have running, how much time they have left, and which jobs are still waiting to run. Be patient, sometimes it takes a minute for things to get started. -
If you realize your code is never going to finish or that you’ve made some terrible mistake, you can cancel a batch job by typing
scancel <JOB_ID>
. You can specify a single node or just put the general job id for the whole run and cancel everything.