Skip to content

Commit 7ba5e54

Browse files
committed
testing
1 parent 9d17181 commit 7ba5e54

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

docs/hpc/09_ood/02_jupyter_with_conda_singularity.mdx

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,111 @@ This page describes how to use your Singularity with conda environment in OOD GU
66
### Log Into Greene via the Terminal
77
The following commands must be run from the terminal. Information on accessing via the terminal can be found at [Connecting to the HPC](../02_connecting_to_hpc/01_connecting_to_hpc.mdx) or you can log into OOD and select the `Clusters` tab at the top of the page and select `Greene Shell Access`.
88

9+
### Preinstallation Warning
10+
:::warning
11+
If you have initialized Conda in your base environment, your prompt on Greene may show something like:
12+
```bash
13+
(base) [NetID@log-1 ~]$
14+
```
15+
then you must first comment out or remove this portion of your `~/.bashrc` file:
16+
17+
```bash
18+
# >>> conda initialize >>>
19+
# !! Contents within this block are managed by 'conda init' !!
20+
__conda_setup="$('/share/apps/anaconda3/2020.07/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
21+
if [ $? -eq 0 ]; then
22+
eval "$__conda_setup"
23+
else
24+
if [ -f "/share/apps/anaconda3/2020.07/etc/profile.d/conda.sh" ]; then
25+
. "/share/apps/anaconda3/2020.07/etc/profile.d/conda.sh"
26+
else
27+
export PATH="/share/apps/anaconda3/2020.07/bin:$PATH"
28+
fi
29+
fi
30+
unset __conda_setup
31+
# <<< conda initialize <<<
32+
```
33+
34+
The above code automatically makes your environment look for the default shared installation of Conda on the cluster and will sabotage any attempts to install packages to a Singularity environment. Once removed or commented out, log out and back into the cluster for a fresh environment.
35+
:::
36+
37+
### Prepare Overlay File
38+
```bash
39+
[NetID@log-1 ~]$ mkdir /scratch/$USER/my_env
40+
[NetID@log-1 ~]$ cd /scratch/$USER/my_env
41+
[NetID@log-1 my_env]$ cp -rp /scratch/work/public/overlay-fs-ext3/overlay-15GB-500K.ext3.gz .
42+
[NetID@log-1 my_env]$ gunzip overlay-15GB-500K.ext3.gz
43+
```
44+
Above we used the overlay file `overlay-15GB-500K.ext3.gz` which will contain all of the installed packages. There are more optional overlay files. You can find instructions on the following pages: [Singularity with Conda](../07_containers/03_singularity_with_conda.md), [Squash File System and Singularity](../07_containers/04_squash_file_system_and_singularity.md).
45+
46+
### Launch Singularity Environment for Installation
47+
```bash
48+
[NetID@log-1 ~]$ singularity exec --overlay /scratch/$USER/my_env/overlay-15GB-500K.ext3:rw /scratch/work/public/singularity/cuda12.3.2-cudnn9.0.0-ubuntu-22.04.4.sif /bin/bash
49+
```
50+
Above we used the Singularity OS image `cuda12.3.2-cudnn9.0.0-ubuntu-22.04.4.sif` which provides the base operating system environment for the conda environment. There are other Singularity OS images available at `/scratch/work/public/singularity`
51+
52+
Launching Singularity with the `--overlay` flag mounts the overlay file to a new directory: `/ext3` - you will notice that when not using Singularity `/ext3` is not available.
53+
54+
:::warning
55+
Be sure that you have the Singularity prompt (`Singularity>`) and that `/ext3` is available before the next step.
56+
```bash
57+
Singularity> ls -lah /ext3
58+
total 8.5K
59+
drwxrwxr-x. 2 root root 4.0K Oct 19 10:01 .
60+
drwx------. 29 root root 8.0K Oct 19 10:01 ..
61+
```
62+
:::
63+
64+
### Install Miniforge to Overlay File
65+
```bash
66+
Singularity> wget --no-check-certificate https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
67+
Singularity> sh Miniforge3-Linux-x86_64.sh -b -p /ext3/miniforge3
68+
```
69+
Next, create a wrapper script at `/ext3/env.sh`:
70+
```bash
71+
Singularity> touch /ext3/env.sh
72+
Singularity> echo '#!/bin/bash' >> /ext3/env.sh
73+
Singularity> echo 'unset -f which' >> /ext3/env.sh
74+
Singularity> echo 'source /ext3/miniforge3/etc/profile.d/conda.sh' >> /ext3/env.sh
75+
Singularity> echo 'export PATH=/ext3/miniforge3/bin:$PATH' >> /ext3/env.sh
76+
Singularity> echo 'export PYTHONPATH=/ext3/miniforge3/bin:$PATH' >> /ext3/env.sh
77+
```
78+
Your `/ext3/env.sh` file should now contain the following:
79+
```bash
80+
#!/bin/bash
81+
unset -f which
82+
source /ext3/miniforge3/etc/profile.d/conda.sh
83+
export PATH=/ext3/miniforge3/bin:$PATH
84+
export PYTHONPATH=/ext3/miniforge3/bin:$PATH
85+
```
86+
The wrapper script will activate your conda environment, to which you will be installing your packages and dependencies.
87+
88+
Next, activate your conda environment with the following:
89+
```bash
90+
Singularity> source /ext3/env.sh
91+
```
92+
93+
### Install Packages to Miniforge Environment
94+
Now that your environment is activated, you can update and install packages:
95+
```bash
96+
Singularity> conda config --remove channels defaults
97+
Singularity> conda update -n base conda -y
98+
Singularity> conda clean --all --yes
99+
Singularity> conda install pip --yes
100+
Singularity> conda install ipykernel --yes # Note: ipykernel is required to run as a kernel in the Open OnDemand Jupyter Notebooks
101+
```
102+
To confirm that your environment is appropriately referencing your Miniforge installation, try out the following:
103+
```bash
104+
Singularity> unset which
105+
Singularity> which conda
106+
# output: /ext3/miniforge3/bin/conda
107+
108+
Singularity> which python
109+
# output: /ext3/miniforge3/bin/python
110+
111+
Singularity> python --version
112+
# output: Python 3.12.9
113+
114+
Singularity> which pip
115+
# output: /ext3/miniforge3/bin/pip
116+
```

0 commit comments

Comments
 (0)