Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

PyLauncher Parameter Sweeps

Run many independent tasks within a single SLURM allocation using PyLauncher and dapi’s parameter sweep utilities.

Try on DesignSafe

When to Use PyLauncher

End-to-End Workflow

1. Define the Parameter Sweep

from dapi import DSClient

ds = DSClient()

sweep = {
    "ALPHA": [0.3, 0.5, 3.7],
    "BETA":  [1.1, 2.0, 3.0],
}

2. Preview (dry run)

ds.jobs.parametric_sweep.generate(
    'python3 simulate.py --alpha ALPHA --beta BETA',
    sweep,
    preview=True,
)
ALPHABETA
00.31.1
10.32.0
.........
83.73.0

3. Generate Sweep Files

ds.jobs.parametric_sweep.generate(
    'python3 simulate.py --alpha ALPHA --beta BETA '
    '--output "$WORK/sweep_$SLURM_JOB_ID/run_ALPHA_BETA"',
    sweep,
    "/home/jupyter/MyData/pylauncher_demo/",
    debug="host+job",
)

4. Submit

job = ds.jobs.parametric_sweep.submit(
    "/MyData/pylauncher_demo/",
    app_id="designsafe-agnostic-app",
    allocation="your_allocation",
    node_count=1,
    cores_per_node=48,
    max_minutes=30,
)
job.monitor()

Placeholder Styles

Two styles are supported for command templates:

Token style (default) -- bare uppercase placeholders:

"python run.py --mass MASS --length LENGTH"

Braces style -- for when token names might collide with other text:

"python run.py --mass {MASS} --length {LENGTH}"
# pass placeholder_style="braces"

OpenSees Example

A parameter sweep for a cantilever pushover analysis. See the full notebook: Try on DesignSafe

sweep = {
    "NODAL_MASS": [4.19, 4.39, 4.59, 4.79, 4.99],
    "LCOL": [100, 200, 300],
}

ds.jobs.parametric_sweep.generate(
    "python3 cantilever.py --mass NODAL_MASS --lcol LCOL "
    "--outDir out_NODAL_MASS_LCOL",
    sweep,
    "/home/jupyter/MyData/opensees_sweep/",
)

job = ds.jobs.parametric_sweep.submit(
    "/MyData/opensees_sweep/",
    app_id="designsafe-agnostic-app",
    allocation="your_allocation",
    node_count=2,
    cores_per_node=48,
)
job.monitor()

Output Directory Pattern

Use TACC environment variables for collision-free output directories:

$WORK/sweep_$SLURM_JOB_ID/run_ALPHA_BETA

Notes