nirs4all.api.native_n4a module
Canonical Core .n4a bridge: one Core-owned fit, sealed bytes, thin glue.
Core’s native producer (nirs4all_core.produce_n4a_native) is the one and only
fit of this profile. It runs cross-validation, selection and refit once and
returns an already sealed canonical container plus its owner view. Canonical
retrain is the same single fit: nirs4all_core.retrain_n4a_native reads the
validated recipe and source stored in the container and runs a fresh owner
cross-validation, selection and refit on a new record. This module only validates
request shapes at the public boundary, calls Core, projects the owner scores into
a RunResult, and publishes the sealed bytes. It never trains, re-inspects
at export, or invents scientific fingerprints; routing, validation and replay
semantics stay with Core, DAG-ML and Methods.
The profile is selected explicitly with engine="native" and
native_profile=CANONICAL_N4A_NATIVE_PROFILE. It never falls back to the
interim Archive V2/V3 lanes or to the bundle path.
- nirs4all.api.native_n4a.CANONICAL_N4A_NATIVE_PROFILE = 'nirs4all.n4a.container.v1'
Explicit
native_profileselecting the canonical Core.n4aproducer.
- nirs4all.api.native_n4a.CANONICAL_N4A_SCHEMA = 'nirs4all.n4a.container.v1'
Exact manifest
schemathat identifies a canonical container.
- exception nirs4all.api.native_n4a.CanonicalN4aDependencyError[source]
Bases:
CanonicalN4aErrorThe installed
nirs4all_corelacks the canonical.n4abridge.
- exception nirs4all.api.native_n4a.CanonicalN4aError[source]
Bases:
RuntimeErrorThe canonical Core
.n4aprofile refused or could not complete.
- class nirs4all.api.native_n4a.CanonicalN4aRunResult(projected: RunResult, *, archive_bytes: bytes, view: Mapping[str, Any], methods_library_path: str, selection: Mapping[str, Any])[source]
Bases:
RunResultScore projection of one Core-sealed canonical container.
exportpublishes the sealed bytes produced by the single Core fit; it never trains, replays or re-inspects.best_score(and the metric shortcut that matches the owner’s selection metric) is Core’s selected OOF score, never a retained-test measurement; other shortcuts are NaN rather than a test substitute. The train-only producer refuses non-train records, so it supplies no retained-test scores (best["test_score"]andfinal_scoreareNone).- property best_mae: float | None
Core’s selected OOF score when the owner selected on
mae; otherwiseNone.
- property canonical_view: dict[str, Any]
Return the owner view (manifest, receipt, training) from the single fit.
- export(output_path: str | Path, format: str = 'n4a', source: dict[str, Any] | None = None, chain_id: str | None = None, *, compatibility: str | None = None) Path[source]
Atomically write the already sealed canonical bytes.
- nirs4all.api.native_n4a.inspect_n4a(path: str | Path, *, source: N4aSource | None = None, include_host_json: bool = False) dict[str, Any][source]
Inspect current container metadata without loading fitted Python objects.
Defaults preserve the existing Core view.
sourceborrows an SDK N4aSource; useopen_n4a_source(core_file=...)to adapt a retained Core file. Borrowed sources remain open. Host JSON mode returns exact owner documents and opaque fitted-artifact descriptors, never models. JSON inspection and the existing bundle pre-model checks do not establish scientific scoring or executability.
- nirs4all.api.native_n4a.predict_canonical_n4a(path: str | Path, data: Any, *, methods_library_path: str | Path | None = None, verbose: int = 0, source: N4aSource | None = None) PredictResult[source]
Replay a canonical container on one external IO record through Core.
datais{"record": <IO record path or bytes>, "partition": <partition>}. Core validates the container at this boundary and every refusal propagates; nothing is fitted and no other route is tried.Core’s replay block is ordered by sample id, not by record row. Core also returns the physical source/partition order as
sample_ids;y_predandmetadata["sample_ids"]follow that order (the signedreplayandreceiptare returned untouched). The SDK never parses the record: a missing, duplicated or differently-populated id list is refused.
- nirs4all.api.native_n4a.retrain_canonical_n4a(source: Any, data: Any, *, name: str = 'retrain_dataset', new_model: Any = None, epochs: int | None = None, verbose: int = 1, save_artifacts: bool = True, options: Mapping[str, Any] | None = None, opened_source: N4aSource | None = None) CanonicalN4aRunResult[source]
Retrain a canonical container on a new IO record through Core’s single fit.
sourceis a canonical.n4apath or theCanonicalN4aRunResultit was produced as;datais the new exact IO record (path or bytes, or{"record": ...}). Core reads the validated stored recipe and source id and runs fresh cross-validation, selection and refit through the same producer: this is always a full retrain, never a transfer or fine-tune, and the caller supplies no recipe or source id. The source container and result are left unchanged; the returned result owns new sealed bytes.Every option Core cannot honor is refused before any fit. The only supported option is
methods_library_path.
- nirs4all.api.native_n4a.run_native_n4a(pipeline: Any, dataset: Any, *, name: str = '', verbose: int = 1, save_artifacts: bool = True, save_charts: bool = False, plots_visible: bool = False, random_state: int | None = None, refit: Any = True, cache: Any = None, project: str | None = None, report_naming: str = 'nirs', results_path: Any = None, session: Any = None, tuning: Any = None, calibration: Any = None, terminal_predict: Any = None, runner_kwargs: Mapping[str, Any] | None = None) CanonicalN4aRunResult[source]
Produce one canonical container through Core’s single fit.
Every option Core’s producer cannot honor is refused explicitly instead of being ignored: seeds, cross-validation/tuning controls, calibration, sessions and workspaces.