nirs4all.pipeline.dagml.cv_weight_transfer module

Run-scoped CV weight initialization for the closed sklearn SGD profile.

Only public coefficient/intercept arrays cross from a completed, explicitly selected CV fold to a fresh REFIT estimator. sklearn owns fitting and resets its optimization counter on fit. This module retains no training rows, estimator objects, optimizer state, or cross-fold ranking implementation.

class nirs4all.pipeline.dagml.cv_weight_transfer.CVWeightTransferStore(run_id: str, *, max_entries: int = 64, max_bytes: int = 67108864)[source]

Bases: object

Bounded run-local snapshots, consumed once and cleared by their owner.

Parameters:
  • run_id – Native execution scope; another candidate/run cannot use it.

  • max_entries – Maximum simultaneously retained requested folds.

  • max_bytes – Bound on retained weights and encoded identity metadata.

capture(request: WarmStartRequest, identity: TransferIdentity, fold_id: str, model: Any, input_contract: TransferInputContract) → bool[source]

Capture only the requested completed CV fold; retain no estimator.

clear() → None[source]

Release every snapshot after success, cancellation or error.

close() → None[source]

Idempotently release snapshots and refuse further use.

property pending_bytes: int

Retained array/encoded metadata bytes, excluding interpreter overhead.

property pending_count: int

Number of actual retained snapshots, for lifecycle evidence.

prepare_refit(request: WarmStartRequest, identity: TransferIdentity, model: Any, input_contract: TransferInputContract) → tuple[dict[str, ndarray], dict[str, Any]][source]

Consume an exact snapshot and return detached public fit initializers.

The caller validates actual REFIT inputs, then calls sklearn fit once. The snapshot is released before fit, including when that fit fails.

property run_id: str

Immutable native run/candidate owner.

class nirs4all.pipeline.dagml.cv_weight_transfer.TransferIdentity(run_id: str, node_id: str, controller_id: str, variant_label: str)[source]

Bases: object

Exact native owner identity; variant_label carries native variant_id.

as_dict() → dict[str, str][source]

Return JSON-native identity for archive provenance.

controller_id: str
node_id: str
run_id: str
variant_label: str
class nirs4all.pipeline.dagml.cv_weight_transfer.TransferInputContract(source_names: tuple[str, ...], feature_names: tuple[str, ...], target_names: tuple[str, ...], x_dtype: str, y_dtype: str)[source]

Bases: object

Ordered, unchanged single-source and single-target representation.

as_dict() → dict[str, Any][source]

Return representation metadata without rows or target values.

feature_names: tuple[str, ...]
source_names: tuple[str, ...]
target_names: tuple[str, ...]
x_dtype: str
y_dtype: str
class nirs4all.pipeline.dagml.cv_weight_transfer.WarmStartRequest(fold_id: str)[source]

Bases: object

An opt-in request naming the one completed native CV fold to retain.

fold_id: str
nirs4all.pipeline.dagml.cv_weight_transfer.parse_warm_start_request(refit_params: Mapping[str, Any], *, train_params: Mapping[str, Any] | None = None) → WarmStartRequest | None[source]

Validate decoded public controls without changing cold-start behavior.

Parameters:
  • refit_params – Decoded per-model REFIT controls.

  • train_params – Decoded CV controls. Ordinary constructor warm_start is preserved without transfer; transferred CV folds must stay cold.

Returns:

An explicit fold request, or None when weight transfer is disabled.

nirs4all.pipeline.dagml.cv_weight_transfer.validate_sgd_profile(model: Any, *, phase: str | None = None) → dict[str, Any][source]

Resolve the closed deterministic SGD capability without fitting.

The exact public estimator type is required. Budgets max_iter/tol may change at REFIT; all other effective constructor options are identity.

nirs4all.pipeline.dagml.cv_weight_transfer.validate_transfer_input(X: Any, y: Any, contract: TransferInputContract) → None[source]

Check actual dense inputs against ordered metadata without coercing them.