payu-org / payu

A workflow management tool for numerical models on the NCI computing systems
Apache License 2.0
21 stars 26 forks source link

User-scripts can't run `module use/load` #522

Open jo-basevi opened 1 month ago

jo-basevi commented 1 month ago

Running module use / module load in user-scripts results in /bin/sh: module: command not found

In payu, $MODULEHOMES/bin/modulecmd is used to run any module commands. The $MODULEHOMES/bin/modulecmd python load <module> generates commands that can be executed to run the module load command.

https://github.com/payu-org/payu/blob/6ee85bb34a6476ccf0031b7131b8ac406edfb532/payu/envmod.py#L102-L108

Payu PBS jobs are submitted with a format similar to qsub -- /path/to/env/bin/python /path/to/env/bin/payu-run. The qsub man page noted had the following for using -- to run commands:

When you run qsub this way, it runs the executable directly. It does not start a shell, so no shell initialization scripts are run, and execution paths and other environment variables are not set.

So the shell initialisation scripts might be what is setting up the module commands? I don't know if it possible to avoid using $MODULEHOMES/bin/modulecmd commands in envmod.py as modules need to be loaded in the same process that python is running (unless copying back the changes to environment in a subprocess call). However when running bash user-scripts should payu first run an shell initialisation script in the subprocess to setup module commands? My ~/.bashrc has the following which I've tested works for setting up the module command (at least on gadi - this might be platform specific?)

# Source global definitions (Required for modules)
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

This might not be a major issue, as workarounds is to specify any required modules in config.yaml, under modules: load:, or run a shell initialisation script or use modulecmd in the user-scripts.

anton-seaice commented 1 month ago

It looks like the modules get initialised in

/opt/Modules/v4.3.0/init/bash