I have a python code I want to execute in a HCP so I need to use arrays of jobs using sbatch. I have never used that so I am both trying to understand how it works (to use it in my future works adapted to the necesities) and to use it now in the current code I am working on.
As my problem was very similar to the one proposed in #21124 (Example Code for Batch (analyzing multiple suibjects)), I followed the same steps proposed:
- Create the submission script (submit_job_array.sh):
Which I adapted to my case by writing the directory that contained all the folders of my subjects instead of$DIRECTORY_WHERE_SUBJECT_FOLDERS_ARE
and changed the partsubjs=($(ls sub*/ -d))
forsubjs=($(ls [0-9]*/ -d))
because I only wanted my subjects which are only numbers and there where other files in that directory that I did not want. - I create the script that calls python for the subject (run_python_single_subject.sh). I changed
$YOUR_PYTHON_FUNCTION.py
for my python projects directory and the header to:
#SBATCH --job-name=test_job
#SBATCH --output=res_test_job_%A_%a.txt
#SBATCH --partition= normal, gpu
#SBATCH --gpus=1
#SBATCH --cpus-per-gpu=8
#SBATCH --error error_%A_%a.out
- I added to my pyhton file the header from indicated and then changed the passing argument to sub.
However, when I run sbatch #PATH_OF_submit_job_array.sh I obtain an slurm-JOBID.out with an error: Batch job submission failed: Invalid job array specification.
My current python code structure is the following:
- Declaration of libraries used
- Definition of functions to read certain files of the subjects (I pass the subject number and it generates the path to the file)
- Definition of a function of the model which receives as input the subject directory. (The function is called: MAPMRI_SUBJECT(subjectdr))
- The main code, which is:
subjectdr = subject_directory(sub)
file_check = subjectdr + '/mask_subject.nii.gz'
if exists(file_check) == True:
print('Subject ' + str(sub) + ' has de correct files to proceed.')
MAPMRI_SUBJECT(subjectdr)
else:
print('Subject ' + str(sub) + ' does not have the needed files.')
which goes through every subject in the subjs list, but it passes to the code one subject number given by the sub variable, at the time. and I do not understand why I receive an error