ACCESS-NRI / ACCESS-OM2

ACCESS-OM2: ACCESS Ocean-Sea Ice Model
Apache License 2.0
5 stars 0 forks source link

Module file organisation makes searching for all versions of a model difficult #48

Closed aidanheerdegen closed 3 weeks ago

aidanheerdegen commented 5 months ago

Currently module files are installed under a directory structure which includes the spack version used to build the model. e.g.

module use /g/data/vk83/apps/spack/0.20/release/modules/linux-rocky8-x86_64
module avail access-om2

This will make it difficult to find all versions of a model, and will necessitate use-ing multiple module paths to find all versions of a model.

I think this could be overcome by automatically loading these paths in a start-up script

https://modules.readthedocs.io/en/latest/module.html#modulecmd-startup

e.g. just instruct users to module use /g/data/vk83/modules and populate /g/data/vk83/modules/.modulerc to add the paths to the spack releases.

This might require that there aren't identical versions of the same model with different spack versions. This is certainly a design intention.

aidanheerdegen commented 2 months ago

The .modulerc is only read if the directory is module loaded not module used

I looked into possible solutions, but couldn't quickly find a solution using module commands.

The only simple way to get a relatively flat module hierarchy was to use symlinks:

$ pwd
/g/data/vk83/modules
$ tree access-models/
access-models/
├── access-om2
│   ├── 2023.11.23 -> /g/data/vk83/apps/spack/0.20/release/modules/linux-rocky8-x86_64/access-om2/2023.11.23
│   └── 2024.03.0 -> /g/data/vk83/apps/spack/0.20/release/modules/linux-rocky8-x86_64/access-om2/2024.03.0
└── access-om2-bgc
    └── 2024.03.0 -> /g/data/vk83/apps/spack/0.20/release/modules/linux-rocky8-x86_64/access-om2-bgc/2024.03.0

2 directories, 3 files
$ module avail access
----------------- /g/data/vk83/modules/access-models ---------------------
access-om2-bgc/2024.03.0  access-om2/2023.11.23  access-om2/2024.03.0  

The downside to this is that new symlinks need to be added every time a new model version is deployed.

If we were prepared to have another level of hierarchy in the module file listing we could include the spack version and just link to the directory itself, which would reflect changes to the contents of the directory.

Thoughts?

aidanheerdegen commented 2 months ago

Ugh. That doesn't work.

$ module load access-om2/2024.03.0 
Loading access-om2/2024.03.0
  ERROR: Unable to locate a modulefile for 'cice5/2023.10.19_2024.03.0'
  ERROR: Load of requirement cice5/2023.10.19_2024.03.0 failed

The module system can't find the dependent modules that are loaded by the top level module because the path hasn't been added to MODULEPATH.

aidanheerdegen commented 2 months ago

Found a solution to dynamically create virtual modules

$ ls -ga /g/data/vk83/modules/access-models/
total 12
drwxrws---+ 2 vk83 4096 May  6 21:08 .
drwxrws---+ 4 vk83 4096 May  6 15:03 ..
-rw-rw----+ 1 vk83  640 May  6 21:08 .modulerc

The contents of the .modulerc file:

#%Module

set module_directories [glob -type d /g/data/vk83/apps/spack/*/release/modules/linux-rocky8-x86_64/ ]

# Loop over all release module directories
foreach module_directory $module_directories {

    # Find all the module files
    set modfiles [split [exec find $module_directory -type f -not -name ".*"] \n]

    # Create a virtual module for each one
    foreach modfile $modfiles {
        set pathElements [file split $modfile]
        set module_version [file join {*}[lrange $pathElements end-1 end]]
        # puts stderr "module-virtual $module_version $modfile"
        module-virtual $module_version $modfile
    }
}

To use:

$ module use /g/data/vk83/modules/access-models
$ module avail access
------------ /g/data/vk83/modules/access-models ----------------------
access-om2-bgc/2024.03.0  access-om2/2023.11.23  access-om2/2024.03.0                                                       

Just the models are listed above, but all the modules are loaded

-------------- /g/data/vk83/modules/access-models ---------------------------------------------
access-om2-bgc/2024.03.0     cice5/2023.10.19_bgc_2024.03.0         mom5/2023.11.09_2023.11.23           
access-om2/2023.11.23        libaccessom2/2023.10.26_2023.11.23     mom5/2023.11.09_2024.03.0            
access-om2/2024.03.0         libaccessom2/2023.10.26_2024.03.0      oasis3-mct/2023.11.09_2023.11.23     
cice5/2023.10.19_2023.11.23  libaccessom2/2023.10.26_bgc_2024.03.0  oasis3-mct/2023.11.09_2024.03.0      
cice5/2023.10.19_2024.03.0   mom5-bgc/2023.11.09_bgc_2024.03.0      oasis3-mct/2023.11.09_bgc_2024.03.0  

This will dynamically update when new modules (and spack versions) are released.