Simulation Orchestrator
Goal
Provide tools to manage multi-simulation campaigns: generate parameter sweeps, track job execution status, and aggregate results from completed runs.
Requirements
- Python 3.10+
- No external dependencies (uses Python standard library only)
- Works on Linux, macOS, and Windows
Inputs to Gather
Before running orchestration scripts, collect from the user:
| Input |
Description |
Example |
| Base config |
Template simulation configuration |
base_config.json |
| Parameter ranges |
Parameters to sweep with bounds |
dt:[1e-4,1e-2],kappa:[0.1,1.0] |
| Sweep method |
How to sample parameter space |
grid, lhs, linspace |
| Output directory |
Where to store campaign files |
./campaign_001 |
| Simulation command |
Command to run each simulation |
python sim.py --config {config} |
Decision Guidance
Choosing a Sweep Method
Need every combination (full factorial)?
├── YES → Use grid (warning: exponential growth with parameters)
└── NO → Is space-filling coverage needed?
├── YES → Use lhs (Latin Hypercube Sampling)
└── NO → Use linspace for uniform sampling per parameter
| Method |
Best For |
Sample Count |
grid |
Low dimensions (1-3), need exact corners |
n^d (exponential) |
linspace |
1D sweeps, uniform spacing |
n per parameter |
lhs |
High dimensions, space-filling |
user-specified budget |
Campaign Size Guidelines
| Parameters |
Grid Points Each |
Total Runs |
Recommendation |
| 1 |
10 |
10 |
Grid is fine |
| 2 |
10 |
100 |
Grid acceptable |
| 3 |
10 |
1,000 |
Consider LHS |
| 4+ |
10 |
10,000+ |
Use LHS or DOE |
Script Outputs (JSON Fields)
| Script |
Output Fields |
scripts/sweep_generator.py |
configs, parameter_space, sweep_method, total_runs |
scripts/campaign_manager.py |
campaign_id, status, jobs, progress |
scripts/job_tracker.py |
job_id, status, start_time, end_time, exit_code |
scripts/result_aggregator.py |
summary, statistics, best_run, failed_runs |
Workflow
Step 1: Generate Parameter Sweep
Create configurations for all parameter combinations:
python3 scripts/sweep_generator.py \
--base-config base_config.json \
--params "dt:1e-4:1e-2:5,kappa:0.1:1.0:3" \
--method linspace \
--output-dir ./campaign_001 \
--json
Step 2: Initialize Campaign
Create campaign tracking structure:
python3 scripts/campaign_manager.py \
--action init \
--config-dir ./campaign_001 \
--command "python sim.py --config {config}" \
--json
Step 3: Track Job Status
Monitor running jobs:
python3 scripts/job_tracker.py \
--campaign-dir ./campaign_001 \
--update \
--json
Step 4: Aggregate Results
Combine results from completed runs:
python3 scripts/result_aggregator.py \
--campaign-dir ./campaign_001 \
--metric objective_value \
--json
CLI Examples
# Generate 5x3=15 runs varying dt (5 values) and kappa (3 values)
python3 scripts/sweep_generator.py \
--base-config sim.json \
--params "dt:1e-4:1e-2:5,kappa:0.1:1.0:3" \
--method linspace \
--output-dir ./sweep_001 \
--json
# Generate LHS samples for 4 parameters with budget of 20 runs
python3 scripts/sweep_generator.py \
--base-config sim.json \
--params "dt:1e-4:1e-2,kappa:0.1:1.0,M:1e-6:1e-4,W:0.5:2.0" \
--method lhs \
--samples 20 \
--output-dir ./lhs_001 \
--json
# Check campaign status
python3 scripts/campaign_manager.py \
--action status \
--config-dir ./sweep_001 \
--json
# Get summary statistics from completed runs
python3 scripts/result_aggregator.py \
--campaign-dir ./sweep_001 \
--metric final_energy \
--json
Conversational Workflow Example
User: I want to run a parameter sweep on dt and kappa for my phase-field simulation. I want to try 5 values of dt between 1e-4 and 1e-2, and 4 values of kappa between 0.1 and 1.0.
Agent workflow:
- Calculate total runs: 5 x 4 = 20 runs
- Generate sweep configurations:
python3 scripts/sweep_generator.py \
--base-config simulation.json \
--params "dt:1e-4:1e-2:5,kappa:0.1:1.0:4" \
--method linspace \
--output-dir ./dt_kappa_sweep \
--json
- Initialize campaign:
python3 scripts/campaign_manager.py \
--action init \
--config-dir ./dt_kappa_sweep \
--command "python phase_field.py --config {config}" \
--json
- After user runs simulations, aggregate results:
python3 scripts/result_aggregator.py \
--campaign-dir ./dt_kappa_sweep \
--metric interface_width \
--json
Error Handling
| Error |
Cause |
Resolution |
Base config not found |
Invalid file path |
Verify base config file exists |
Invalid parameter format |
Malformed param string |
Use format name:min:max:count or name:min:max |
Output directory exists |
Would overwrite |
Use --force or choose new directory |
No completed jobs |
No results to aggregate |
Wait for jobs to complete or check for failures |
Metric not found |
Result files missing field |
Verify metric name in result JSON |
Integration with Other Skills
The simulation-orchestrator works with other simulation-workflow skills:
parameter-optimization simulation-orchestrator
│ │
│ DOE samples ────────────────>│ Generate configs
│ │
│ │ Run simulations
│ │
│<──────────────────────────── │ Aggregate results
│ │
│ Sensitivity analysis │
│ Optimizer selection │
Typical Combined Workflow
- Use
parameter-optimization/doe_generator.py to get sample points
- Use
simulation-orchestrator/sweep_generator.py to create configs
- Run simulations (user's responsibility)
- Use
simulation-orchestrator/result_aggregator.py to collect results
- Use
parameter-optimization/sensitivity_summary.py to analyze
Security
The orchestrator applies the following safeguards when processing external data:
- Result file validation:
result_aggregator.py enforces a 10 MB file-size limit, maximum JSON nesting depth, strict numeric type checking (rejects bool, NaN, Inf), and sanitizes all string values (truncation, control-character stripping) before surfacing them.
- Metric name validation: Metric names are validated against
[a-zA-Z_][a-zA-Z0-9_.]* to prevent traversal or injection via crafted keys.
- Command template safety:
campaign_manager.py validates command templates to reject shell chaining operators (;, |, &, backticks, $).
- Path sanitization: Config paths interpolated into shell commands are validated against a safe-character allowlist and escaped with
shlex.quote().
- Reduced tool surface: The skill's
allowed-tools excludes Bash to prevent the agent from executing arbitrary commands when processing untrusted simulation outputs.
Limitations
- Not a job scheduler: Does not submit jobs to SLURM/PBS; generates configs and tracks status
- No parallel execution: User must run simulations externally (can use GNU parallel, SLURM, etc.)
- File-based tracking: Status tracked via files; no database or real-time monitoring
- Local filesystem: Assumes all files accessible from local machine
References
references/campaign_patterns.md - Common campaign structures
references/sweep_strategies.md - Parameter sweep design guidance
references/aggregation_methods.md - Result aggregation techniques
Version History
- v1.0.0 (2024-12-24): Initial release with sweep, campaign, tracking, and aggregation
1---2name: simulation-orchestrator3description: Orchestrate multi-simulation campaigns including parameter sweeps, batch jobs, and result aggregation. Use for running parameter studies, managing simulation batches, tracking job status, combining results from multiple runs, or automating simulation workflows.4---5
6# Simulation Orchestrator
7
8## Goal
9
10Provide tools to manage multi-simulation campaigns: generate parameter sweeps, track job execution status, and aggregate results from completed runs.
11
12## Requirements
13
14- Python 3.10+
15- No external dependencies (uses Python standard library only)
16- Works on Linux, macOS, and Windows
17
18## Inputs to Gather
19
20Before running orchestration scripts, collect from the user:
21
22| Input | Description | Example |
23|-------|-------------|---------|
24| Base config | Template simulation configuration | `base_config.json` |
25| Parameter ranges | Parameters to sweep with bounds | `dt:[1e-4,1e-2],kappa:[0.1,1.0]` |
26| Sweep method | How to sample parameter space | `grid`, `lhs`, `linspace` |
27| Output directory | Where to store campaign files | `./campaign_001` |
28| Simulation command | Command to run each simulation | `python sim.py --config {config}` |
29
30## Decision Guidance
31
32### Choosing a Sweep Method
33
34```
35Need every combination (full factorial)?
36├── YES → Use grid (warning: exponential growth with parameters)
37└── NO → Is space-filling coverage needed?
38 ├── YES → Use lhs (Latin Hypercube Sampling)
39 └── NO → Use linspace for uniform sampling per parameter
40```
41
42| Method | Best For | Sample Count |
43|--------|----------|--------------|
44| `grid` | Low dimensions (1-3), need exact corners | n^d (exponential) |
45| `linspace` | 1D sweeps, uniform spacing | n per parameter |
46| `lhs` | High dimensions, space-filling | user-specified budget |
47
48### Campaign Size Guidelines
49
50| Parameters | Grid Points Each | Total Runs | Recommendation |
51|------------|------------------|------------|----------------|
52| 1 | 10 | 10 | Grid is fine |
53| 2 | 10 | 100 | Grid acceptable |
54| 3 | 10 | 1,000 | Consider LHS |
55| 4+ | 10 | 10,000+ | Use LHS or DOE |
56
57## Script Outputs (JSON Fields)
58
59| Script | Output Fields |
60|--------|---------------|
61| `scripts/sweep_generator.py` | `configs`, `parameter_space`, `sweep_method`, `total_runs` |
62| `scripts/campaign_manager.py` | `campaign_id`, `status`, `jobs`, `progress` |
63| `scripts/job_tracker.py` | `job_id`, `status`, `start_time`, `end_time`, `exit_code` |
64| `scripts/result_aggregator.py` | `summary`, `statistics`, `best_run`, `failed_runs` |
65
66## Workflow
67
68### Step 1: Generate Parameter Sweep
69
70Create configurations for all parameter combinations:
71
72```bash
73python3 scripts/sweep_generator.py \
74 --base-config base_config.json \
75 --params "dt:1e-4:1e-2:5,kappa:0.1:1.0:3" \
76 --method linspace \
77 --output-dir ./campaign_001 \
78 --json
79```
80
81### Step 2: Initialize Campaign
82
83Create campaign tracking structure:
84
85```bash
86python3 scripts/campaign_manager.py \
87 --action init \
88 --config-dir ./campaign_001 \
89 --command "python sim.py --config {config}" \
90 --json
91```
92
93### Step 3: Track Job Status
94
95Monitor running jobs:
96
97```bash
98python3 scripts/job_tracker.py \
99 --campaign-dir ./campaign_001 \
100 --update \
101 --json
102```
103
104### Step 4: Aggregate Results
105
106Combine results from completed runs:
107
108```bash
109python3 scripts/result_aggregator.py \
110 --campaign-dir ./campaign_001 \
111 --metric objective_value \
112 --json
113```
114
115## CLI Examples
116
117```bash
118# Generate 5x3=15 runs varying dt (5 values) and kappa (3 values)
119python3 scripts/sweep_generator.py \
120 --base-config sim.json \
121 --params "dt:1e-4:1e-2:5,kappa:0.1:1.0:3" \
122 --method linspace \
123 --output-dir ./sweep_001 \
124 --json
125
126# Generate LHS samples for 4 parameters with budget of 20 runs
127python3 scripts/sweep_generator.py \
128 --base-config sim.json \
129 --params "dt:1e-4:1e-2,kappa:0.1:1.0,M:1e-6:1e-4,W:0.5:2.0" \
130 --method lhs \
131 --samples 20 \
132 --output-dir ./lhs_001 \
133 --json
134
135# Check campaign status
136python3 scripts/campaign_manager.py \
137 --action status \
138 --config-dir ./sweep_001 \
139 --json
140
141# Get summary statistics from completed runs
142python3 scripts/result_aggregator.py \
143 --campaign-dir ./sweep_001 \
144 --metric final_energy \
145 --json
146```
147
148## Conversational Workflow Example
149
150**User**: I want to run a parameter sweep on dt and kappa for my phase-field simulation. I want to try 5 values of dt between 1e-4 and 1e-2, and 4 values of kappa between 0.1 and 1.0.
151
152**Agent workflow**:
1531. Calculate total runs: 5 x 4 = 20 runs
1542. Generate sweep configurations:
155 ```bash
156 python3 scripts/sweep_generator.py \
157 --base-config simulation.json \
158 --params "dt:1e-4:1e-2:5,kappa:0.1:1.0:4" \
159 --method linspace \
160 --output-dir ./dt_kappa_sweep \
161 --json
162 ```
1633. Initialize campaign:
164 ```bash
165 python3 scripts/campaign_manager.py \
166 --action init \
167 --config-dir ./dt_kappa_sweep \
168 --command "python phase_field.py --config {config}" \
169 --json
170 ```
1714. After user runs simulations, aggregate results:
172 ```bash
173 python3 scripts/result_aggregator.py \
174 --campaign-dir ./dt_kappa_sweep \
175 --metric interface_width \
176 --json
177 ```
178
179## Error Handling
180
181| Error | Cause | Resolution |
182|-------|-------|------------|
183| `Base config not found` | Invalid file path | Verify base config file exists |
184| `Invalid parameter format` | Malformed param string | Use format `name:min:max:count` or `name:min:max` |
185| `Output directory exists` | Would overwrite | Use `--force` or choose new directory |
186| `No completed jobs` | No results to aggregate | Wait for jobs to complete or check for failures |
187| `Metric not found` | Result files missing field | Verify metric name in result JSON |
188
189## Integration with Other Skills
190
191The simulation-orchestrator works with other simulation-workflow skills:
192
193```
194parameter-optimization simulation-orchestrator
195 │ │
196 │ DOE samples ────────────────>│ Generate configs
197 │ │
198 │ │ Run simulations
199 │ │
200 │<──────────────────────────── │ Aggregate results
201 │ │
202 │ Sensitivity analysis │
203 │ Optimizer selection │
204```
205
206### Typical Combined Workflow
207
2081. Use `parameter-optimization/doe_generator.py` to get sample points
2092. Use `simulation-orchestrator/sweep_generator.py` to create configs
2103. Run simulations (user's responsibility)
2114. Use `simulation-orchestrator/result_aggregator.py` to collect results
2125. Use `parameter-optimization/sensitivity_summary.py` to analyze
213
214## Security
215
216The orchestrator applies the following safeguards when processing external data:
217
218- **Result file validation**: `result_aggregator.py` enforces a 10 MB file-size limit, maximum JSON nesting depth, strict numeric type checking (rejects `bool`, `NaN`, `Inf`), and sanitizes all string values (truncation, control-character stripping) before surfacing them.
219- **Metric name validation**: Metric names are validated against `[a-zA-Z_][a-zA-Z0-9_.]*` to prevent traversal or injection via crafted keys.
220- **Command template safety**: `campaign_manager.py` validates command templates to reject shell chaining operators (`;`, `|`, `&`, backticks, `$`).
221- **Path sanitization**: Config paths interpolated into shell commands are validated against a safe-character allowlist and escaped with `shlex.quote()`.
222- **Reduced tool surface**: The skill's `allowed-tools` excludes `Bash` to prevent the agent from executing arbitrary commands when processing untrusted simulation outputs.
223
224## Limitations
225
226- **Not a job scheduler**: Does not submit jobs to SLURM/PBS; generates configs and tracks status
227- **No parallel execution**: User must run simulations externally (can use GNU parallel, SLURM, etc.)
228- **File-based tracking**: Status tracked via files; no database or real-time monitoring
229- **Local filesystem**: Assumes all files accessible from local machine
230
231## References
232
233- `references/campaign_patterns.md` - Common campaign structures
234- `references/sweep_strategies.md` - Parameter sweep design guidance
235- `references/aggregation_methods.md` - Result aggregation techniques
236
237## Version History
238
239- **v1.0.0** (2024-12-24): Initial release with sweep, campaign, tracking, and aggregation