nirs4all.pipeline.dagml.pipeline_objective module

Shared native DAG-ML pipeline objective substrate.

P4 is the seam between a typed tuning contract and optimizer adapters. This module does not run Optuna or n4m. It evaluates one explicit trial by cloning an estimator, applying candidate parameter patches, fitting through the estimator’s own native compiler/client path, and extracting one score through an injected callback. Optimizer adapters in P5 can then consume the same score tape.

class nirs4all.pipeline.dagml.pipeline_objective.PipelineObjective(estimator: Any, tuning: DagMLTuningSpec | Mapping[str, Any], *, score_extractor: Callable[[Any], float], clone_estimator: bool = True)[source]

Bases: object

Evaluate one fixed-topology trial through a supplied estimator seam.

evaluate(params: Mapping[str, Any], X: Any, y: Any, *, trial_index: int = 0, sample_ids: Any = None, groups: Any = None, metadata: Any = None) → PipelineObjectiveResult[source]

Fit and score a single candidate without driving an optimizer.

refit_best(tuning_result: Any, X: Any, y: Any, *, sample_ids: Any = None, groups: Any = None, metadata: Any = None) → Any[source]

Fit exactly one terminal estimator from a completed tuning result.

class nirs4all.pipeline.dagml.pipeline_objective.PipelineObjectiveResult(trial_index: int, params: Mapping[str, Any], score: float, metric: str, direction: str, tuning_fingerprint: str, diagnostics: Mapping[str, Any])[source]

Bases: object

Result for one evaluated candidate.

diagnostics: Mapping[str, Any]
direction: str
metric: str
params: Mapping[str, Any]
score: float
trial_index: int
tuning_fingerprint: str
nirs4all.pipeline.dagml.pipeline_objective.apply_trial_parameter_patch(estimator: Any, path: str, value: Any) → None[source]

Apply one fail-closed candidate parameter patch to an estimator.

nirs4all.pipeline.dagml.pipeline_objective.make_conformal_prediction_score_extractor(metric: str, X_score: Any, y_score: Any, calibration_data: Mapping[str, Any], *, coverage: float = 0.9, sample_ids: Any = None, groups: Any = None, metadata: Any = None) → Callable[[Any], float][source]

Build a conformal-aware development score extractor.

This helper is intentionally evaluation-only. For each fitted candidate it:

  1. predicts an explicit development calibration cohort;

  2. fits a temporary split conformal calibrator from that cohort;

  3. predicts the explicit scoring cohort;

  4. evaluates empirical conformal diagnostics on the scoring cohort.

It does not persist the temporary calibrator and does not touch the final calibrator produced by run(..., calibration=...).

nirs4all.pipeline.dagml.pipeline_objective.make_prediction_score_extractor(metric: str, X_score: Any, y_score: Any, *, sample_ids: Any = None, groups: Any = None, metadata: Any = None) → Callable[[Any], float][source]

Build a PipelineObjective score extractor from explicit score data.

The returned callable scores a fitted estimator by calling estimator.predict(X_score) and evaluating the requested metric against y_score. The score cohort is supplied explicitly; this helper does not split data, reuse optimizer objective values as test metrics, or infer a validation set. Optional sample_ids/groups/metadata are validated for row alignment and forwarded to predict() only when the estimator signature accepts them.