cubie.outputhandling.update_summaries

CUDA device function factory for updating summary metrics during integration.

This module implements a recursive function chaining approach for CUDA device functions that update summary metrics during integration steps. It uses the same chaining strategy as save_summaries.py but for accumulating data rather than extracting final results.

Notes

This implementation is based on the “chain” approach by sklam from https://github.com/numba/numba/issues/3405. The approach allows dynamic compilation of only the summary metrics that are actually requested, avoiding wasted space in working arrays.

The process consists of: 1. A recursive chain_metrics function that builds a chain of update functions 2. An update_summary_factory that applies the chained functions to each variable

Functions

chain_metrics(metric_functions, ...[, ...])

Recursively chain summary metric update functions for CUDA execution.

update_summary_factory(buffer_sizes, ...)

Factory function for creating CUDA device functions to update summary metrics.

cubie.outputhandling.update_summaries.chain_metrics(metric_functions: ~typing.Sequence, buffer_offsets: ~typing.Sequence[int], buffer_sizes, function_params, inner_chain=<numba.cuda.simulator.kernel.FakeCUDAKernel object>)[source]

Recursively chain summary metric update functions for CUDA execution.

This function builds a recursive chain of summary metric update functions, where each function in the sequence is wrapped with the previous functions to create a single callable that updates all metrics.

Parameters:
  • metric_functions (Sequence) – Sequence of CUDA device functions for updating summary metrics.

  • buffer_offsets (Sequence[int]) – Buffer memory offsets for each metric function.

  • buffer_sizes (Sequence) – Buffer sizes required by each metric function.

  • function_params (Sequence) – Parameters required by each metric function.

  • inner_chain (callable, default do_nothing) – Previously chained function to execute before current function.

Returns:

CUDA device function that executes all chained metric updates.

Return type:

callable

Notes

The function uses recursion to build a chain where each level executes the inner chain first, then the current metric update function. This ensures all requested metrics are updated in the correct order during each integration step.

cubie.outputhandling.update_summaries.update_summary_factory(buffer_sizes: SummariesBufferSizes, summarised_state_indices: Sequence[int] | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], summarised_observable_indices: Sequence[int] | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], summaries_list: Sequence[str])[source]

Factory function for creating CUDA device functions to update summary metrics.

This factory generates an optimized CUDA device function that applies chained summary metric updates to all requested state and observable variables during each integration step.

Parameters:
  • buffer_sizes (SummariesBufferSizes) – Object containing buffer size information for summary calculations.

  • summarised_state_indices (Sequence[int] or ArrayLike) – Indices of state variables to include in summary calculations.

  • summarised_observable_indices (Sequence[int] or ArrayLike) – Indices of observable variables to include in summary calculations.

  • summaries_list (Sequence[str]) – List of summary metric names to compute.

Returns:

Compiled CUDA device function for updating summary metrics.

Return type:

callable

Notes

The generated function iterates through all specified state and observable variables, applying the chained summary metric updates to accumulate data in the appropriate buffer locations during each integration step.