cubie.batchsolving.solveresult

Structures used for returning results from the batch solver.

The SolveSpec class stores the configuration of a solver run while the SolveResult class aggregates output arrays and related metadata.

Classes

SolveResult([time_domain_array, ...])

Aggregates output arrays and related metadata for a solver run.

SolveSpec(dt_min, dt_max, dt_save, ...)

Container describing a solver run.

class cubie.batchsolving.solveresult.SolveResult(time_domain_array: ndarray[Any, dtype[_ScalarType_co]] | None = NOTHING, summaries_array: ndarray[Any, dtype[_ScalarType_co]] | None = NOTHING, time: ndarray[Any, dtype[_ScalarType_co]] | None = NOTHING, time_domain_legend: dict[int, str] | None = NOTHING, summaries_legend: dict[int, str] | None = NOTHING, solve_settings: SolveSpec | None = None, singlevar_summary_legend: dict[int, str] | None = NOTHING, active_outputs: ActiveOutputs | None = NOTHING, stride_order: tuple[str, ...] | list[str] = ('time', 'run', 'variable'))[source]

Bases: object

Aggregates output arrays and related metadata for a solver run.

Parameters:
  • time_domain_array (Optional[NDArray]) – NumPy array containing time-domain results.

  • summaries_array (Optional[NDArray]) – NumPy array containing summary results.

  • time (Optional[NDArray]) – NumPy array containing time values.

  • time_domain_legend (Optional[dict[int, str]]) – Legend mapping time-domain indices to labels.

  • summaries_legend (Optional[dict[int, str]]) – Legend mapping summary indices to labels.

  • solve_settings (Optional[SolveSpec]) – Solver run configuration.

  • _singlevar_summary_legend (Optional[dict[int, str]]) – Legend mapping summary offset indices to labels.

  • _active_outputs (Optional[ActiveOutputs]) – Active outputs flags.

  • _stride_order (tuple[str, ...]) – Tuple specifying the order of variables in the host arrays..

property active_outputs

Get flags indicating which device arrays are active.

Returns:

Object storing active output flags.

Return type:

ActiveOutputs

property as_numpy: dict[str, ndarray[Any, dtype[_ScalarType_co]] | None]

Return the results as copies of NumPy arrays.

Returns:

Dictionary containing copies of time, time_domain_array, summaries_array, time_domain_legend, and summaries_legend.

Return type:

dict[str, Optional[NDArray]]

property as_numpy_per_summary: dict[str, ndarray[Any, dtype[_ScalarType_co]] | None]

Return the results as separate NumPy arrays per summary type.

Returns:

Dictionary containing time, time_domain_array, time_domain_legend, and individual summary arrays.

Return type:

dict[str, Optional[NDArray]]

property as_pandas

Convert the results to Pandas DataFrames.

Returns:

Dictionary with keys ‘time_domain’ and ‘summaries’ containing the corresponding DataFrames.

Return type:

dict[str, DataFrame]

Raises:

ImportError – If the pandas package is not available.

static cleave_time(state: ndarray[Any, dtype[_ScalarType_co]] | FakeCUDAArray | None, time_saved: bool = False, stride_order: list[str] | None = None) tuple[ndarray[Any, dtype[_ScalarType_co]] | None, ndarray[Any, dtype[_ScalarType_co]]][source]

Remove time from the state array if saved.

Parameters:
  • state (ArrayTypes) – The state array to cleave.

  • time_saved (bool, optional) – Flag indicating if time is saved in the state array.

  • stride_order (Optional[list[str]], optional) – The order of dimensions in the array. Defaults to [‘time’, ‘run’, ‘variable’] if None.

Returns:

Tuple containing the time array (or None) and the state array with time removed.

Return type:

tuple[Optional[NDArray], NDArray]

static combine_summaries_array(state_summaries, observable_summaries, summarise_states, summarise_observables) ndarray[source]

Combine state and observable summary arrays into a single array.

Parameters:
  • state_summaries (NDArray) – Array containing state summaries.

  • observable_summaries (NDArray) – Array containing observable summaries.

  • summarise_states (bool) – Flag indicating if state summaries are active.

  • summarise_observables (bool) – Flag indicating if observable summaries are active.

Returns:

Combined summary array.

Return type:

np.ndarray

static combine_time_domain_arrays(state, observables, state_active=True, observables_active=True) ndarray[Any, dtype[_ScalarType_co]][source]

Combine state and observable arrays into a single time-domain array.

Parameters:
  • state (NDArray) – Array of state values.

  • observables (NDArray) – Array of observables.

  • state_active (bool, optional) – Flag indicating if state is active.

  • observables_active (bool, optional) – Flag indicating if observables are active.

Returns:

Combined array along the last axis or a copy of the active array.

Return type:

NDArray

classmethod from_solver(solver: Solver | BatchSolverKernel, results_type: str = 'full') SolveResult | dict[str, Any][source]

Create a SolveResult from a solver instance.

Parameters:
  • solver (Solver or BatchSolverKernel) – Object providing access to output arrays and metadata.

  • results_type ({'full', 'numpy', 'numpy_per_summary', 'pandas'}, optional) – Format of the returned results. Default 'full'.

Returns:

SolveResult when results_type is 'full'; otherwise a dictionary containing the requested representation of the data.

Return type:

SolveResult or dict

property per_summary_arrays: dict[str, ndarray[Any, dtype[_ScalarType_co]]]

Split summaries_array into separate arrays keyed by summary type.

Returns:

Dictionary where each key is a summary type and the value is the corresponding NumPy array. The dictionary also includes a key ‘summary_legend’ mapping to the variable legend.

Return type:

dict[str, NDArray]

solve_settings: SolveSpec | None
summaries_array: ndarray[Any, dtype[_ScalarType_co]] | None
summaries_legend: dict[int, str] | None
static summary_legend_from_solver(solver: Solver) dict[int, str][source]

Generate a summary legend from the solver instance.

Parameters:

solver (Solver) – Solver instance providing saved states, observables, and summary legends.

Returns:

Dictionary mapping summary array indices to labels.

Return type:

dict[int, str]

time: ndarray[Any, dtype[_ScalarType_co]] | None
time_domain_array: ndarray[Any, dtype[_ScalarType_co]] | None
time_domain_legend: dict[int, str] | None
static time_domain_legend_from_solver(solver: Solver) dict[int, str][source]

Generate a time domain legend from the solver instance.

Parameters:

solver (Solver) – Solver instance providing saved states and observables.

Returns:

Dictionary mapping time domain indices to labels.

Return type:

dict[int, str]

class cubie.batchsolving.solveresult.SolveSpec(dt_min: float, dt_max: float, dt_save: float, dt_summarise: float, atol: float, rtol: float, duration: float, warmup: float, algorithm: str, saved_states: List[str] | None, saved_observables: List[str] | None, summarised_states: List[str] | None, summarised_observables: List[str] | None, output_types: List[str] | None, precision: type)[source]

Bases: object

Container describing a solver run.

dt_min, dt_max

Minimum and maximum time step sizes.

Type:

float

dt_save

Interval at which state values are stored.

Type:

float

dt_summarise

Interval for computing summary outputs.

Type:

float

atol, rtol

Absolute and relative error tolerances.

Type:

float

duration, warmup

Total integration time and initial warm-up period.

Type:

float

algorithm

Name of the integration algorithm.

Type:

str

saved_states, saved_observables

Labels of variables saved verbatim.

Type:

list of str or None

summarised_states, summarised_observables

Labels of variables for which summaries were computed.

Type:

list of str or None

output_types

Types of output arrays generated during the run.

Type:

list of str or None

precision

Floating point precision used.

Type:

type

algorithm: str
atol: float
dt_max: float
dt_min: float
dt_save: float
dt_summarise: float
duration: float
output_types: List[str] | None
precision: type
rtol: float
saved_observables: List[str] | None
saved_states: List[str] | None
summarised_observables: List[str] | None
summarised_states: List[str] | None
warmup: float