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.
TensorTileSink
¶
Assemble the full dense output tensor in host memory.
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
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
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::
TileSource.read_window(core+halo)
→ 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.
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=(), max_halo_px=1024, pixel_nm=1.0, max_requeues=4)
¶
Process a full chip tile-by-tile under core/halo ownership.
Source code in src/openlithohub/streaming/pipeline.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 | |