orchestrator
orchard.optimization.orchestrator
¶
Optuna Study Orchestrator Package.
High-level coordination for hyperparameter optimization studies. Provides a modular architecture for study creation, execution, visualization, and result export.
Key Components
OptunaOrchestrator: Primary study lifecycle manager.
run_optimization: Convenience function for full pipeline
execution (study creation → trial loop → artifact export).
export_best_config, export_study_summary,
export_top_trials: Post-study artifact generators.
Typical Usage
from orchard.optimization.orchestrator import run_optimization study = run_optimization(cfg=config, device=device, paths=paths)
TrialData(number, value, params, datetime_start=None, datetime_complete=None, state=None, duration_seconds=None)
dataclass
¶
Immutable snapshot of Optuna trial metadata for serialization.
Attributes:
| Name | Type | Description |
|---|---|---|
number |
int
|
Trial number within the study. |
value |
float | None
|
Objective value (None for incomplete trials). |
params |
dict[str, Any]
|
Hyperparameter values sampled for this trial. |
datetime_start |
str | None
|
ISO-formatted start timestamp. |
datetime_complete |
str | None
|
ISO-formatted completion timestamp. |
state |
str | None
|
Trial state name (COMPLETE, PRUNED, FAIL, etc.). |
duration_seconds |
float | None
|
Wall-clock duration in seconds. |
from_trial(trial)
classmethod
¶
Build from an Optuna FrozenTrial, computing duration if timestamps are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trial
|
FrozenTrial
|
Frozen trial from study. |
required |
Returns:
| Type | Description |
|---|---|
TrialData
|
Immutable trial snapshot with computed duration. |
Source code in orchard/optimization/orchestrator/exporters.py
to_dict()
¶
Serialize to plain dictionary for JSON export.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary representation with all fields. |
OptunaOrchestrator(cfg, device, paths, tracker=None)
¶
High-level manager for Optuna hyperparameter optimization studies.
Coordinates the complete optimization lifecycle: study creation, trial execution, and post-processing artifact generation. Integrates with Orchard ML's Config and RunPaths infrastructure, delegating specialized tasks (sampler/pruner building, visualization, export) to focused submodules.
This orchestrator serves as the entry point for hyperparameter tuning, wrapping Optuna's API with Orchard ML-specific configuration and output management.
Attributes:
| Name | Type | Description |
|---|---|---|
cfg |
Config
|
Template configuration that will be overridden per trial |
device |
device
|
Hardware target for training (CPU/CUDA/MPS) |
paths |
RunPaths
|
Output directory structure for artifacts and results |
Example
orchestrator = OptunaOrchestrator(cfg=config, device=device, paths=paths) study = orchestrator.optimize() print(f"Best AUC: {study.best_value:.3f}")
Artifacts saved to paths.figures/ and paths.exports/¶
Initialize orchestrator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Config
|
Base Config to override per trial |
required |
device
|
device
|
PyTorch device for training |
required |
paths
|
RunPaths
|
Root directory for outputs |
required |
tracker
|
TrackerProtocol | None
|
Optional experiment tracker for nested trial logging |
None
|
Source code in orchard/optimization/orchestrator/orchestrator.py
create_study()
¶
Create or load Optuna study with configured sampler and pruner.
Returns:
| Type | Description |
|---|---|
Study
|
Configured Optuna study instance |
Source code in orchard/optimization/orchestrator/orchestrator.py
optimize()
¶
Execute hyperparameter optimization.
Returns:
| Type | Description |
|---|---|
Study
|
Completed study with trial results |
Source code in orchard/optimization/orchestrator/orchestrator.py
export_best_config(study, cfg, paths)
¶
Export best trial configuration as YAML file.
Creates a new Config instance with best hyperparameters applied, validates it, and saves to reports/best_config.yaml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study
|
Study
|
Completed Optuna study with at least one successful trial |
required |
cfg
|
Config
|
Template configuration (used for non-optimized parameters) |
required |
paths
|
RunPaths
|
RunPaths instance for output location |
required |
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to exported config file, or None if no completed trials |
Note
Skips export with warning if no completed trials exist.
Source code in orchard/optimization/orchestrator/exporters.py
export_study_summary(study, paths)
¶
Export complete study metadata to JSON.
Serializes all trials with parameters, values, states, timestamps, and durations. Handles studies with zero completed trials gracefully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study
|
Study
|
Optuna study (may contain failed/pruned trials) |
required |
paths
|
RunPaths
|
RunPaths instance for output location |
required |
Output structure::
{
"study_name": str,
"direction": str,
"n_trials": int,
"n_completed": int,
"best_trial": {...} or null,
"trials": [...]
}
Source code in orchard/optimization/orchestrator/exporters.py
export_top_trials(study, paths, metric_name, top_k=10)
¶
Export top K trials to Excel spreadsheet with professional formatting.
Creates human-readable comparison table of best-performing trials with hyperparameters, metric values, and durations. Applies professional Excel styling matching TrainingReport format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study
|
Study
|
Completed Optuna study with at least one successful trial |
required |
paths
|
RunPaths
|
RunPaths instance for output location |
required |
metric_name
|
str
|
Name of optimization metric (for column header) |
required |
top_k
|
int
|
Number of top trials to export (default: 10) |
10
|
DataFrame Columns:
- Rank: 1-based ranking
- Trial: Trial number
- {METRIC_NAME}: Objective value
- {param_name}: Each hyperparameter
- Duration (s): Trial duration if available
Example
export_top_trials(study, paths, "auc", top_k=10)
Creates: {paths.reports}/top_10_trials.xlsx¶
Source code in orchard/optimization/orchestrator/exporters.py
run_optimization(cfg, device, paths, tracker=None)
¶
Convenience function to run complete optimization pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
Config
|
Global configuration with optuna section |
required |
device
|
device
|
PyTorch device for training |
required |
paths
|
RunPaths
|
RunPaths instance for output management |
required |
tracker
|
TrackerProtocol | None
|
Optional experiment tracker for nested trial logging |
None
|
Returns:
| Type | Description |
|---|---|
Study
|
Completed Optuna study with trial results |
Example
study = run_optimization(cfg=config, device=torch.device("cuda"), paths=paths) print(f"Best AUC: {study.best_value:.3f}")