-
Notifications
You must be signed in to change notification settings - Fork 0
Add SWOPP3 analysis script and violations module #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6619210
Add SWOPP3 analysis and routing workflow updates
daniprec 59b379f
Add per-subplot PNG exports for SWOPP3 figures
daniprec 5d065ce
prune story
daniprec 2fdebe7
Support zipped SWOPP3 submissions and participant name parsing
daniprec b1342a4
Merge branch 'feat/swopp3-clean' into scripts/swopp3-analysis
daniprec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| """Shared configuration helpers for SWOPP3 analysis. | ||
|
|
||
| This module provides the stable, importable API used by both | ||
| ``scripts/swopp3_analysis.py`` and its test suite. Keeping these helpers | ||
| in a proper library module avoids the fragile ``importlib`` pattern that | ||
| would otherwise be needed to test them. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import tomllib | ||
| from dataclasses import dataclass | ||
| from functools import cache | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class AnalysisPaths: | ||
| """Filesystem locations used by the SWOPP3 analysis script.""" | ||
|
|
||
| output_dir: Path | ||
| figs_dir: Path | ||
| config_path: Path | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Experiment registry — all known experiments across all profiles | ||
| # --------------------------------------------------------------------------- | ||
| EXPERIMENTS_REGISTRY: dict[str, dict] = { | ||
| # ── No-penalty profile (four-experiment) ──────────────────────────── | ||
| "no_penalty": { | ||
| "folder": "swopp3_no_penalty", | ||
| "label": "CMA-ES", | ||
| "short": "No Penalty", | ||
| "color": "#F23333", # IE law red — unconstrained | ||
| "color_light": "#FF9B9B", | ||
| "hatch": "", | ||
| "order": 1, | ||
| }, | ||
| "no_penalty_fms": { | ||
| "folder": "swopp3_no_penalty_fms", | ||
| "label": "CMA-ES + FMS", | ||
| "short": "No Penalty + FMS", | ||
| "color": "#007A3D", # emerald green — high contrast with red | ||
| "color_light": "#5CC28A", | ||
| "hatch": "///", | ||
| "order": 2, | ||
| }, | ||
| "penalty": { | ||
| "folder": "swopp3_penalty", | ||
| "label": "CMA-ES + Penalty", | ||
| "short": "Penalty", | ||
| "color": "#000066", # IE primary ocean-blue — constrained | ||
| "color_light": "#6080CC", | ||
| "hatch": "", | ||
| "order": 3, | ||
| }, | ||
| "penalty_fms": { | ||
| "folder": "swopp3_penalty_fms", | ||
| "label": "CMA-ES + Penalty + FMS", | ||
| "short": "Penalty + FMS", | ||
| "color": "#E09400", # amber — high contrast with dark navy | ||
| "color_light": "#FFCC66", | ||
| "hatch": "///", | ||
| "order": 4, | ||
| }, | ||
| # ── Sweep-combined profile (two-experiment) ────────────────────────── | ||
| "sweep_combined": { | ||
| "folder": "sweep_combined", | ||
| "label": "CMA-ES", | ||
| "short": "Sweep Combined", | ||
| "color": "#F23333", # IE law red — unconstrained | ||
| "color_light": "#FF9B9B", | ||
| "hatch": "", | ||
| "order": 1, | ||
| }, | ||
| "sweep_combined_fms": { | ||
| "folder": "sweep_combined_fms", | ||
| "label": "CMA-ES + FMS", | ||
| "short": "Sweep Combined + FMS", | ||
| "color": "#007A3D", # emerald green — high contrast with red | ||
| "color_light": "#5CC28A", | ||
| "hatch": "///", | ||
| "order": 2, | ||
| }, | ||
| "sweep_combined_fms_strict": { | ||
| "folder": "sweep_combined_fms_strict", | ||
| "label": "CMA-ES + FMS (strict)", | ||
| "short": "Sweep Combined + FMS Strict", | ||
| "color": "#0097DC", # IE business blue | ||
| "color_light": "#7FCCEE", | ||
| "hatch": "///", | ||
| "order": 3, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| @cache | ||
| def _configured_output_dirs(config_path: Path) -> dict[str, str]: | ||
| """Return output-folder names declared in the SWOPP3 config file.""" | ||
| if not config_path.exists(): | ||
| return {} | ||
|
|
||
| with config_path.open("rb") as handle: | ||
| config = tomllib.load(handle) | ||
|
|
||
| experiments = config.get("swopp3", {}).get("experiments", {}) | ||
| output_dirs: dict[str, str] = {} | ||
| for experiment_name, experiment_config in experiments.items(): | ||
| output_dir = experiment_config.get("output_dir") | ||
| if isinstance(output_dir, str) and output_dir: | ||
| output_dirs[experiment_name] = Path(output_dir).name | ||
| return output_dirs | ||
|
|
||
|
|
||
| def _experiment_folder(exp_key: str, paths: AnalysisPaths) -> str: | ||
| """Return the folder name for one analysis experiment. | ||
|
|
||
| Prefer config-driven folder names when the merged SWOPP3 experiment config | ||
| defines a matching output directory. Keep the legacy folder names as a | ||
| fallback so older result folders remain readable. | ||
| """ | ||
| metadata = EXPERIMENTS_REGISTRY[exp_key] | ||
| configured_dirs = _configured_output_dirs(paths.config_path) | ||
| candidates: list[str] = [] | ||
|
|
||
| config_experiment = metadata.get("config_experiment") | ||
| if isinstance(config_experiment, str): | ||
| configured = configured_dirs.get(config_experiment) | ||
| if configured is not None: | ||
| candidates.append(configured) | ||
|
|
||
| config_parent = metadata.get("config_parent") | ||
| if isinstance(config_parent, str): | ||
| configured_parent = configured_dirs.get(config_parent) | ||
| if configured_parent is not None: | ||
| candidates.append(f"{configured_parent}_fms") | ||
|
|
||
| legacy_folder = str(metadata["folder"]) | ||
| candidates.append(legacy_folder) | ||
|
|
||
| for candidate in candidates: | ||
| if (paths.output_dir / candidate).exists(): | ||
| return candidate | ||
| return candidates[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.