cubie.batchsolving.arrays.BatchOutputArrays
Batch Output Arrays Module.
This module provides classes for managing output arrays in batch integration operations, including containers for storing results and managers for handling memory allocation and data transfer between host and device.
Classes
|
Track which output arrays are actively being used. |
|
Container for batch output arrays. |
|
Manage batch integration output arrays between host and device. |
- class cubie.batchsolving.arrays.BatchOutputArrays.ActiveOutputs(state: bool = False, observables: bool = False, state_summaries: bool = False, observable_summaries: bool = False)[source]
Bases:
object
Track which output arrays are actively being used.
This class provides boolean flags indicating which output types are currently active based on array sizes and allocation status.
- Parameters:
state (bool, default=False) – Whether state output is active.
observables (bool, default=False) – Whether observables output is active.
state_summaries (bool, default=False) – Whether state summaries output is active.
observable_summaries (bool, default=False) – Whether observable summaries output is active.
- update_from_outputarrays(output_arrays: OutputArrays)[source]
Update active outputs based on OutputArrays instance.
- Parameters:
output_arrays (OutputArrays) – The OutputArrays instance to check for active outputs.
Notes
An output is considered active if the corresponding array exists and has more than one element (size > 1).
- class cubie.batchsolving.arrays.BatchOutputArrays.OutputArrayContainer(stride_order: tuple[str, ...] | None = None, unchunkable: tuple[str] = NOTHING, state: ndarray[Any, dtype[_ScalarType_co]] | FakeCUDAArray | None = None, observables: ndarray[Any, dtype[_ScalarType_co]] | FakeCUDAArray | None = None, state_summaries: ndarray[Any, dtype[_ScalarType_co]] | FakeCUDAArray | None = None, observable_summaries: ndarray[Any, dtype[_ScalarType_co]] | FakeCUDAArray | None = None, memory_type: str = 'device')[source]
Bases:
ArrayContainer
Container for batch output arrays.
This container holds the output arrays generated during batch integration, including state trajectories, observables, and their summaries.
- Parameters:
state (ArrayTypes, optional) – State variable trajectories over time.
observables (ArrayTypes, optional) – Observable variable trajectories over time.
state_summaries (ArrayTypes, optional) – Summary statistics for state variables.
observable_summaries (ArrayTypes, optional) – Summary statistics for observable variables.
stride_order (tuple[str, ...], default=("time", "run", "variable")) – Order of array dimensions.
_memory_type (str, default="device") – Type of memory allocation.
Notes
This class uses attrs for automatic initialization and validation. The stride_order specifies how the 3D arrays are organized in memory.
- classmethod device_factory()[source]
Create a new device memory container.
- Returns:
A new container configured for mapped memory.
- Return type:
- class cubie.batchsolving.arrays.BatchOutputArrays.OutputArrays(precision: type = <class 'numpy.float32'>, chunks: int = 0, chunk_axis: str = 'run', stream_group: str = 'default', memory_proportion: float | None = None, memory_manager: ~cubie.memory.mem_manager.MemoryManager = MemoryManager(totalmem=8589934592, registry={}, stream_groups=StreamGroups(groups={}, streams={}), _mode='passive', _allocator=<class 'cubie.cudasim_utils.FakeNumbaCUDAMemoryManager'>, _auto_pool=[], _manual_pool=[], _stride_order=('time', 'run', 'variable'), _queued_allocations={}), sizes: ~cubie.outputhandling.output_sizes.BatchOutputSizes = NOTHING, host: ~cubie.batchsolving.arrays.BatchOutputArrays.OutputArrayContainer = NOTHING)[source]
Bases:
BaseArrayManager
Manage batch integration output arrays between host and device.
This class manages the allocation, transfer, and synchronization of output arrays generated during batch integration operations. It handles state trajectories, observables, and summary statistics.
- Parameters:
_sizes (BatchOutputSizes) – Size specifications for the output arrays.
host (OutputArrayContainer) – Container for host-side arrays.
device (OutputArrayContainer) – Container for device-side arrays.
_active_outputs (ActiveOutputs) – Tracker for which outputs are currently active.
Notes
This class is initialized with a BatchOutputSizes instance (which is drawn from a solver instance using the from_solver factory method), which sets the allowable 3D array sizes from the ODE system’s data and run settings. Once initialized, the object can be updated with a solver instance to update the expected sizes, check the cache, and allocate if required.
- property active_outputs: ActiveOutputs
Get currently active output types.
- Returns:
Object indicating which output arrays are active.
- Return type:
Notes
Checks which outputs are requested, treating size-1 arrays as an artifact of the default allocation.
- device: OutputArrayContainer
- property device_observable_summaries
Get device observable summaries array.
- Returns:
The observable summaries array from the device container.
- Return type:
ArrayTypes
- property device_observables
Get device observables array.
- Returns:
The observables array from the device container.
- Return type:
ArrayTypes
- property device_state
Get device state array.
- Returns:
The state array from the device container.
- Return type:
ArrayTypes
- property device_state_summaries
Get device state summaries array.
- Returns:
The state summaries array from the device container.
- Return type:
ArrayTypes
- finalise(host_indices)[source]
Copy mapped arrays to host array slices.
- Parameters:
host_indices (slice or array-like) – Indices for the chunk being finalized.
Notes
This method copies mapped device arrays over the specified slice of host arrays. The copy operation may trigger CUDA runtime synchronization.
- classmethod from_solver(solver_instance: BatchSolverKernel) OutputArrays [source]
Create an OutputArrays instance from a solver.
Does not allocate arrays, just sets up size specifications.
- Parameters:
solver_instance (BatchSolverKernel) – The solver instance to extract configuration from.
- Returns:
A new OutputArrays instance configured for the solver.
- Return type:
- host: OutputArrayContainer
- initialise(host_indices)[source]
Initialize device arrays before kernel execution.
- Parameters:
host_indices (slice or array-like) – Indices for the chunk being initialized.
Notes
No initialization to zeros is needed unless chunk calculations in time leave a dangling sample at the end, which is possible but not expected.
- property observable_summaries
Get host observable summaries array.
- Returns:
The observable summaries array from the host container.
- Return type:
ArrayTypes
- property observables
Get host observables array.
- Returns:
The observables array from the host container.
- Return type:
ArrayTypes
- property state
Get host state array.
- Returns:
The state array from the host container.
- Return type:
ArrayTypes
- property state_summaries
Get host state summaries array.
- Returns:
The state summaries array from the host container.
- Return type:
ArrayTypes
- update(solver_instance) OutputArrays [source]
Update output arrays from solver instance.
- Parameters:
solver_instance (BatchSolverKernel) – The solver instance providing configuration and sizing information.
- Returns:
Self, for method chaining.
- Return type:
- update_from_solver(solver_instance: BatchSolverKernel)[source]
Update sizes and precision from solver, returning new host arrays
- Parameters:
solver_instance (BatchSolverKernel) – The solver instance to update from.
- Returns:
A dict of host arrays; np.zeros with updated sizes for the update_host_arrays method to interpret.
- Return type: