Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:services:application_services:high_performance_computing:ipython_parallel [2019/02/15 09:51] – akhuziy | en:services:application_services:high_performance_computing:ipython_parallel [2025/02/19 16:28] (current) – nboelte | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Parallel execution of Jupyter notebooks on the cluster ====== | ||
+ | This documentation is based on the IPython example used in our [[en: | ||
+ | |||
+ | When submitting that image, please add the -B option of singularity for mounting the /opt folder: | ||
+ | |||
+ | < | ||
+ | srun --pty -p jupyter apptainer shell -B /opt sjupyter.sif | ||
+ | </ | ||
+ | |||
+ | To be able to run Slurm commands within the container, additional libraries and directories should be bound into the container: | ||
+ | |||
+ | < | ||
+ | apptainer -B / | ||
+ | </ | ||
+ | |||
+ | Also you need to add //slurm// user to the container when building the image, with following commands: | ||
+ | < | ||
+ | echo " | ||
+ | echo " | ||
+ | </ | ||
+ | |||
+ | For using IPython Parallel with the cluster, we need to configure it. These steps are required only once, everything will be kept in your '' | ||
+ | |||
+ | To create a new profile and configure it for the compute cluster, run following command: | ||
+ | |||
+ | < | ||
+ | ipython profile create --parallel --profile=myslurm | ||
+ | </ | ||
+ | |||
+ | This will create the profile at '' | ||
+ | |||
+ | Add following config lines to the file '' | ||
+ | |||
+ | < | ||
+ | c.IPClusterEngines.engine_launcher_class = ' | ||
+ | c.IPClusterStart.controller_launcher_class = ' | ||
+ | c.SlurmControllerLauncher.batch_template_file =' | ||
+ | c.SlurmEngineSetLauncher.batch_template_file = ' | ||
+ | </ | ||
+ | and comment out the following parameters: | ||
+ | < | ||
+ | # | ||
+ | # | ||
+ | </ | ||
+ | |||
+ | Add the following line to '' | ||
+ | |||
+ | < | ||
+ | c.HubFactory.ip = ' | ||
+ | </ | ||
+ | |||
+ | IPython Parallel is almost ready to use. For submitting Slurm jobs in a specific queue and with additional parameters, create templates for batch jobs in the directory you want to start the container using the names specified in the configuration file, i.e. '' | ||
+ | |||
+ | slurm.controller.template: | ||
+ | |||
+ | < | ||
+ | #!/bin/bash | ||
+ | |||
+ | #SBATCH -p medium | ||
+ | #SBATCH -J ipcontroller | ||
+ | #SBATCH -o jupyterhub-gwdg/ | ||
+ | #SBATCH -n 1 | ||
+ | #SBATCH -t 1:00:00 | ||
+ | |||
+ | module load apptainer | ||
+ | apptainer exec sjupyter.sif ipcontroller --profile-dir={profile_dir} --location=$HOSTNAME | ||
+ | </ | ||
+ | |||
+ | slurm.engine.template: | ||
+ | |||
+ | < | ||
+ | #!/bin/bash | ||
+ | |||
+ | #SBATCH -p medium | ||
+ | #SBATCH -J ipengine | ||
+ | #SBATCH -n {n} | ||
+ | #SBATCH -o jupyterhub-gwdg/ | ||
+ | #SBATCH -t 1:00:00 | ||
+ | |||
+ | module load apptainer | ||
+ | srun apptainer exec sjupyter.sif ipengine --profile-dir={profile_dir} | ||
+ | </ | ||
+ | |||
+ | Now you can launch a jupyter instance: | ||
+ | |||
+ | < | ||
+ | jupyter notebook --port < | ||
+ | </ | ||
+ | |||
+ | For '' | ||
+ | |||
+ | < | ||
+ | ssh -L 0.0.0.0:< | ||
+ | </ | ||
+ | |||
+ | For '' | ||
+ | |||
+ | To start the cluster, use the IPython Clusters tab in the Jupyter interface, select the myslurm profile and amount of processes and click **start**. You will be able to see the engines running with the " | ||
+ | |||
+ | To test if it is working, simply run following script in the Jupyter notebook: | ||
+ | |||
+ | < | ||
+ | import ipyparallel as ipp | ||
+ | c = ipp.Client(profile=" | ||
+ | c.ids | ||
+ | c[: | ||
+ | </ |