Working with Results
Every call to solve_ivp() or
solve() returns a
SolveResult.
The SolveResult Object
Key attributes:
time_domain_array3-D NumPy array with shape
(n_time_points, n_variables, n_runs).summaries_array2-D NumPy array with shape
(n_summary_rows, n_runs).time1-D array of time values corresponding to the first axis of
time_domain_array.iteration_countersPer-run integer array encoding Newton iteration counts and status codes.
time_domain_legendDictionary mapping column indices to variable names.
summaries_legendDictionary mapping row indices to summary labels.
Convenience accessors:
result.as_numpy— returns a dict of NumPy arrays.result.as_pandas— returns a dict of pandas DataFrames.result.as_numpy_per_summary— splits summaries by metric type.
Output Types
Control what is saved with the output_types list (or via
output_settings on the Solver):
"state"Time-domain state trajectories.
"observables"Time-domain observable trajectories.
"time"Time point array.
"iteration_counters"Newton iteration counts and status codes.
Any summary metric name (e.g. "mean", "max", "peaks") adds
that metric to the output.
Time-Domain vs Summary Output
Time-domain saves and summary metrics operate at independent cadences:
dt_save(orsave_every) controls how often state snapshots are written.dt_summarise(orsummarise_every) controls how often the summary accumulators are updated.sample_summaries_everycontrols the sub-step sampling rate for metrics that interpolate between steps.
Using summaries lets you extract statistics (mean, max, peaks, etc.) without ever writing the full trajectory to VRAM.
Built-in Summary Metrics
Metric |
Description |
|---|---|
|
Time-averaged value. |
|
Standard deviation over time. |
|
Root-mean-square value. |
|
Maximum value. |
|
Minimum value. |
|
Both max and min. |
|
Maximum absolute value. |
|
Positive peaks (local maxima). |
|
Negative peaks (local minima). |
|
Maximum of the first derivative. |
|
Minimum of the first derivative. |
|
Both max and min of the first derivative. |
|
Maximum of the second derivative. |
|
Minimum of the second derivative. |
|
Both max and min of the second derivative. |
|
Mean and standard deviation combined. |
|
Standard deviation and RMS combined. |
|
Mean, standard deviation, and RMS combined. |
Selecting Variables to Save
By default all states and observables are saved. To reduce memory and improve speed, select only the variables you need:
result = qb.solve_ivp(
system,
y0=y0,
parameters=params,
method="dormand_prince_54",
duration=10.0,
save_variables=["x"],
summarise_variables=["x", "y"],
output_types=["state", "mean", "max"],
)
Iteration Counters
When using implicit algorithms, the iteration counter for each run encodes the Newton iteration count in the upper 16 bits:
counters = result.iteration_counters
iterations = (counters >> 16) & 0xFFFF
status = counters & 0xFFFF
See Nonlinear Solvers for background on the Newton solver.
Example: Requesting Summaries
import cubie as qb
import numpy as np
# ... (system definition omitted for brevity)
result = qb.solve_ivp(
system,
y0=y0,
parameters=params,
method="dormand_prince_54",
duration=50.0,
output_types=["mean", "std"],
summarise_variables=["x"],
)
per_summary = result.as_numpy_per_summary
print("Mean of x:", per_summary["mean"])
print("Std of x:", per_summary["std"])