Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jo-basevi opened this issue Sep 25, 2024 · 1 comment
Open

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

jo-basevi opened this issue Sep 25, 2024 · 1 comment

Comments

@jo-basevi
Copy link
Collaborator

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.

payu/payu/envmod.py

Lines 102 to 108 in 6ee85bb

modulecmd = ('{0}/bin/modulecmd'.format(os.environ['MODULESHOME']))
cmd = '{0} python {1} {2}'.format(modulecmd, command, ' '.join(args))
envs, _ = subprocess.Popen(shlex.split(cmd),
stdout=subprocess.PIPE).communicate()
exec(envs)

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
Copy link
Collaborator

It looks like the modules get initialised in

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants