Oscar: Sage
Loading and Launching Sage
1. OpenOnce theauthenticated Terminalto andOscar, 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. module load sage
to load the most recent version of Sage.
4. If your work requires an older version of Sage, use module load sage/9.
05 to load Sage. This command will return confirmation “module: loading 'sage/9.0'”.
3. Sage on Oscar usually has dependent modules. These will be output to your terminal when you load the Sage module similar to the example below.
[username@node ~]$ module load sage/9.0
module: loading 'sage/9.0'
module: sage: To use: module load gcc/8.3
4. Load any other dependent modules for Sage that were output in the above steps. These modules must be loaded in the specific order specified by the system when the Sage module is loaded. Loading them in a different order may cause Sage to throw errors.
For Sageversion 9.0: module load gcc/8.3
For Sage 8.7: module load gcc/8.3 sqlite/3.25.2 perl/5.24.1 libgd/2.2.5 mpfr/3.1.5 ffmpeg/4.0.1 imagemagick/7.0.7 texlive/2018
5. sage
to launch the Sage console within your Terminal window.
Sage on VNC
The Sage install may not always work properly on Oscar's VNC nodes due to the VNC nodes running older chipsets. The easiest way to remedy this issue is to run sage in an interactive job via the terminal in your VNC 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'
Installing Sage Packages Locally with --user
It is possible to install most Sage packages locally to your home folder by passing the the –user
parameter at the end of your install command. See below for example steps to install the Sage packages “surface_dynamics” and “sage-flatsurf”. In this example, we are loading both packages from git repositories, so we need to load the git module.
1. module load git
2. sage -pip install git+https://gitlab.com/videlec/surface_dynamics
–user
3. sage -pip install git+https://github.com/videlec/sage-flatsurf –user
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/8.7
module load gcc/8.3 sqlite/3.25.2 perl/5.24.1 libgd/2.2.5 mpfr/3.1.5 ffmpeg/4.0.1 imagemagick/7.0.7 texlive/2018
sage test_program.sage $SLURM_ARRAY_TASK_ID
-
#!/bin/bash
-
#SBATCH -J test_program
-
#SBATCH –array=0-9
-
#SBATCH -t 1:00:00
ininHH:MM:SS
-
#SBATCH –mem=8G
thethe.err
-
#SBATCH -e data/<ccv-username>/test_output/test%a.err
andand#SBATCH -o data/<ccv-username>/test_output/test%a.out
thethedata
titledtitledtest_output
TheThe%a
bebe0-9
filesfilestest7.err
andandtest7.out
. -
module load sage/8.7
-
module load gcc/8.3 sqlite/3.25.2 perl/5.24.1 libgd/2.2.5 mpfr/3.1.5 ffmpeg/4.0.1 imagemagick/7.0.7 texlive/2018
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
linelinesage test_program.sage $SLURM_ARRAY_TASK_ID
programprogramtest_program.sage
. -
The file needs to have
thethe.sage
-
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
itit$SLURM_ARRAY_TASK_ID
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.
-
ImportImportsys
bybysys.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
thetheprint
thethe.out
-
Notice the
linelinesys.stdout.flush()
outputoutput anythinganyanysys.stdout.flush()
Submitting the Batch Job
-
To run this batch program go back to the submit node and
typetypesbatch <NAME_OF_BATCH_FILE>
. In our example here, our batch file iscalledcalledsage-batch.sh
, so we simplytypetypesbatch sage-batch.sh
-
To check the progress of your jobs
typetypemyq
-
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
typingtypingscancel <JOB_ID>
. You can specify a single node or just put the general job id for the whole run and cancel everything.