Skip to content

Commit 9d17181

Browse files
committed
testing
1 parent 8fafc90 commit 9d17181

1 file changed

Lines changed: 0 additions & 197 deletions

File tree

docs/hpc/09_ood/02_jupyter_with_conda_singularity.mdx

Lines changed: 0 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -6,200 +6,3 @@ 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-
```sh
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-
```sh
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-
```
117-
118-
Now use either conda or pip to install your required python packages to the Miniforge environment.
119-
120-
To install larger packages, like Tensorflow, you must first start an interactive job with adequate compute and memory resources to install packages. The login nodes restrict memory to 2GB per user, which may cause some large packages to crash.
121-
```bash
122-
Singularity> exit
123-
124-
[NetID@log-1 my_env]$ srun --cpus-per-task=2 --mem=10GB --time=04:00:00 --pty /bin/bash
125-
126-
# wait to be assigned a node
127-
128-
[NetID@cm001 my_env]$ 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
129-
130-
Singularity> source /ext3/env.sh
131-
# activate the environment
132-
```
133-
134-
After it is running, you’ll be redirected to a compute node. From there, run singularity to setup on conda environment, same as you were doing on login node.
135-
136-
### Configure iPython Kernels
137-
To create a kernel named my_env copy the template files to your home directory.
138-
```bash sh
139-
Singularity> mkdir -p ~/.local/share/jupyter/kernels
140-
Singularity> cd ~/.local/share/jupyter/kernels
141-
Singularity> cp -R /share/apps/mypy/src/kernel_template ./my_env # this should be the name of your Singularity env
142-
Singularity> cd ./my_env
143-
144-
Singularity> ls
145-
#kernel.json logo-32x32.png logo-64x64.png python # files in the ~/.local/share/jupyter/kernels directory
146-
```
147-
148-
To set the conda environment, edit the file named `python` in `/.local/share/jupyter/kernels/my_env/`.
149-
150-
The python file is a wrapper script that the Jupyter notebook will use to launch your Singularity container and attach it to the notebook.
151-
152-
At the bottom of the file we have the template singularity command.
153-
```bash
154-
singularity exec $nv \
155-
--overlay /scratch/$USER/my_env/overlay-15GB-500K.ext3:ro \
156-
/scratch/work/public/singularity/cuda12.3.2-cudnn9.0.0-ubuntu-22.04.4.sif \
157-
/bin/bash -c "source /ext3/env.sh; $cmd $args"
158-
```
159-
:::warning
160-
If you used a different overlay (/scratch/$USER/my_env/overlay-15GB-500K.ext3 shown above) or .sif file (/scratch/work/public/singularity/cuda12.3.2-cudnn9.0.0-ubuntu-22.04.4.sif shown above), you MUST change those lines in the command above to the files you used.
161-
:::
162-
163-
Edit the default `kernel.json` file by setting PYTHON_LOCATION and KERNEL_DISPLAY_NAME using a text editor like nano/vim.
164-
```json
165-
{
166-
"argv": [
167-
"PYTHON_LOCATION",
168-
"-m",
169-
"ipykernel_launcher",
170-
"-f",
171-
"{connection_file}"
172-
],
173-
"display_name": "KERNEL_DISPLAY_NAME",
174-
"language": "python"
175-
}
176-
```
177-
to
178-
```json
179-
{
180-
"argv": [
181-
"/home/<Your NetID>/.local/share/jupyter/kernels/my_env/python",
182-
"-m",
183-
"ipykernel_launcher",
184-
"-f",
185-
"{connection_file}"
186-
],
187-
"display_name": "my_env",
188-
"language": "python"
189-
}
190-
```
191-
Update the `"<Your NetID>"` to your own NetID without the `"<>"` symbols.
192-
193-
### Launch an OOD Jupyter Notebook
194-
[https://ood.hpc.nyu.edu](https://ood.hpc.nyu.edu)
195-
196-
![OOD Launch](./static/ood_launch.png)
197-
198-
### Configure and Launch your Notebook
199-
200-
![Configure Notebook](./static/configure_notebook.png)
201-
202-
### Select kernel
203-
Once configured and launched, kernels can be selected in the "New" dropdown or within the notebook under the kernel menu. Please note that your notebook view may look slightly different depending on available directories and environments, as well as if you choose the lab or traditional notebook view.
204-
205-
![Select Kernel](./static/select_kernel.png)

0 commit comments

Comments
 (0)