Running qsub with anaconda environment
Asked Answered
T

4

7

I have a program that usually runs inside a conda environmet in Linux, because I use it to manage my libraries, with this instructions:

source activate my_environment
python hello_world.py

How can I run hello_world.py in a high computer that works with PBS. Instructions explains to run adapting the code script.sh, shown below, and calling with the instruction qsub.

# script.sh
#!/bin/sh
#PBS -S /bin/sh
#PBS -N job_example
#PBS -l select=24
#PBS -j oe
cd $PBS_O_WORKDIR
mpiexec ./programa_mpi

How do I run hello_world.py with qsub using my anaconda environment?

Tymothy answered 16/11, 2018 at 22:18 Comment(0)
U
0

You'll need to load the Python module before activating your environment and before running your script.

module load python3

cd $PBS_O_WORKDIR
source activate my_environment

mpiexec python hello_world.py

Check the documentation for your institution regarding their Python modules. At my institution, Anaconda was the environment module for Python3, so you could load it as I have shown.

Unpolitic answered 26/2, 2019 at 19:46 Comment(4)
what do you mean by python module?Clown
@Ghanem, I mean module load python3. On supercomputers, Python isn't enabled automatically, so you need to enable the version of Python or Matlab or whatever in your PBS script. Loading that module makes that version of Python your default when your Python script is run.Unpolitic
Ok, @HS-nebula , could have a look here: https://stackoverflow.com/questions/56871054/force-shell-to-use-python-from-conda-variable-in-sungrid-engine , I have a similar issue.Clown
@Ghanem can you reformat your comment so that it's a link? I can try, but I've never user SunGrid Engine.Unpolitic
W
1

Unless it is in the environment by default, one also needs to "load" conda as well, inside the SGE(qsub) script (similar thing would hold for a slurm script too I assume). For example I had installed conda to the directory seen below in the SGE script, so I export the path (if conda is installed as a module on an HPCC, then simply load that instead):

#!/bin/bash
#$ -q compute
#$ -l compute
#$ -cwd
#$ -N name
#$ -j yes

export PATH=$HOME/miniconda3/bin:$PATH

source activate my_environment

environment function code...
Whitney answered 25/7, 2021 at 15:17 Comment(0)
U
0

You'll need to load the Python module before activating your environment and before running your script.

module load python3

cd $PBS_O_WORKDIR
source activate my_environment

mpiexec python hello_world.py

Check the documentation for your institution regarding their Python modules. At my institution, Anaconda was the environment module for Python3, so you could load it as I have shown.

Unpolitic answered 26/2, 2019 at 19:46 Comment(4)
what do you mean by python module?Clown
@Ghanem, I mean module load python3. On supercomputers, Python isn't enabled automatically, so you need to enable the version of Python or Matlab or whatever in your PBS script. Loading that module makes that version of Python your default when your Python script is run.Unpolitic
Ok, @HS-nebula , could have a look here: https://stackoverflow.com/questions/56871054/force-shell-to-use-python-from-conda-variable-in-sungrid-engine , I have a similar issue.Clown
@Ghanem can you reformat your comment so that it's a link? I can try, but I've never user SunGrid Engine.Unpolitic
C
0

If your really need your conda environment you can activate it in the script

source ~/.bashrc #configures your shell to use conda activate
conda activate your_env_name
Cowslip answered 7/11, 2021 at 12:0 Comment(0)
L
0

source ~/.bashrc

conda activate your_environment

cd $PBS_O_WORKDIR

Lyndes answered 25/6, 2023 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.