Skip to content

Commit 6aa1cd0

Browse files
authored
Merge pull request #303 from xylar/customize-generated-scripts
Use shell scripts generated from `config_machines.xml`
2 parents 0cabaca + 9b5a43f commit 6aa1cd0

File tree

70 files changed

+131
-1976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+131
-1976
lines changed

docs/developers_guide/spack.md

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ To enable Spack-based environments for a new machine, you will need to:
1414
supported compiler and MPI library combination.
1515
2. Add system-provided (external) packages, saving time and preventing build
1616
failures if Spack attempts to build them from source.
17-
3. Optionally, provide shell script templates for module/environment setup if
18-
needed.
17+
3. Prefer automatic shell script generation. Shell snippets used to be
18+
maintained as templates in `mache.spack.templates`, but are now derived
19+
primarily from the E3SM CIME machine configuration
20+
(`mache/cime_machine_config/config_machines.xml`). Only add a minimal
21+
template override when strictly necessary (see below).
1922

2023
## YAML Template Files
2124

@@ -82,21 +85,46 @@ all:
8285
8386
```
8487

85-
## Shell Script Templates
88+
## Automatic shell script generation (preferred)
8689

87-
If the machine requires special module loads or environment variables not handled by Spack, add corresponding shell script templates:
90+
When downstream packages call
91+
{py:func}`mache.spack.get_spack_script`, the module loads and
92+
environment-variable setup are constructed as follows:
8893

89-
- `<machine>.sh` and/or `<machine>_<compiler>_<mpilib>.sh` for bash
90-
- `<machine>.csh` and/or `<machine>_<compiler>_<mpilib>.csh` for csh/tcsh
94+
1. Optional: activate Spack and the requested environment.
95+
2. Auto-generate a shell snippet from the E3SM CIME machine configuration
96+
stored in `mache/cime_machine_config/config_machines.xml`, filtered for the
97+
requested `(machine, compiler, mpilib)` and rendered for the target shell
98+
(`sh` or `csh`).
99+
3. Append any Jinja2 template override found in
100+
`mache/spack/templates/` named either `<machine>.<sh|csh>` or
101+
`<machine>_<compiler>_<mpilib>.<sh|csh>`.
91102

92-
These scripts are also Jinja2 templates and can use the same conditional logic as the YAML files.
103+
This pipeline greatly reduces maintenance and prevents drift between Mache and
104+
E3SM’s authoritative machine configuration. In most cases, you do not need to
105+
author or maintain shell script templates in Mache.
106+
107+
### When to add a template override
108+
109+
Only provide a small override in `mache/spack/templates/` if you need to:
110+
111+
- Apply an adjustment that’s not appropriate for the shared E3SM CIME config
112+
(machine-local quirk, temporary workaround, etc.).
113+
- Add conditional behavior toggled by
114+
`include_e3sm_lapack` or `include_e3sm_hdf5_netcdf` (both exposed as Jinja
115+
booleans in templates) that cannot be expressed in the CIME config.
116+
117+
Templates are Jinja2 files and can use the same conditional logic as YAML
118+
templates.
93119

94120
## Testing
95121

96-
After adding or modifying YAML and shell script templates:
122+
After adding or modifying YAML templates (or an exceptional shell override):
97123

98-
1. Use the `make_spack_env` or `get_spack_script` functions in `mache.spack` to generate and test the environment.
99-
2. Confirm that all modules load and all external packages are correctly detected by Spack.
124+
1. Use `make_spack_env` or `get_spack_script` in `mache.spack` to generate and
125+
test the environment and load scripts.
126+
2. Confirm that the generated shell snippet includes the expected module loads
127+
from the CIME machine config and that Spack detects all external packages.
100128
3. Build and run a simple test application to verify the environment.
101129

102130
## Further Reading

docs/users_guide/spack/build.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ from mache.spack import get_spack_script
9494
```
9595

9696
**Purpose:**
97-
Generates a shell script snippet to activate a Spack environment and load any required modules or environment variables.
97+
Generates a shell script snippet to activate a Spack environment and load the
98+
required modules or environment variables.
9899

99100
**Typical usage in downstream packages:**
100101

@@ -113,20 +114,24 @@ spack_script = get_spack_script(
113114
mpi=mpi,
114115
shell='sh', # or 'csh'
115116
machine=machine,
116-
config_file=machine_config,
117117
include_e3sm_lapack=include_e3sm_lapack,
118118
include_e3sm_hdf5_netcdf=e3sm_hdf5_netcdf,
119-
yaml_template=yaml_template
120119
)
121120
```
122121

123-
**Returns:**
124-
A string containing shell commands to:
122+
**How the script is composed:**
123+
124+
The returned snippet is assembled in three steps:
125125

126-
- Load required modules (if any).
127-
- Source the Spack setup script.
128-
- Activate the specified Spack environment.
129-
- Set any additional environment variables.
126+
1. Optionally source Spack and activate the requested environment.
127+
2. Auto-generate module loads and environment exports from the E3SM CIME
128+
machine configuration (`mache/cime_machine_config/config_machines.xml`) for
129+
the given `(machine, compiler, mpi)` and target shell (`sh` or `csh`).
130+
3. Append any Mache template override present in `mache/spack/templates/` named
131+
`<machine>.<sh|csh>` or `<machine>_<compiler>_<mpi>.<sh|csh>`.
132+
133+
This design keeps Mache aligned with E3SM’s authoritative machine
134+
configuration and minimizes maintenance.
130135

131136
**Usage in activation scripts:**
132137

@@ -144,7 +149,8 @@ from mache.spack import get_modules_env_vars_and_mpi_compilers
144149
```
145150

146151
**Purpose:**
147-
Returns the MPI compiler wrappers and a shell snippet to load modules and set environment variables for a given machine, compiler, and MPI library.
152+
Returns the MPI compiler wrappers and a shell snippet to load modules and set
153+
environment variables for a given machine, compiler, and MPI library.
148154

149155
**Typical usage in downstream packages:**
150156

@@ -161,7 +167,6 @@ mpicc, mpicxx, mpifc, mod_env_commands = get_modules_env_vars_and_mpi_compilers(
161167
shell='sh', # or 'csh'
162168
include_e3sm_lapack=include_e3sm_lapack,
163169
include_e3sm_hdf5_netcdf=e3sm_hdf5_netcdf,
164-
yaml_template=yaml_template
165170
)
166171
```
167172

@@ -172,13 +177,18 @@ mpicc, mpicxx, mpifc, mod_env_commands = get_modules_env_vars_and_mpi_compilers(
172177
- `mpifc`: Name of the MPI Fortran compiler wrapper (e.g., `mpif90` or `ftn`).
173178
- `mod_env_commands`: Shell commands to load modules and set environment variables.
174179

175-
**Usage in build scripts:**
180+
**Notes and usage in build scripts:**
176181

177182
```bash
178183
{{ mod_env_commands }}
179184
# Now safe to use $mpicc, $mpicxx, $mpifc for building MPI-dependent software
180185
```
181186

187+
- This helper produces a minimal snippet based on Mache’s template overrides
188+
(when present). It does not auto-generate content from
189+
`config_machines.xml`. If you need the full environment setup used by
190+
downstream activation scripts, prefer `get_spack_script`.
191+
182192
---
183193

184194
## Example: How Downstream Packages Use These Functions

mache/machines/anvil.cfg

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ partitions = acme-small, acme-medium, acme-large
6363
qos = regular, acme_high
6464

6565

66-
# Config options related to spack environments
67-
[spack]
68-
69-
# whether to load modules from the spack yaml file before loading the spack
70-
# environment
71-
modules_before = False
72-
73-
# whether to load modules from the spack yaml file after loading the spack
74-
# environment
75-
modules_after = False
76-
77-
7866
# config options related to synchronizing files
7967
[sync]
8068

mache/machines/aurora.cfg

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ account = E3SM_Dec
4949
# queues (default is the first)
5050
queues = prod, debug
5151

52-
# Config options related to spack environments
53-
[spack]
54-
55-
# whether to load modules from the spack yaml file before loading the spack
56-
# environment
57-
modules_before = False
58-
59-
# whether to load modules from the spack yaml file after loading the spack
60-
# environment
61-
modules_after = False
62-
63-
6452
# config options related to synchronizing files
6553
[sync]
6654

mache/machines/chicoma-cpu.cfg

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ partitions = standard, gpu
4040
qos = standard, debug
4141

4242

43-
# Config options related to spack environments
44-
[spack]
45-
46-
# whether to load modules from the spack yaml file before loading the spack
47-
# environment
48-
modules_before = False
49-
50-
# whether to load modules from the spack yaml file after loading the spack
51-
# environment
52-
modules_after = False
53-
54-
5543
# config options related to synchronizing files
5644
[sync]
5745

mache/machines/chrysalis.cfg

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,6 @@ cores_per_node = 128
5656
# available partition(s) (default is the first)
5757
partitions = compute, debug, Shigh
5858

59-
60-
# Config options related to spack environments
61-
[spack]
62-
63-
# whether to load modules from the spack yaml file before loading the spack
64-
# environment
65-
modules_before = False
66-
67-
# whether to load modules from the spack yaml file after loading the spack
68-
# environment
69-
modules_after = True
70-
71-
7259
# config options related to synchronizing files
7360
[sync]
7461

mache/machines/compy.cfg

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,6 @@ partitions = slurm
6363
qos = regular
6464

6565

66-
# Config options related to spack environments
67-
[spack]
68-
69-
# whether to load modules from the spack yaml file before loading the spack
70-
# environment
71-
modules_before = True
72-
73-
# whether to load modules from the spack yaml file after loading the spack
74-
# environment
75-
modules_after = False
76-
77-
7866
# config options related to synchronizing files
7967
[sync]
8068

mache/machines/dane.cfg

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ cores_per_node = 112
5353
partitions = pbatch, pdebug
5454

5555

56-
# Config options related to spack environments
57-
[spack]
58-
59-
# whether to load modules from the spack yaml file before loading the spack
60-
# environment
61-
modules_before = True
62-
63-
# whether to load modules from the spack yaml file after loading the spack
64-
# environment
65-
modules_after = False
66-
67-
6856
# config options related to synchronizing files
6957
[sync]
7058

mache/machines/frontier.cfg

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ partitions = batch
5656
# Config options related to spack environments
5757
[spack]
5858

59-
# whether to load modules from the spack yaml file before loading the spack
60-
# environment
61-
modules_before = False
62-
63-
# whether to load modules from the spack yaml file after loading the spack
64-
# environment
65-
modules_after = False
66-
6759
# whether the machine uses cray compilers
6860
cray_compilers = True
6961

mache/machines/pm-cpu.cfg

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,10 @@ constraints = cpu
6262
# quality of service (default is the first)
6363
qos = regular, debug, premium
6464

65+
6566
# Config options related to spack environments
6667
[spack]
6768

68-
# whether to load modules from the spack yaml file before loading the spack
69-
# environment
70-
modules_before = False
71-
72-
# whether to load modules from the spack yaml file after loading the spack
73-
# environment
74-
modules_after = False
75-
7669
# whether the machine uses cray compilers
7770
cray_compilers = True
7871

0 commit comments

Comments
 (0)