CodeEntropy.levels.execution.reducers module

Parent-side reducers for frame/chunk map-reduce outputs.

class CodeEntropy.levels.execution.reducers.CovarianceReducer[source]

Bases: object

Merge frame and chunk covariance outputs into canonical accumulators.

merge_chunk_partial(shared_data: dict[str, Any], partial: CovarianceChunkPartial) None[source]

Merge a worker covariance partial into parent accumulators.

Parameters:
  • shared_data – Shared workflow data containing covariance accumulators.

  • partial – Compact covariance partial returned by a worker frame chunk.

reduce_frame_map_output(shared_data: dict[str, Any], frame_out: dict[str, Any]) None[source]

Reduce a complete serial MAP output.

Parameters:
  • shared_data – Shared workflow data containing covariance and neighbour accumulators.

  • frame_out – MAP output containing optional covariance and neighbors entries.

reduce_frame_output(shared_data: dict[str, Any], frame_out: dict[str, Any]) None[source]

Reduce one frame covariance payload into parent accumulators.

Parameters:
  • shared_data – Shared workflow data containing covariance accumulators.

  • frame_out – Frame covariance payload with force, torque, and optional force-torque sections.

class CodeEntropy.levels.execution.reducers.NeighborReducer[source]

Bases: object

Initialise, merge, and finalise neighbour-count reductions.

static finalise(shared_data: dict[str, Any]) None[source]

Compute average neighbour counts from reduced totals.

Parameters:

shared_data – Shared workflow data containing groups, neighbor_totals, and neighbor_samples. The method writes neighbors.

static initialise(shared_data: dict[str, Any]) None[source]

Initialise parent-side neighbour accumulators.

Parameters:

shared_data – Shared workflow data containing groups. The method writes neighbor_totals and neighbor_samples.

static merge_chunk_partial(shared_data: dict[str, Any], neighbor_totals: dict[int, int], neighbor_samples: dict[int, int]) None[source]

Merge chunk-level neighbour totals and samples.

Parameters:
  • shared_data – Shared workflow data containing neighbour accumulators.

  • neighbor_totals – Mapping of group id to additive neighbour totals.

  • neighbor_samples – Mapping of group id to additive sample counts.

static reduce_frame_output(shared_data: dict[str, Any], frame_neighbors: dict[int, tuple[int, int]] | None) None[source]

Merge one frame’s neighbour-count payload.

Parameters:
  • shared_data – Shared workflow data containing neighbour total/sample accumulators.

  • frame_neighbors – Optional mapping of group id to (count, sample_count).

CodeEntropy.levels.execution.reducers.incremental_mean(old: Any, new: Any, n: int) Any[source]

Update a running mean with one new sample.

Parameters:
  • old – Existing running mean, or None for the first sample.

  • new – New sample to incorporate.

  • n – One-based sample count after adding new.

Returns:

The updated running mean.

CodeEntropy.levels.execution.reducers.merge_means(old_mean: Any, old_n: int, new_mean: Any, new_n: int) Any[source]

Merge two running means using their sample counts.

Parameters:
  • old_mean – Existing mean value, or None if no samples have been seen.

  • old_n – Number of samples represented by old_mean.

  • new_mean – New mean value to merge.

  • new_n – Number of samples represented by new_mean.

Returns:

The merged mean. If new_n is zero or negative, old_mean is returned.

CodeEntropy.levels.execution.reducers.stable_keys(mapping: dict[Any, Any]) list[Any][source]

Return mapping keys in deterministic order.

Parameters:

mapping – Mapping whose keys should be ordered independently of process hash randomisation.

Returns:

A list of keys sorted by key type name and representation.