nirs4all.pipeline.dagml.tuning_adapters module

Optimizer adapters for the native DAG-ML PipelineObjective.

P5 starts here: optimizers drive the same objective instead of embedding their own evaluation logic. The Optuna adapter is functional for the portable subset of the public tuning.space contract. The n4m adapter uses the native ask/tell wrapper for the same objective where the wrapper exposes equivalent search-space primitives.

class nirs4all.pipeline.dagml.tuning_adapters.N4MPipelineObjectiveAdapter(optimizer_api: Any | None = None)[source]

Bases: object

Drive a PipelineObjective with the native n4m ask/tell optimizer.

optimize(objective: PipelineObjective, X: Any, y: Any, *, sample_ids: Any = None, groups: Any = None, metadata: Any = None) → TuningResult[source]

Run n4m over the objective’s typed tuning space.

class nirs4all.pipeline.dagml.tuning_adapters.ObjectiveTuningRunResult(tuning_result: TuningResult, refit_estimator: Any | None, tuning_id: str | None = None)[source]

Bases: object

Internal result for optimize-then-optional-refit over PipelineObjective.

refit_estimator: Any | None
tuning_id: str | None = None
tuning_result: TuningResult
class nirs4all.pipeline.dagml.tuning_adapters.OptunaPipelineObjectiveAdapter[source]

Bases: object

Drive a PipelineObjective with Optuna without duplicating scoring.

optimize(objective: PipelineObjective, X: Any, y: Any, *, sample_ids: Any = None, groups: Any = None, metadata: Any = None) → TuningResult[source]

Run Optuna over the objective’s typed tuning space.

exception nirs4all.pipeline.dagml.tuning_adapters.TuningAdapterUnavailable[source]

Bases: NotImplementedError

Raised when a requested optimizer adapter is not wired to P4 yet.

nirs4all.pipeline.dagml.tuning_adapters.optimize_pipeline_objective(objective: PipelineObjective, X: Any, y: Any, *, sample_ids: Any = None, groups: Any = None, metadata: Any = None) → TuningResult[source]

Dispatch the objective to the optimizer selected by its tuning spec.

nirs4all.pipeline.dagml.tuning_adapters.run_pipeline_objective_tuning(objective: PipelineObjective, X: Any, y: Any, *, sample_ids: Any = None, groups: Any = None, metadata: Any = None, refit: bool = True, workspace_path: str | Path | None = None, workspace_name: str = '', workspace_tuning_id: str | None = None, workspace_metadata: Mapping[str, Any] | None = None, run_id: str | None = None, pipeline_id: str | None = None, chain_id: str | None = None) → ObjectiveTuningRunResult[source]

Run optimizer-driving and the terminal winner refit as separate phases.

When workspace_path is provided, the completed TuningResult is persisted immediately after optimizer-driving and before terminal refit. That preserves the HPO evidence tape even if a later refit fails.