toil icon indicating copy to clipboard operation
toil copied to clipboard

Allow loading HPC module system modules for Toil CWL jobs, possibly by preamble script

Open mpachkov opened this issue 9 years ago • 7 comments

Dear All,

I want to use toil/CWL to implement a pipeline to run on our SLURM cluster. It turned out that for proper working some modules should be loaded before toil.worker is called.

Jobs are submitted like this: "sbatch --wrap='.../_toil_worker ...", for our case I need this "sbatch --wrap='module load A; module load B; _toil_worker ...'". So it would be useful to have possibility to insert some commands before executing toil.worker.

I tried to use --preserve-environment option for toil-cwl-runner but there were no effect.

Best regards,

Mikhail

┆Issue is synchronized with this Jira Story ┆Issue Number: TOIL-213

mpachkov avatar Oct 24 '17 14:10 mpachkov

This would be useful to load some modules for the slurm batch jobs. I tried compiling a MPI program with toil --batchSystem=slurm, but it failed as I need to run at least module load intel impi on BSC MN5.

What I'm using at the moment is this:

toil-cwl-runner  \
	--batchSystem=slurm  \
	--slurmTime "00:10:00"  \
	--slurmPartition "debug"  \
	--slurmAllocateMem=False  \
	--slurmArgs="-A <PROJECT> \
	--nodes=1  \
	--ntasks=2  \
	--qos gp_debug"  \
	--retryCount 0  \
	--logLevel DEBUG  \
	--workDir `pwd`  \
	--outdir `pwd`  \
	--logFile cwltoil.log  \
	--maxLogFileSize 200000000  \
	--jobstore 001  \
	--bypass-file-store  \
	--caching false sr-workflow.cwl sr-workflow-srun-job.yml

And it's failing due to the missing impi module and the mpicc command. The only thing that's working for me is to load the module before, and include --preserve-entire-environment.

kinow avatar Mar 07 '26 21:03 kinow

I am running a simple workflow that does mpicc sr.c -o sr and then mpirun -np 6 ./sr. These steps run in Slurm, and need to have certain environment variables in MareNostrum5.

mpicc, for instance, only works if LD_LIBRARY_PATH and I_MPI_ROOT are kept (learned this carefully adding variables with cwltool.

However, the same command-line using --preserve-environment=LD_LIBRARY_PATH and --preserve-environment=I_MPI_ROOT doesn't work. I wrote this small CWL document to verify

cwlVersion: v1.2
class: CommandLineTool

baseCommand: [bash, -c]

inputs: []
outputs: []

arguments:
  - |
    hostname
    which mpicc
    mpicc -show
    env | sort

First, I launched the whole CWL workflow (mpicc + sr) in MN5 with an automation Makefile script, then executed this small probe.cwl file with similar arguments.

sbatch \
  --partition=gpp \
  --qos=A \
  --account=A \
  --time=00:10:00 --job-name=toil_mn5 --ntasks=10 --cpus-per-task=1 --export=ALL \
  --wrap="module load singularity/4.1.5; module load impi; toil-cwl-runner --no-container --logDebug --enable-ext --bypass-file-store --disable-streaming --retryCount 0 --mpi-config-file mpi-config-file.yml --preserve-environment=I_MPI_ROOT --preserve-environment=LD_LIBRARY_PATH probe.cwl"

That prints only

```bash
        gs14r3b26
        /gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/bin/mpicc
        gcc -I"I_MPI_SUBSTITUTE_INSTALLDIR/include" -L"I_MPI_SUBSTITUTE_INSTALLDIR/lib/release" -L"I_MPI_SUBSTITUTE_INSTALLDIR/lib" -Xlinker --enable-new-dtags -Xlinker -rpath -Xlinker "I_MPI_SUBSTITUTE_INSTALLDIR/lib/release" -Xlinker -rpath -Xlinker "I_MPI_SUBSTITUTE_INSTALLDIR/lib" -lmpifort -lmpi -lrt -lpthread -Wl,-z,now -Wl,-z,relro -Wl,-z,noexecstack -Xlinker --enable-new-dtags -ldl
        HOME=/scratch/tmp/41770107/tmpxdisy4h3
        PATH=...
        PWD=/scratch/tmp/41770107/tmpxdisy4h3
        SHLVL=0
        TMPDIR=/scratch/tmp/41770107/tmpn_y6c365
        _=/usr/bin/env

Both LD_LIBRARY_PATH and I_MPI_ROOT are not listed. If I use --preserve-entire-environment, then it works just fine. For this test I am actually avoiding using --preserve-entire-environment as I'm testing portability of workflows, so I will mark the execution as failure for now.

kinow avatar Jun 13 '26 22:06 kinow

I think we need to look at this issue carefully and possibly split it up.

We can let you run commands before the Toil worker, but that won't necessarily be sufficient to accomplish the underlying goal of having a module available to an (uncontainerized but still cwltool-managed) CWL CommandLineTool, if the right environment variables fro that module are not preserved and the right thing is not done with regard to containerization.

We also might be able to make sure that modules loaded on the leader are available on the workers without needing to have you inject extra module load commands into the job.

adamnovak avatar Aug 25 '26 20:08 adamnovak

@kinow Do you have any evidence that the problem you're having isn't just --preserve-environment being broken in toil-cwl-runner? I don't think we have tests for it, so it's possible that it has never worked, which I think we'd want to track as a separate issue.

In particular it looks like we might be clobbering it here: https://github.com/DataBiosphere/toil/blob/7bf1a0c1878d6660aa3cc5f8337a5dbf39cb67d2/src/toil/cwl/cwltoil.py#L3200

adamnovak avatar Aug 25 '26 20:08 adamnovak

The correct way to do this is https://cwltool.readthedocs.io/en/latest/#leveraging-softwarerequirements-beta which is already supported in Toil

mr-c avatar Aug 25 '26 21:08 mr-c

Hi.

I tried it again today, on MN5.

Using the same cwl document from my previous message. Just toil-cwl-runner, no args.

=========>
	glogin4
	/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/bin/mpicc
	gcc -I"I_MPI_SUBSTITUTE_INSTALLDIR/include" -L"I_MPI_SUBSTITUTE_INSTALLDIR/lib/release" -L"I_MPI_SUBSTITUTE_INSTALLDIR/lib" -Xlinke
r --enable-new-dtags -Xlinker -rpath -Xlinker "I_MPI_SUBSTITUTE_INSTALLDIR/lib/release" -Xlinker -rpath -Xlinker "I_MPI_SUBSTITUTE_INSTALLD
IR/lib" -lmpifort -lmpi -lrt -lpthread -Wl,-z,now -Wl,-z,relro -Wl,-z,noexecstack -Xlinker --enable-new-dtags -ldl
	HOME=/scratch/tmp/toilwf-550a1ba62fbf58d19983e7adac1c13f1/40c2/job/tmpbl0tl08v/tmp-outznmcn618
	PATH=/gpfs/projects/GROUP/USER/micromamba-envs/envs/toil/bin:/gpfs/projects/GROUP/USER/micromamba-envs//condabin:/home/bs
c/USER/.local/bin:/home/bsc/USER/bin:/apps/modules/bsc/bin:/apps/GPP/UCX/1.15.0/INTEL/bin:/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/
2021.10.0/libfabric/bin:/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/bin:/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/compiler/latest/linux/bin:/
gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/compiler/latest/linux/bin/intel64:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
	PWD=/scratch/tmp/toilwf-550a1ba62fbf58d19983e7adac1c13f1/40c2/job/tmpbl0tl08v/tmp-outznmcn618
	SHLVL=1
	TMPDIR=/scratch/tmp/toilwf-550a1ba62fbf58d19983e7adac1c13f1/40c2/job/tmpjq0xw2oo9mdbqnna
	_=/usr/bin/env
<=========

I added dependency-resolver.yml in the same folder, with type: modules. And changed my CWL doc to:

#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: CommandLineTool

hints:
  SoftwareRequirement:
    packages:
      - package: singularity
        version:
          - "4.1.5"
      - package: impi

baseCommand: [bash, -c]

inputs: []
outputs: []

arguments:
  - |
    hostname
    which mpicc
    mpicc -show
    env | sort

Results:

	glogin4
	/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/bin/mpicc
	gcc -I"I_MPI_SUBSTITUTE_INSTALLDIR/include" -L"I_MPI_SUBSTITUTE_INSTALLDIR/lib/release" -L"I_MPI_SUBSTITUTE_INSTALLDIR/lib" -Xlinke
r --enable-new-dtags -Xlinker -rpath -Xlinker "I_MPI_SUBSTITUTE_INSTALLDIR/lib/release" -Xlinker -rpath -Xlinker "I_MPI_SUBSTITUTE_INSTALLD
IR/lib" -lmpifort -lmpi -lrt -lpthread -Wl,-z,now -Wl,-z,relro -Wl,-z,noexecstack -Xlinker --enable-new-dtags -ldl
	HOME=/scratch/tmp/toilwf-da3ce6b795f5589bb1751fcfdf74afef/45d9/job/tmpfyu_iinj/tmp-outl864laps
	PATH=/gpfs/projects/GROUP/USER/micromamba-envs/envs/toil/bin:/gpfs/projects/GROUP/USER/micromamba-envs//condabin:/home/bs
c/USER/.local/bin:/home/bsc/USER/bin:/apps/modules/bsc/bin:/apps/GPP/UCX/1.15.0/INTEL/bin:/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/
2021.10.0/libfabric/bin:/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/bin:/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/compiler/latest/linux/bin:/
gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/compiler/latest/linux/bin/intel64:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
	PWD=/scratch/tmp/toilwf-da3ce6b795f5589bb1751fcfdf74afef/45d9/job/tmpfyu_iinj/tmp-outl864laps
	SHLVL=1
	TMPDIR=/scratch/tmp/toilwf-da3ce6b795f5589bb1751fcfdf74afef/45d9/job/tmp1leno3p957oatmet
	_=/usr/bin/env

I_MPI_ROOT is still not included. I did a pip install --dry-run cwltool[deps], and nothing else was being installed. I checked and I couldn't see any warnings about SoftwareRequirement (it only works as hints), so I assume it's working OK.

The impi module that I added is supposed to have defined I_MPI_ROOT, and added more to LD_LIBRARY_PATH.

$ module show impi
---------------------------------------------------------------------------------------------------------------------------------------
   /apps/GPP/modulefiles/environment/impi/2021.10.0:
---------------------------------------------------------------------------------------------------------------------------------------
setenv("MPI","impi")
setenv("MPI_V","2021.10.0")
whatis("loads the impi 2021.10.0 environment")
conflict("impi","openmpi","poe")
LmodMsgRaw("display impi/2021.10.0 (PATH, MANPATH, LD_LIBRARY_PATH)
")
setenv("BSC_I_MPI_VERSION","2021.10.0")
setenv("I_MPI_ROOT","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0")
setenv("I_MPI_PMI_LIBRARY","/usr/lib64/libpmi2.so")
setenv("I_MPI_EXTRA_FILESYSTEM_FORCE","gpfs")
setenv("I_MPI_EXTRA_FILESYSTEM","on")
setenv("MPI_ROOT","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0")
prepend_path("PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/bin")
prepend_path("PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/libfabric/bin")
prepend_path("MANPATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/man")
prepend_path("LD_LIBRARY_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/lib/release")
prepend_path("LIBRARY_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/lib/release")
prepend_path("LD_LIBRARY_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/lib")
prepend_path("LD_LIBRARY_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/libfabric/lib")
prepend_path("LIBRARY_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/lib")
prepend_path("LIBRARY_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/libfabric/lib")
prepend_path("C_INCLUDE_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/include")
prepend_path("CPLUS_INCLUDE_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/include")
setenv("FI_PROVIDER_PATH","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/libfabric/lib/prov:/usr/lib64/libfabric")
setenv("I_MPI_TUNING_BIN","/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0/etc/tuning_spr_shm-ofi.dat")
help([[]])

Maybe I'm still missing something? --preserve-entire-environment brings back these env vars, so MPI should work only when that's enabled.

kinow avatar Sep 06 '26 10:09 kinow

@kinow Do you have any evidence that the problem you're having isn't just --preserve-environment being broken in toil-cwl-runner? I don't think we have tests for it, so it's possible that it has never worked, which I think we'd want to track as a separate issue.

In particular it looks like we might be clobbering it here:

https://github.com/DataBiosphere/toil/blob/7bf1a0c1878d6660aa3cc5f8337a5dbf39cb67d2/src/toil/cwl/cwltoil.py#L3200

@adamnovak I think you might be correct.

I analysed the output of cwltool (3.2.20260413085819). Here's the result grep'ing the output to simplify.

$ cwltool --preserve-environment I_MPI_ROOT toil_print_env.cwl 2>&1 | grep MPI
I_MPI_ROOT=/gpfs/apps/MN5/GPP/ONEAPI/2023.2.0/mpi/2021.10.0

With toil-cwl-runner (9.5.0)

$ toil-cwl-runner --preserve-environment=I_MPI_ROOT toil_print_env.cwl 2>&1 | grep MPI
	gcc -I"I_MPI_SUBSTITUTE_INSTALLDIR/include" -L"I_MPI_SUBSTITUTE_INSTALLDIR/lib/release" -L"I_MPI_SUBSTITUTE_INSTALLDIR/lib" -Xlinker --enable-new-dtags -Xlinker -rpath -Xlinker "I_MPI_SUBSTITUTE_INSTALLDIR/lib/release" -Xlinker -rpath -Xlinker "I_MPI_SUBSTITUTE_INSTALLDIR/lib" -lmpifort -lmpi -lrt -lpthread -Wl,-z,now -Wl,-z,relro -Wl,-z,noexecstack -Xlinker --enable-new-dtags -ldl

I guess toil-cwl-runner's preserve-environment is behaving different than cwltool.


p.s. without the =, Toil rejects the option, while cwltool accepts it... not a biggie, but may be annoying to users coming from cwltool, I guess

$ toil-cwl-runner --preserve-environment I_MPI_ROOT toil_print_env.cwl
usage: toil-cwl-runner [options] WORKFLOW [INFILE] [WF_OPTIONS...]
toil-cwl-runner: error: the following arguments are required: WORKFLOW

kinow avatar Sep 06 '26 10:09 kinow