cubie.outputhandling.output_functions
Output function management for CUDA-accelerated batch solving.
This module provides classes for managing output functions that handle state saving, summary calculations, and writing to memory for CUDA batch solvers. The functions are automatically cached and compiled on demand through the CUDAFactory base class.
Classes
|
Cache container for compiled output functions. |
|
Output function factory with automatic caching. |
- class cubie.outputhandling.output_functions.OutputFunctionCache(save_state_function: Callable, update_summaries_function: Callable, save_summaries_function: Callable)[source]
Bases:
object
Cache container for compiled output functions.
This class holds the three main compiled functions used in output handling: state saving, summary updates, and summary saving. It serves as a data container returned by the OutputFunctions.build() method.
- save_state_function
Compiled CUDA function for saving state values.
- Type:
Callable
- update_summaries_function
Compiled CUDA function for updating summary metrics.
- Type:
Callable
- save_summaries_function
Compiled CUDA function for saving summary results.
- Type:
Callable
- class cubie.outputhandling.output_functions.OutputFunctions(max_states: int, max_observables: int, output_types: list[str] = None, saved_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] = None, saved_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] = None, 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] = None, 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] = None)[source]
Bases:
CUDAFactory
Output function factory with automatic caching.
This class manages the creation and caching of CUDA-compiled output functions for state saving and summary calculations. It extends CUDAFactory to provide automatic function caching and invalidation when settings change.
- Parameters:
max_states (int) – Maximum number of state variables in the system.
max_observables (int) – Maximum number of observable variables in the system.
output_types (list[str], optional) – Types of output to generate. Default is [“state”].
saved_state_indices (Sequence[int] or ArrayLike, optional) – Indices of state variables to save in time-domain output.
saved_observable_indices (Sequence[int] or ArrayLike, optional) – Indices of observable variables to save in time-domain output.
summarised_state_indices (Sequence[int] or ArrayLike, optional) – Indices of state variables to include in summary calculations.
summarised_observable_indices (Sequence[int] or ArrayLike, optional) – Indices of observable variables to include in summary calculations.
Notes
The class automatically creates an OutputConfig object from the provided parameters and sets it up as compile settings through the CUDAFactory interface. Functions are compiled lazily when first accessed.
- build() OutputFunctionCache [source]
Compile output functions and calculate memory requirements.
Compiles three main functions: save state, update summary metrics, and save summaries. Also calculates memory requirements for buffer and output arrays based on the current configuration.
- Returns:
Container with all compiled functions and memory requirements.
- Return type:
Notes
This method is called automatically by the CUDAFactory when functions are first accessed. The compiled functions are optimized for the current configuration settings.
- property compile_flags
Get the compile flags for output functions.
- Returns:
Compile flags indicating which output types are enabled.
- Return type:
- property n_saved_observables: int
Get number of observables that will be saved in time-domain output.
- Returns:
Number of observable variables that will actually be saved.
- Return type:
- property n_saved_states: int
Get number of states that will be saved in time-domain output.
- Returns:
Number of state variables to save, which equals the length of saved_state_indices when save_state is True.
- Return type:
- property n_summarised_observables: int
Get number of observables that will be summarised.
- Returns:
Number of observable variables that will actually be summarised.
- Return type:
- property n_summarised_states: int
Get number of states that will be summarised.
- Returns:
Number of state variables included in summary calculations, which equals the length of summarised_state_indices when save_summaries is active.
- Return type:
- property observable_summaries_buffer_height: int
Get height of the observable summaries buffer.
- Returns:
Total height of the buffer for observable summary calculations.
- Return type:
- property observable_summaries_output_height: int
Get height of the output array for observable summaries.
- Returns:
Height of the output array for observable summary data.
- Return type:
- property output_array_heights: OutputArrayHeights
Get output array height information.
- Returns:
Object containing height information for output arrays.
- Return type:
Notes
Exposes OutputArrayHeights from the child OutputArrayHeights object.
- property output_types
Get the output types configured for compilation.
- Returns:
Set of output types requested/compiled into the functions.
- Return type:
- property save_state_func
Access the compiled state saving function.
- Returns:
Compiled CUDA function for saving state values.
- Return type:
Callable
Notes
Exposes save_state_function from the cached OutputFunctionCache object. The function is compiled on first access if not already cached.
- property save_summary_metrics_func
Access the compiled summary saving function.
- Returns:
Compiled CUDA function for saving summary results.
- Return type:
Callable
Notes
Exposes save_summaries_function from the cached OutputFunctionCache object. The function is compiled on first access if not already cached.
- property save_time
Check if time saving is enabled.
- Returns:
True if time values are being saved with state data.
- Return type:
- property saved_observable_indices
Get indices of observables to save in time-domain output.
- Returns:
Array of observable variable indices for time-domain saving.
- Return type:
np.ndarray
- property saved_state_indices
Get indices of states to save in time-domain output.
- Returns:
Array of state variable indices for time-domain saving.
- Return type:
np.ndarray
- property state_summaries_buffer_height: int
Get height of the state summaries buffer.
- Returns:
Total height of the buffer for state summary calculations.
- Return type:
- property state_summaries_output_height: int
Get height of the output array for state summaries.
- Returns:
Height of the output array for state summary data.
- Return type:
- property summaries_buffer_height_per_var: int
Get height of the summary buffer per variable.
- Returns:
Height of the summary buffer required per variable.
- Return type:
- property summaries_buffer_sizes: SummariesBufferSizes
Get summary buffer size information.
- Returns:
Object containing buffer size information for summary calculations.
- Return type:
Notes
Exposes SummariesBufferSizes from the child SummariesBufferSizes object.
- property summaries_output_height_per_var: int
Get height of the summary output per variable.
- Returns:
Height of the summary output array per variable.
- Return type:
- property summarised_observable_indices
Get indices of observables to include in summary calculations.
- Returns:
Array of observable variable indices for summary calculations.
- Return type:
np.ndarray
- property summarised_state_indices
Get indices of states to include in summary calculations.
- Returns:
Array of state variable indices for summary calculations.
- Return type:
np.ndarray
- property summary_legend_per_variable: dict[str, int]
Get mapping of summary names to their heights per variable.
- property total_summary_buffer_size: int
Get total size of the summaries buffer.
- Returns:
Total size required for all summary buffers combined.
- Return type:
- update(updates_dict=None, silent=False, **kwargs)[source]
Update compile settings through the CUDAFactory interface.
Pass updates to compile settings, which will invalidate the function cache if an update is successful. This allows dynamic reconfiguration of output parameters.
- Parameters:
- Returns:
Set of recognized parameter names that were successfully updated.
- Return type:
- Raises:
KeyError – If unrecognized parameters are provided and silent=False.
Notes
This method is useful for bulk updates with other component parameters when silent=True is used to suppress warnings about keys not found in this component.
- property update_summaries_func
Access the compiled summary update function.
- Returns:
Compiled CUDA function for updating summary metrics.
- Return type:
Callable
Notes
Exposes update_summaries_function from the cached OutputFunctionCache object. The function is compiled on first access if not already cached.