Streaming Core/Halo Pipeline¶
RFC 0008 streaming architecture: full-chip processing where layout growth increases tile count, not per-run memory. See architecture and rfcs/0008 for the design; this page is the API reference.
openlithohub.streaming.geometry
¶
Streaming full-chip geometry primitives (RFC 0008).
Core/halo ownership model:
- The core is the only region whose result may be committed to the final full-chip output.
- The halo is read-region context that gives the forward model real neighbourhood content instead of zero-padded artefacts.
- Adjacent cores must exactly cover the global domain (no gaps, no duplicate ownership); adjacent read regions may overlap freely.
BoundingBox
dataclass
¶
Half-open pixel rectangle [x0, x1) x [y0, y1) in global coords.
Source code in src/openlithohub/streaming/geometry.py
clipped_to(width, height)
¶
Clip to the global domain [0,width) x [0,height).
Returns a bbox that may shrink; callers must treat an empty intersection (degenerate result) as "no overlap".
Source code in src/openlithohub/streaming/geometry.py
HaloSpec
dataclass
¶
Per-side halo widths requested for a tile read region.
Source code in src/openlithohub/streaming/geometry.py
core_grid_boxes(shape, core_size, *, core_stride=None)
¶
Partition shape into an exact cover of axis-aligned core boxes.
The last column/row of cores is pulled back to the domain edge so
cores cover [0,W) x [0,H) with no gap and no overlap. Returns
boxes in row-major order.
Source code in src/openlithohub/streaming/geometry.py
read_bbox_for(core, halo, width, height)
¶
Expand a core by its halo, clipped to the global domain.
Source code in src/openlithohub/streaming/geometry.py
halo_actual(core, read)
¶
Recover the per-side halo actually realised after domain clipping.
Source code in src/openlithohub/streaming/geometry.py
halo_overhead_stats(core_boxes, read_boxes)
¶
Report halo duplicate-compute overhead (prompt §15).
eta_halo = ((C+2h)^2 - C^2) / C^2 generalised per tile with the
realised (possibly clipped) halos.
Source code in src/openlithohub/streaming/geometry.py
openlithohub.streaming.core_halo
¶
Tile requests, planning, and the streaming scheduler (RFC 0008).
TileRequest pairs a trusted core with its context halo. Planning a
request list from a layout shape guarantees an exact core cover; the
scheduler consumes requests (possibly re-queuing refinements) one tile at
a time so full-chip memory stays O(tile area + active batch).
TileRequest
dataclass
¶
Read read_bbox (core + halo) and commit only core_bbox.
Source code in src/openlithohub/streaming/core_halo.py
RefinementRequest
dataclass
¶
Verifier-agnostic advice to re-run a tile with more context.
Produced by verification plugins (prompt §12); the scheduler never needs to know why a tile was inconclusive — only which knob to turn.
Source code in src/openlithohub/streaming/core_halo.py
TileScheduler
dataclass
¶
Sequential streaming scheduler with verifier-driven refinement.
The consumer pulls one request at a time; refinement requests re-enqueue
work without the scheduler knowing anything about the verifier's maths.
domain (global (H, W)) lets grown halos clip to the real layout
instead of the tile's previous read region; when omitted, the previous
read extent is used as the clip bound.
Source code in src/openlithohub/streaming/core_halo.py
enqueue_refinement(request, refinement)
¶
Re-queue refined work for an inconclusive tile.
Source code in src/openlithohub/streaming/core_halo.py
plan_tile_requests(shape, core_size, halo_px, *, core_stride=None, prefix='tile')
¶
Plan core-exact-cover tile requests for a layout shape.
Source code in src/openlithohub/streaming/core_halo.py
subdivide_request(request, subdivision)
¶
Split a tile's core into subdivision^2 smaller cores.
Source code in src/openlithohub/streaming/core_halo.py
tiling_overhead(requests)
¶
Aggregate core/halo duplicate-compute statistics for a plan.
Source code in src/openlithohub/streaming/core_halo.py
plan_tiling(layout_shape, *, memory_budget_bytes, bytes_per_pixel=4.0, halo_px=0, min_core_size=32, max_core_size=4096, batch=1)
¶
Pick the largest core size that fits the per-tile memory budget.
Approximates peak per-tile memory as bytes_per_pixel * (C + 2h)^2 *
batch and maximises core efficiency C^2 / (C + 2h)^2 subject to
the budget (prompt §16). Callers may pass an explicit
HaloPolicy-derived halo; the planner itself stays policy-agnostic.
Source code in src/openlithohub/streaming/core_halo.py
openlithohub.streaming.sources
¶
Streaming tile sources (RFC 0008, prompt §2).
A TileSource produces the read region tensor for a tile request on
demand. Implementations must never require the whole layout as a dense
host tensor:
- :class:
TensorTileSourcewraps an already-materialised tensor (compatibility, tests, small benchmarks). - :class:
MemmapTensorTileSourcereads windows out of an on-disknp.memmapraster (out-of-core big raster). - :class:
VectorLayoutTileSourcerasterizes only the objects that intersect the requested window of a vector GDS/OASIS layout through a :class:SpatialLayoutIndex.
TileSource
¶
Bases: Protocol
Read-only windowed view over a full-chip layout.
Source code in src/openlithohub/streaming/sources.py
shape
property
¶
Global raster shape (H, W) in pixels.
TensorTileSource
¶
Wrap an existing dense tensor. Zero-copy via narrow/as_strided.
Source code in src/openlithohub/streaming/sources.py
MemmapTensorTileSource
¶
Out-of-core windowed reads over an on-disk raster via np.memmap.
The backing file may be far larger than RAM; only requested windows are
paged in. Accepts a .npy/raw path plus dtype/shape, or an existing
np.memmap.
Source code in src/openlithohub/streaming/sources.py
SpatialLayoutIndex
¶
Minimal grid-bucket spatial index over vector layout boxes.
Each layout object is an axis-aligned bounding box plus optional fill
(1.0 foreground). Objects are bucketed on a coarse uniform grid so a
window query only visits intersecting buckets. This is the smallest
useful realisation of the SpatialLayoutIndex concept from RFC 0008;
a klayout-Region-backed implementation can drop in later behind the
same interface.
Source code in src/openlithohub/streaming/sources.py
VectorLayoutTileSource
¶
Rasterize only the objects intersecting each requested window.
Source code in src/openlithohub/streaming/sources.py
openlithohub.streaming.sinks
¶
Streaming tile sinks (RFC 0008, prompt §3).
A TileSink receives each tile's trusted-core result. Implementations
decide the output materialisation:
- :class:
TensorTileSink— assemble a full dense tensor (small layouts, backward-compatible behaviour). - :class:
MemmapTileSink— page the output to an on-disk memmap (out-of-core big rasters). - :class:
MetricOnlyTileSink— keep only per-tile metrics/aggregates and never materialise a raster at all (the QDM-critical mode).
Because only trusted cores are ever written, no weight map / blend pass is required: cores are an exact partition of the output domain.
CertifiedCommitNotRepresentableError
¶
Bases: ValueError
A sink was asked to commit a certified core it cannot represent.
R17 C2: a verifier PASS (or a screening fact) without a known output
tensor is a verification-only disposition. Metric-only sinks can
record it; tensor-materializing sinks must reject it, because
verifier PASS does not imply a known output tensor.
Source code in src/openlithohub/streaming/sinks.py
TensorTileSink
¶
Assemble the full dense output tensor in host memory.
Source code in src/openlithohub/streaming/sinks.py
record_certified_core(tile_id, bbox, *, exact_fill, metadata=None)
¶
R17 C2 certified commit: synthesize the exact fill, or reject.
Source code in src/openlithohub/streaming/sinks.py
MemmapTileSink
¶
Page trusted cores straight into an on-disk memmap raster.
Source code in src/openlithohub/streaming/sinks.py
record_certified_core(tile_id, bbox, *, exact_fill, metadata=None)
¶
R17 C2 certified commit: synthesize the exact fill, or reject.
Source code in src/openlithohub/streaming/sinks.py
MetricOnlyTileSink
¶
Aggregate per-tile results without ever materialising a raster.
Reducers receive one tile at a time, so peak memory is O(1) beyond the running aggregates. This is the sink mode QDM-style verification needs (certificates, worst bounds, violation lists, provenance).
Source code in src/openlithohub/streaming/sinks.py
record_certified_core(tile_id, bbox, *, exact_fill, metadata=None)
¶
R17 C2 tensor-free certified commit (the QDM-critical mode).
No raster is materialised for a certified core — with or without an
exact output fill. exact_fill is recorded as provenance only.
Source code in src/openlithohub/streaming/sinks.py
covered_pixels(sink)
¶
Total trusted-core pixels written (for gap/overlap audits).
Source code in src/openlithohub/streaming/sinks.py
openlithohub.streaming.halo_policy
¶
Halo policies (RFC 0008, prompt §4-6).
A HaloPolicy answers "how much context halo does this tile need?" and
must always explain itself: every answer carries the halo, its provenance,
an optional rigorous error bound, and a certification status. Policies
composing means taking the max halo; the strictest provenance/certification
status wins.
HaloContext
dataclass
¶
Everything a policy may need to size a halo.
Source code in src/openlithohub/streaming/halo_policy.py
LegacyFixedHaloPolicy
¶
Reproduce the pre-RFC-0005 fixed halo (default 128 px).
Source code in src/openlithohub/streaming/halo_policy.py
PhysicalInteractionHaloPolicy
¶
h = max(OIR_px, receptive-field px), RFC-0005 logic moved here.
Source code in src/openlithohub/streaming/halo_policy.py
KernelTailHaloPolicy
¶
Pick the smallest halo whose kernel tail mass <= tolerance.
T(h) = sum_{|x|>h} |K(x)| <= eps over the sampled spatial kernel.
When the sample truly bounds the full kernel, the emitted halo is
CERTIFIED_SUFFICIENT with tail mass as the error bound; if the
caller cannot vouch for the sample, pass trusted_sample=False and
the answer stays PHYSICS_ESTIMATED (never pretend certification).
Source code in src/openlithohub/streaming/halo_policy.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
combine_requirements(*requirements)
¶
Max-combine halo requirements; strictest provenance wins.
Any non-certified participant demotes the combination, and any INCONCLUSIVE participant makes the whole answer inconclusive — a halo is only as trustworthy as its weakest contributor.
Source code in src/openlithohub/streaming/halo_policy.py
kernel_tail_mass(kernel, halo_px)
¶
Fraction of |kernel| mass outside the central (2h+1)^2 box.
Source code in src/openlithohub/streaming/halo_policy.py
estimate_minimum_halo(forward_fn, *, core_bbox_px, full_context, candidate_halos=(0, 8, 16, 32, 64, 128), tolerance=0.001)
¶
Adaptive empirical halo sizing (prompt §6).
Compares the forward result restricted to a fixed core as the halo
grows. The first candidate whose discrepancy with the final
(largest-halo) reference drops under tolerance — and stays there
for the remaining candidates — is returned as EMPIRICALLY_STABLE.
This is explicitly not a mathematical certificate; a rigorous bound
needs an analytic kernel-tail or QDM argument.
Source code in src/openlithohub/streaming/halo_policy.py
openlithohub.streaming.pipeline
¶
Streaming full-chip pipeline (RFC 0008, prompt §11).
Runs the per-tile loop::
optional certified pre-forward screen
-> TileSource.read_window(core+halo) only for survivors
-> forward model
-> optional VerificationPlugin(s)
-> TileSink.write_core(trusted core only)
-> discard tile tensors
Peak memory is O(tile area + active batch), never O(full-chip raster).
Every core is written exactly once; an inconclusive verdict re-runs the
same core with a larger halo (bounded by max_requeues) before the
best-effort result is committed.
Increment 28 integrates work accounting into the actual pipeline and adds a fail-closed screening hook. Screening may skip expensive work only when its decision is certified; with verification plugins present, the screen must also explicitly certify those verifiers or the pipeline falls back to the ordinary active path.
BoundingBox
dataclass
¶
Half-open pixel rectangle [x0, x1) x [y0, y1) in global coords.
Source code in src/openlithohub/streaming/geometry.py
clipped_to(width, height)
¶
Clip to the global domain [0,width) x [0,height).
Returns a bbox that may shrink; callers must treat an empty intersection (degenerate result) as "no overlap".
Source code in src/openlithohub/streaming/geometry.py
HaloSpec
dataclass
¶
Per-side halo widths requested for a tile read region.
Source code in src/openlithohub/streaming/geometry.py
run_streaming(source, sink, forward_fn, *, core_size, halo_policy=None, verifiers=(), screening_policy=None, work_accounting=None, max_halo_px=1024, pixel_nm=1.0, max_requeues=4, tolerance_nm=None)
¶
Process a full chip tile-by-tile under core/halo ownership.
tolerance_nm (R17 C5) is a legacy convenience: it flows down only
when there is at most one verifier. With several verifiers the error
budget gate requires per-verifier tolerances on each verifier's own
:class:MetricDescriptor — a scalar cannot be a shared tolerance for
heterogeneous metrics.
Source code in src/openlithohub/streaming/pipeline.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |