R2 native artifact preflight¶
This page connects the R2 nirs4all native training route to the Methods wire APIs. It describes a locally qualified release candidate, not a published package or installer. Availability and digests are authoritative only after the signed release manifest is locked.
An R2 nirs4all.run(..., engine="native") result is a Core Archive V2. The
archive manifest identifies a raw N4MM Methods payload; filename suffixes do
not. Validate the complete payload before importing fitted state.
Python inspection¶
from pathlib import Path
from pls4all import (
SERIALIZED_MODEL_CAPABILITY_PIPELINE,
SERIALIZED_MODEL_CAPABILITY_PREDICT,
inspect_n4mm,
)
# An arbitrary extraction name is used: N4MM has no canonical extension.
payload = Path("extracted-methods-payload").read_bytes()
info = inspect_n4mm(payload)
if not info.capabilities & SERIALIZED_MODEL_CAPABILITY_PREDICT:
raise RuntimeError("artifact is not prediction-capable")
if info.format_version == 2:
if info.pipeline is None:
raise RuntimeError("format 2 is missing its attested pipeline")
if not info.capabilities & SERIALIZED_MODEL_CAPABILITY_PIPELINE:
raise RuntimeError("pipeline capability is missing")
print(info.pipeline.fingerprint)
The full Python package exposes the same inspector as
n4m.lowlevel.migration.inspect_n4mm. Inspection validates the magic, wire
version, recipe, dimensions, array lengths, checksum, exact end of payload and,
for format 2, the complete pipeline attestation. It does not fit, predict, or
import model state.
JavaScript and C inspection¶
The JavaScript/WASM binding exposes the same complete-byte gate:
import {
inspectN4mm,
SERIALIZED_MODEL_CAPABILITY_PREDICT,
} from "@nirs4all/methods";
const info = inspectN4mm(payload);
if ((info.capabilities & SERIALIZED_MODEL_CAPABILITY_PREDICT) === 0n) {
throw new Error("artifact is not prediction-capable");
}
C consumers call n4m_serialization_inspect_model_v1 and, when plan details
matter, n4m_serialization_inspect_pipeline_v1. The latter receives both the
output pointer and its allocation size. See the
serialization contract for the ABI structs,
status codes, zero-on-error rule and fingerprint algorithm.
Limitations and their preflight¶
Public limitation |
Preflight |
Stable outcome/remediation |
|---|---|---|
N4MM format 2 represents only exact row-wise SNV ( |
Require |
Unsupported fit recipes fail before export; altered recipes return |
Format 1 is valid raw fitted-model state and carries no pipeline. |
|
Do not infer preprocessing from a filename or sidecar. Supply preprocessing under a separately versioned contract. |
Imported affine predictors are prediction-only. |
Check `PREDICT |
AFFINE |
Future wire versions are not silently accepted. |
Run the inspector on all bytes before import. |
|
Truncated, checksum-invalid or trailing data is rejected. |
Run the inspector before allocating downstream model state. |
|
The writer ABI triple is provenance, not a strict load gate. |
Read |
An ABI difference currently records a context warning; never claim that it guarantees rejection. |
N4MM is neither a full Core Archive V2 nor a |
Resolve it through the owning archive manifest, then inspect its bytes. |
Keep archive metadata, dataset/pipeline contracts and scientific evidence outside N4MM. |
Python imports fitted N4MM state; JS currently inspects it; R and MATLAB/Octave have no N4MM import/export wrappers. |
Check the selected binding’s documented surface before artifact transfer. |
Do not infer cross-binding artifact support from method-fit parity. Use C/Python import where supported. |
Scientific contract¶
The bounded format-2 plan is intentionally tied to documented scientific methods. Review the method pages for SNV, Savitzky-Golay, and PLS, including their equations, assumptions, and primary references. The consolidated bibliography and downloadable BibTeX database preserve the scientific citations used by those pages.