experiments
agentevac.analysis.experiments
Parameter sweep driver for AgentEvac calibration experiments.
This module builds a Cartesian-product grid of agent parameters and runs one simulation subprocess per grid cell, collecting the resulting metrics and replay files.
Parameter axes:
- info_sigma : Gaussian noise standard deviation on margin observations (metres).
- info_delay_s : Information delay in seconds (stale observation replay).
- theta_trust : Social-signal trust weight ∈ [0, 1].
- scenario : Information regime ("no_notice", "alert_guided", "advice_guided").
Each case is run by spawning agentevac.simulation.main as a subprocess with the appropriate
environment variables set (INFO_SIGMA, INFO_DELAY_S, DEFAULT_THETA_TRUST).
The SUMO GUI is suppressed (--sumo-binary sumo) for headless batch execution.
Outputs (written to output_dir):
- routes_<case_id>.jsonl : Recorded LLM route decisions (for replay).
- metrics_<case_id>.json : Run-level KPI summary.
- stdout_<case_id>.log : Full stdout + stderr of the subprocess.
- experiment_results.json : Aggregated list of all case result dicts.
- experiment_results.csv : Flat CSV of key result fields.
build_experiment_grid(sigma_values=None, delay_values=None, trust_values=None, scenario_modes=None, base_overrides=None)
Build a Cartesian-product experiment grid from parameter value lists.
Defaults apply when a parameter list is not provided
- sigma_values : [40.0]
- delay_values : [0.0]
- trust_values : [0.5]
- scenario_modes : ["advice_guided"]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma_values
|
Optional[List[float]]
|
List of |
None
|
delay_values
|
Optional[List[float]]
|
List of |
None
|
trust_values
|
Optional[List[float]]
|
List of |
None
|
scenario_modes
|
Optional[List[str]]
|
List of scenario mode strings to sweep. |
None
|
base_overrides
|
Optional[Dict[str, Any]]
|
Additional key-value pairs merged into every case dict
(e.g., |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of case config dicts, one per grid cell. |
Source code in agentevac/analysis/experiments.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
export_experiment_results(results, *, output_dir, stem='experiment_results')
Write experiment results to JSON (full) and CSV (flat key subset) files.
The JSON file contains all result fields. The CSV file contains a flattened subset suitable for quick inspection in spreadsheet tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
List[Dict[str, Any]]
|
List of result dicts from |
required |
output_dir
|
str
|
Directory to write output files. |
required |
stem
|
str
|
Base filename stem (without extension). |
'experiment_results'
|
Returns:
| Type | Description |
|---|---|
Dict[str, str]
|
Dict with |
Source code in agentevac/analysis/experiments.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
run_experiment_case(case_cfg, *, script_path='agentevac/simulation/main.py', python_executable=None, output_dir='outputs/experiments', sumo_binary='sumo', run_mode='record', timeout_s=None, sumo_seed=None, map_name=None)
Execute one parameter-grid case by spawning a simulation subprocess.
Constructs the CLI command and environment from case_cfg, runs the process,
captures stdout/stderr, and extracts the metrics and replay file paths from the
subprocess stdout using fixed prefix patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
case_cfg
|
Dict[str, Any]
|
Case configuration dict (from |
required |
script_path
|
str
|
Path to the main simulation script (relative to project root). |
'agentevac/simulation/main.py'
|
python_executable
|
Optional[str]
|
Python interpreter to use; defaults to |
None
|
output_dir
|
str
|
Directory for output files. |
'outputs/experiments'
|
sumo_binary
|
str
|
SUMO binary name; use |
'sumo'
|
run_mode
|
str
|
|
'record'
|
timeout_s
|
Optional[float]
|
Optional subprocess timeout in seconds. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A result dict with fields including |
Dict[str, Any]
|
|
Dict[str, Any]
|
|
Source code in agentevac/analysis/experiments.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
run_parameter_sweep(grid, *, script_path='agentevac/simulation/main.py', python_executable=None, output_dir='outputs/experiments', sumo_binary='sumo', run_mode='record', timeout_s=None, sumo_seed=None, map_name=None)
Run all cases in the experiment grid sequentially.
Cases run one at a time (no parallelism) to avoid SUMO port conflicts and to keep resource usage predictable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
List[Dict[str, Any]]
|
List of case config dicts from |
required |
script_path
|
str
|
Path to the main simulation script. |
'agentevac/simulation/main.py'
|
python_executable
|
Optional[str]
|
Python interpreter to use. |
None
|
output_dir
|
str
|
Directory for all case output files. |
'outputs/experiments'
|
sumo_binary
|
str
|
SUMO binary name. |
'sumo'
|
run_mode
|
str
|
|
'record'
|
timeout_s
|
Optional[float]
|
Per-case subprocess timeout in seconds. |
None
|
map_name
|
Optional[str]
|
Map config directory name (e.g., |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of result dicts (one per grid case) from |
Source code in agentevac/analysis/experiments.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |