--- title: Apptainer --- [toc] ## Environment Settings{#enviroment} ### Software Version and System Requirements{#version} The Apptainer shown in the table below is available. As it is provided as a package that comes with the operating system, there is no need to set the environment with module files. |Version | Module File Name | System B/C | System G | Cloud System | Note |--- | --- | --- | --- | --- | --- |1.1.2 | none | + | + | + | Former name:singularity \+ : Available for all users \- : Not available ## How to Use{#usage} 1. Create a job script (`test.sh`) to run a program (`a.out`) that performs hybrid parallelism, using a container image called `ubuntu.sif`. ```nohighlight #!/bin/bash #============ Slurm Options #SBATCH -p gr19999b # Specify the job queue (partition). The name of the queue to be submitted needs to be changed accordingly. #SBATCH -t 1:00:00 # Specify the elapsed time (example: to specify one hour). #SBATCH --rsc p=2:c=40 # Specifying the required resources (example: hybrid parallel using 2 processes and 40 cores). #SBATCH -o %x.%j.out # Specify the standard output file of the job. %x is replaced by the job name and %j by the job ID. #============ Shell Script ============ set -x ## When you do not use GPU srun apptainer exec --bind `pwd`,/opt/system,/usr/lib64 --env LD_LIBRARY_PATH=/usr/lib64 ubuntu.sif ./a.out ## When you use GPU (Adding --nv makes it GPU-compatible.) srun apptainer exec --nv --bind `pwd`,/opt/system,/usr/lib64 --env LD_LIBRARY_PATH=/usr/lib64 ubuntu.sif ./a.out ``` #### Main Option |Option | Meaning | Example |---------- | ----------- | ----------- | | --bind _MOUNT\_DIR_ | Specify the to mount.| --bind /LARGE0,LARGE1,/opt/system,/usr/lib64 | | --env _ENVIRONMENT_ | Specify the environment variables | --env LD_LIBRARY_PATH=/usr/lib64 | | --nv | Add when you use GPU.| --nv | 2. Job submission using the job script created in 1. ```nohighlight $ sbatch test.sh Submitted batch job {jobid} ``` 3. Confirmation of execution results . ```nohighlight $ cat test.sh.{jobid}.out ================ Slrum Info ================ DATE = 2023-03-08T14:38:10+09:00 PARTITION = gr19999d JOB_ID = {jobid} JOB_NAME = test.sh NNODES = 1 RSC_OPT = p=1:t=8:c=8:m=8G ============================================ _________ < hello!! > --------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || ``` ## How to create container images ### Create a new container image for Apptainer (Singurarity) Here, we use the ubuntu22.04 docker image as the base package and create a container image of python3 and tensorflow installed. 1. Create a recipe file to generate the container and save it as `ubuntu22_tensorflow.def`. ```nohighlight Bootstrap: docker From: ubuntu:22.04    %post apt-get update apt-get install -y python3 python3-pip pip3 install tensorflow ``` 2. Execute a build of the container image using the recipe file (`ubunutu22_tensorflow.def`) generated in 1.The container image is saved as `ubuntu22_tensorflow.sif`. ```nohighlight $ apptainer build --fakeroot {Container image storage location} {Recipe files for generating container images.}   (Example) $ apptainer build --fakeroot ~/ubuntu22_tensorflow.sif ubuntu22_tensorflow.def INFO: Starting build... Getting image source signatures (snip) INFO: Creating SIF file... INFO: Build complete: ubuntu22_tensorflow.sif ``` * The destination of the container image should be set under the home directory. If the destination is set to a large disk, the container image will fail to build. 3. Operation Check ```nohighlight ## Start the container. $ apptainer shell ~/ubuntu22_tensorflow.sif   ## Launch the Python 3 Apptainer> python3 Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.   ## Check the operation of Tensorflow >>> import tensorflow as tf >>> tf.__version__ '2.11.0' ``` ### Use the container images uploaded to DockerHub. 1. Translate to the directory where the Apptainer container image is stored. ```nohighlight $ cd container_image ``` 2. Download and build a container image from DockerHub ```nohighlight $ apptainer build lolcow.sif docker://godlovedc/lolcow INFO: Starting build... Getting image source signatures (snip) INFO: Creating SIF file... INFO: Build complete: lolcow.sif ``` * If "Build failed", please try building again. 3.Confirm that the container image has been created. ```nohighlight $ ls lolcow.sif lolcow.sif ```