Python: Difference between revisions

169 bytes added ,  6 months ago
Marked this version for translation
(Added virtual env. creation on multiple nodes)
(Marked this version for translation)
Line 250: Line 250:
Note that the above instructions require all of the packages you need to be available in the python wheels that we provide (see "Available wheels" below). If the wheel is not available in our wheelhouse, you can pre-download it (see "Pre-downloading packages" section below). If you think that the missing wheel should be included in our wheelhouse, please contact [[Technical support]] to make a request.
Note that the above instructions require all of the packages you need to be available in the python wheels that we provide (see "Available wheels" below). If the wheel is not available in our wheelhouse, you can pre-download it (see "Pre-downloading packages" section below). If you think that the missing wheel should be included in our wheelhouse, please contact [[Technical support]] to make a request.


==== Creating virtual environments inside of your jobs (multi-nodes) ====
==== Creating virtual environments inside of your jobs (multi-nodes) ==== <!--T:102-->


<!--T:103-->
In order to run scripts accross multiple nodes, each nodes must have it own virtual environment activated.
In order to run scripts accross multiple nodes, each nodes must have it own virtual environment activated.


<!--T:104-->
1. In your submission script, create the virtual environment on each allocated nodes :
1. In your submission script, create the virtual environment on each allocated nodes :
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
srun --ntasks $SLURM_NNODES --tasks-per-node=1 bash << EOF
srun --ntasks $SLURM_NNODES --tasks-per-node=1 bash << EOF


<!--T:105-->
virtualenv --no-download $SLURM_TMPDIR/env
virtualenv --no-download $SLURM_TMPDIR/env
source $SLURM_TMPDIR/env/bin/activate
source $SLURM_TMPDIR/env/bin/activate


<!--T:106-->
pip install --no-index --upgrade pip
pip install --no-index --upgrade pip
pip install --no-index -r requirements.txt
pip install --no-index -r requirements.txt


<!--T:107-->
EOF
EOF
</syntaxhighlight>
</syntaxhighlight>


<!--T:108-->
2. Activate the virtual environment on the main node
2. Activate the virtual environment on the main node
<syntaxhighlight lang="bash">source $SLURM_TMPDIR/env/bin/activate;</syntaxhighlight>
<syntaxhighlight lang="bash">source $SLURM_TMPDIR/env/bin/activate;</syntaxhighlight>


<!--T:109-->
3. Use <tt>srun</tt> to run your script
3. Use <tt>srun</tt> to run your script
<syntaxhighlight lang="bash">srun python myscript.py;</syntaxhighlight>
<syntaxhighlight lang="bash">srun python myscript.py;</syntaxhighlight>


==== Example (multi-nodes) ====
==== Example (multi-nodes) ==== <!--T:110-->
{{File
{{File
   |name=submit-nnodes-venv.sh
   |name=submit-nnodes-venv.sh
Line 286: Line 293:
#SBATCH --mem-per-cpu=2000M
#SBATCH --mem-per-cpu=2000M


<!--T:111-->
module load StdEnv/2023 python/3.11 mpi4py
module load StdEnv/2023 python/3.11 mpi4py


<!--T:112-->
# create the virtual environment on each node :  
# create the virtual environment on each node :  
srun --ntasks $SLURM_NNODES --tasks-per-node=1 bash << EOF
srun --ntasks $SLURM_NNODES --tasks-per-node=1 bash << EOF
Line 293: Line 302:
source $SLURM_TMPDIR/env/bin/activate
source $SLURM_TMPDIR/env/bin/activate


<!--T:113-->
pip install --no-index --upgrade pip
pip install --no-index --upgrade pip
pip install --no-index -r requirements.txt
pip install --no-index -r requirements.txt
EOF
EOF


<!--T:114-->
# activate only on main node                                                               
# activate only on main node                                                               
source $SLURM_TMPDIR/env/bin/activate;
source $SLURM_TMPDIR/env/bin/activate;
cc_staff
284

edits