SC-NIR API¶
SC-NIR is the SC-NeuroCore metadata layer for stochastic-computing semantics that plain NIR does not encode. It records bitstream length, stochastic encoding, fixed-point precision, random-source metadata, and stream correlation constraints before a model reaches hardware compilation or experiment handoff.
The schema is intentionally strict. Unknown fields, missing fields, duplicate stream identifiers, invalid random-source metadata, and dangling correlation references are rejected rather than ignored.
JSON Schema¶
The reference schema is tracked at:
schemas/scnir/scnir.schema.json
Current schema version:
sc-neurocore.scnir.v0.1
Each stream entry must provide:
| Field | Purpose |
|---|---|
stream_id |
Stable identifier used by correlation constraints |
layer |
Producer layer or graph node name |
bitstream_length |
Positive integer SC stream length |
encoding |
unipolar, bipolar, low-discrepancy, replay, LFSR, or hardware-source encoding |
precision |
Signedness, total bits, fractional bits, accumulator bits, rounding, overflow |
source |
LFSR, Sobol, Halton, replay, or hardware source metadata |
correlation_constraints |
Pairwise policy metadata between streams |
CLI¶
Validate a document:
sc-neurocore scnir validate model.scnir.json
Exit code 0 means the document passed the SC-NIR validator. Exit code 1
means it failed validation or could not be read.
Python API¶
from sc_neurocore.ir import (
SCNIRDocument,
SCNIRPrecision,
SCNIRSource,
SCNIRStream,
load_scnir,
validate_scnir_dict,
write_scnir,
)
sc_neurocore.ir.scnir_schema
¶
SC-aware NIR metadata schema and validator.
The SC-NIR layer records stochastic-computing semantics that plain NIR does not carry: stream length, encoding, fixed-point precision, random-source metadata, and correlation constraints. Validation is intentionally fail-closed so unrecognised or under-specified metadata cannot silently reach hardware generation.
SCNIR_SCHEMA_VERSION = 'sc-neurocore.scnir.v0.1'
module-attribute
¶
SCNIRValidationError
¶
Bases: ValueError
Raised when an SC-NIR payload violates the fail-closed contract.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
73 74 | |
SCNIRPrecision
dataclass
¶
Fixed-point interpretation attached to one stochastic stream.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
77 78 79 80 81 82 83 84 85 86 | |
SCNIRSource
dataclass
¶
Random or deterministic source metadata for a stochastic stream.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
89 90 91 92 93 94 95 96 97 98 99 100 | |
SCNIRCorrelationConstraint
dataclass
¶
Correlation rule between two stochastic streams.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
103 104 105 106 107 108 109 110 | |
SCNIRStream
dataclass
¶
SC metadata for one logical stochastic bitstream.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
113 114 115 116 117 118 119 120 121 122 123 | |
SCNIRDocument
dataclass
¶
Top-level SC-NIR metadata document.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
126 127 128 129 130 131 132 | |
validate_scnir_dict(payload)
¶
Validate a decoded SC-NIR payload or raise SCNIRValidationError.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
scnir_from_dict(payload)
¶
Build a typed SC-NIR document from a decoded mapping.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
scnir_to_dict(document)
¶
Convert a typed SC-NIR document to deterministic JSON-ready data.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
191 192 193 194 195 196 197 198 199 200 | |
load_scnir(path)
¶
Load and validate an SC-NIR JSON document.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
203 204 205 206 207 | |
write_scnir(path, document)
¶
Write an SC-NIR JSON document after validating it.
Source code in src/sc_neurocore/ir/scnir_schema.py
| Python | |
|---|---|
210 211 212 213 214 215 216 217 | |