Running CDSAPI on Shaheen as container job

With changes in Shaheen programming environment, it is sometimes necessary to upgrade python and its dependencies. This implies that all the packages depending on python will also need updating. Conda environment are good up an alternative package management strategy which freezes the runtime environment is containers. This container image should work on Shaheen, Ibex or Neser.

Running rootless containers on Shaheen is easy. Here is an example of cdsapi container which KSL team has created and uploaded in the DockerHub registry for our users.

Pull the Image

Before you run cdsapi as a container job Shaheen, first pull the image on Shaheen filesystem:

cd /scratch/$USER module load singularity singularity pull docker://krccl/cdsapi:0.5.1

 

The above should produce a file named cdsapi_0.5.1.sif

 

CDSAPI key file

Create an API Key file needed by cdsapi as you identity for the remote repositories to recognise your account. The API key can be generated by creating an account using the following instruction: https://cds.climate.copernicus.eu/api-how-to

Copy the url and API key and paste in the file /scratch/$USER/cdsapi_rc

Running container job on compute node as batch job

Here is a jobscript that runs cdsapi as a batch job on Shaheen compute node:

#!/bin/bash #SBATCH --nodes=1 #SBATCH --time=00:10:00 module load singularity export IMAGE=./cdsapi_0.5.1.sif export SINGULARITYENV_CDSAPI_RC=$PWD/cdsapi_key srun singularity exec $IMAGE python test.py

Where test.py looks as follows:

import cdsapi c = cdsapi.Client() c.retrieve("reanalysis-era5-pressure-levels", { "variable": "temperature", "pressure_level": "1000", "product_type": "reanalysis", "year": "2008", "month": "01", "day": "01", "time": "12:00", "format": "grib" }, "download.grib")

Running container job on compute node as interactive job

Similar to the batch job as above, you can run the contents of test.py in your python interpreter within a container:

First allocate an interactive job

salloc -p debug
salloc: Pending job allocation 27956089 salloc: job 27956089 queued and waiting for resources salloc: job 27956089 has been allocated resources salloc: Granted job allocation 27956089

Then jump on the compute node allocated to you:

srun --pty bash

Load the environment

module load singularity export SINGULARITYENV_CDSAPI_RC=$PWD/cdsapi_key

Run Singularity shell

singularity shell ./cdsapi_0.5.1.sif

The above will put you in a container environment where the Python and CDSAPI are available. You can run your python script interactively step by step:

Singularity> python Python 3.8.0 (default, Dec 9 2021, 17:53:27) [GCC 8.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cdsapi >>> c = cdsapi.Client() >>> c.retrieve("reanalysis-era5-pressure-levels", ... { ... "variable": "temperature", ... "pressure_level": "1000", ... "product_type": "reanalysis", ... "year": "2008", ... "month": "01", ... "day": "01", ... "time": "12:00", ... "format": "grib" ... }, "download.grib") 2022-10-02 16:24:56,133 INFO Welcome to the CDS 2022-10-02 16:24:56,133 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/reanalysis-era5-pressure-levels 2022-10-02 16:24:56,434 INFO Request is completed 2022-10-02 16:24:56,434 INFO Downloading https://download-0013-clone.copernicus-climate.eu/cache-compute-0013/cache/data6/adaptor.mars.internal-1664160723.1706429-22753-13-aed26f41-fde5-4c0a-9b64-c5d9312e0966.grib to download.grib (2M) 2022-10-02 16:25:02,285 INFO Download rate 346.6K/s Result(content_length=2076600,content_type=application/x-grib,location=https://download-0013-clone.copernicus-climate.eu/cache-compute-0013/cache/data6/adaptor.mars.internal-1664160723.1706429-22753-13-aed26f41-fde5-4c0a-9b64-c5d9312e0966.grib) >>> exit

To exit the container

Singularity> exit exit shaima0d@nid00008:/scratch/shaima0d/tickets/43489> exit exit shaima0d@gateway1:/scratch/shaima0d/tickets/43489> exit exit salloc: Relinquishing job allocation 27956089 salloc: Job allocation 27956089 has been revoked.

Please feel free to comment on the page.

Happy hunting