exporters
orchard.optimization.orchestrator.exporters
¶
Study Result Export Functions.
Handles serialization of Optuna study results to various formats:
- Best trial configuration (YAML)
- Complete study metadata (JSON)
- Top K trials comparison (Excel)
All export functions handle edge cases (no completed trials, missing timestamps) and provide informative logging with professional Excel formatting.
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. |
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
build_best_config_dict(best_params, cfg)
¶
Construct config dictionary from best trial parameters.
Maps Optuna parameters back to Config structure using map_param_to_config_path and restores full training epochs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
best_params
|
dict[str, Any]
|
Dictionary from study.best_params |
required |
cfg
|
Config
|
Template config for structure and defaults |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Config dictionary ready for validation |
Source code in orchard/optimization/orchestrator/exporters.py
build_best_trial_data(study, completed)
¶
Build best trial metadata as an immutable snapshot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study
|
Study
|
Optuna study instance. |
required |
completed
|
list[FrozenTrial]
|
List of completed trials. |
required |
Returns:
| Type | Description |
|---|---|
TrialData | None
|
Immutable trial snapshot, or None if no completed trials. |
Source code in orchard/optimization/orchestrator/exporters.py
build_top_trials_dataframe(sorted_trials, metric_name)
¶
Build DataFrame from sorted trials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sorted_trials
|
list[FrozenTrial]
|
list of trials sorted by performance |
required |
metric_name
|
str
|
Name of optimization metric (for column header) |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Pandas DataFrame with trial comparison data |