nirs4all.api.native_session module

Stateful native Methods session with no legacy workspace dependency.

class nirs4all.api.native_session.NativeMethodsSession(pipeline: list[Any], *, name: str = '', random_state: int | None = None, tuning: Mapping[str, Any] | None = None, calibration: Mapping[str, Any] | None = None)[source]

Bases: object

One portable Methods pipeline through train, predict, export, and close.

This session holds only the fitted DAG-ML/Methods estimator and never creates a PipelineRunner or legacy workspace. A persisted session is loaded through nirs4all.load_session() with engine='native' and becomes a NativeArchiveSession.

property calibration: dict[str, Any] | None

Return the explicit identity-bound conformal calibration request.

close() → None[source]

Release the current live native result before dropping its reference.

property closed: bool

Whether the session has been closed.

property is_trained: bool

Whether this session owns a fitted native result.

property pipeline: list[Any]

The exact portable pipeline object owned by this session.

predict(X: Any, *, sample_ids: Any, groups: Any = None, metadata: Any = None) → PredictResult[source]

Replay the fitted native package for one explicitly identified cohort.

property random_state: int | None

The deterministic seed configured for every session training run.

property result: NativeMethodsRunResult | NativeMethodsRefitResult

The fitted native run result, or raise before training.

retrain(dataset: Mapping[str, Any]) → NativeMethodsRefitResult[source]

Full-refit the attested selected Methods variant on one new cohort.

This delegates to the public native retrain contract, which preserves only the selected portable PLS recipe and its attested patch. Transfer learning and finetuning are intentionally not session capabilities.

run(dataset: Mapping[str, Any]) → NativeMethodsRunResult[source]

Fit this session’s portable Methods pipeline exactly once per call.

save(path: str | Path) → Path[source]

Persist the current native result as its Core Archive V2 or V3.

property tuning: dict[str, Any] | None

Return the session’s immutable-at-boundary native tuning request.