pycsa.compute.context

ComputeContext: explicit container for per-task compute resources.

Bundles the BufferPool (per-task lifetime; owned by the context) and an accessor for the worker-local tile cache (worker-process lifetime; the context only holds a getter). Threading a single ctx through the pipeline makes the data flow explicit, replacing the previous pattern of implicit BufferPool creation inside get_pmf.__init__ + module-level tile_cache.get_worker_cache() calls scattered through do_cell.

The tile_cache field is a callable rather than the cache itself because the real cache is a per-Dask-worker singleton owned by the worker process and can’t be carried across pickle boundaries. A test can substitute a stub by passing any callable that returns a cache-like object.

Classes

ComputeContext(buffer_pool, tile_cache, ...)

Per-task compute resources for the CSA pipeline.

class pycsa.compute.context.ComputeContext(buffer_pool: ~pycsa.core.buffer_pool.BufferPool = <factory>, tile_cache: ~typing.Callable[[], ~typing.Any] | None = None, prior: ~typing.Any | None = None, selector: ~typing.Any | None = None)

Per-task compute resources for the CSA pipeline.

Parameters:
  • buffer_pool (pycsa.core.buffer_pool.BufferPool) – Owned by the context. One BufferPool per ComputeContext.

  • tile_cache (Callable[[], Any] | None) – Optional callable that returns the worker-local tile cache. The cache itself is not stored (it’s owned by the Dask worker process); we hold a getter that resolves at call time. Pass None for environments that don’t need tile_cache (idealised runs, tests).

  • prior (Any | None) – Optional pycsa.core.priors.Prior carried through to lin_reg.do. Spike scripts thread a structured prior here without modifying any call site. None (default) means the preserved scalar-trace branch in lin_reg.do runs unchanged.

  • selector (Any | None) – Optional pycsa.core.mode_selection.ModeSelector carried through to pycsa.wrappers.interface.second_appx. Spike scripts thread an alternative selector here without modifying any call site. None (default) means the preserved inline argmax loop in second_appx runs unchanged.

buffer_pool: BufferPool
tile_cache: Callable[[], Any] | None = None
prior: Any | None = None
selector: Any | None = None
classmethod default() ComputeContext

Production setup: fresh BufferPool + tile_cache accessor.

Imports pycsa.core.tile_cache lazily so callers in dependency-light environments can still construct a no-cache context via plain ComputeContext().

__init__(buffer_pool: ~pycsa.core.buffer_pool.BufferPool = <factory>, tile_cache: ~typing.Callable[[], ~typing.Any] | None = None, prior: ~typing.Any | None = None, selector: ~typing.Any | None = None) None