rxnfit.solv_ode module

Integrate and plot concentration trajectories when rate laws are fully specified.

Uses rxnfit.solver_backend.solve_ode() for time stepping (including optional LSODA / numbalsoda; see that module for dispatch rules and fallbacks).

class rxnfit.solv_ode.RxnODEsolver(builder: RxnODEbuild, config: SolverConfig)

Bases: object

Integrate reaction-network ODEs and compare against experiments.

Time stepping is delegated to solve_ode() (LSODA / numbalsoda policy is documented there). Plotting and RSS-based metrics reuse rxnfit.plot_results and rxnfit.fit_metrics.

builder

Reaction system and RHS factory.

config

Solver options.

ode_construct

Tuple from the builder after solve_system().

solution

Latest integration result, or None if integration failed.

eval_fit_metrics(expdata_df, solution=None, verbose=True, recompute=True)

Return {'rss', 'tss', 'r2'} using fit_metrics().

NaNs are dropped consistently; TSS is per-species about the experimental mean.

Parameters:
  • expdata_df – Time in column 0; species columns match function_names.

  • solution – Optional trajectory for the interpolation path.

  • verbose – Print RSS and R² when true.

  • recompute – Forwarded to _compute_rss().

Returns:

Metric dictionary of floats.

Raises:

RuntimeError – Same as _compute_rss() (interpolation path).

Note

expdata_df_to_datasets() may raise ValueError if species columns required by function_names are missing from expdata_df.

solution_plot(solution=None, expdata_df: DataFrame | List[DataFrame] | None = None, species: List[str] | None = None, subplot_layout: Tuple[int, int] | None = None)

Plot concentrations and optional experimental overlays.

Delegates layout to plot_time_course_solutions().

Parameters:
  • solution – Trajectory to plot; defaults to solution.

  • expdata_df – One or more DataFrames (time + species); multiple frames create one subplot each while reusing the same simulated curve.

  • species – Subset of function_names; None plots every species.

  • subplot_layout – (rows, cols) when several DataFrames are supplied; None picks a vertical stack.

Returns:

None. The plotting helper returns (fig, axes), which this method does not pass through.

Raises:

ValueError – Passed through when species names are absent from the ODE species list (see plot_time_course_solutions()).

solve_system()

Integrate the model and cache ode_construct and solution.

Returns:

A pair (ode_construct, solution). solution is None only when integration raises; otherwise it is the integrator output (check success on SciPy-style results). Failures without exceptions still return a result object.

to_dataframe_list(solution=None, time_column_name='time')

Convert solution (or the cached one) to a one-element DataFrame list.

Parameters:
  • solution – Optional override; defaults to solution.

  • time_column_name – Name of the leading time column.

Returns:

[DataFrame] with species columns named like function_names.

Raises:

RuntimeError – When no solution exists.

class rxnfit.solv_ode.SolverConfig(y0: list, t_span: tuple, t_eval: ndarray | None = None, method: str = 'RK45', rtol: float = 1e-06, rate_const_values: Dict[str, float] | Callable[[float], Dict[str, float]] | None = None, symbolic_rate_const_keys: List[str] | None = None)

Bases: object

User-facing options for RxnODEsolver.

y0

Initial state (species concentrations in function_names order).

Type:

list

t_span

Integration window (t_start, t_end).

Type:

tuple

t_eval

Optional dense output times. For method="LSODA" without time-dependent rates, a grid may be built automatically when omitted.

Type:

numpy.ndarray | None

method

Integrator label passed to solve_ode().

Type:

str

rtol

Relative tolerance.

Type:

float

rate_const_values

Fixed dict k -> float or (t) -> dict when using lambdified ODEs with explicit rate arguments.

Type:

Dict[str, float] | Callable[[float], Dict[str, float]] | None

symbolic_rate_const_keys

Parameter order for those ODE signatures. rate_const_values and symbolic_rate_const_keys must both be set or both omitted.

Type:

List[str] | None

method: str = 'RK45'
rate_const_values: Dict[str, float] | Callable[[float], Dict[str, float]] | None = None
rtol: float = 1e-06
symbolic_rate_const_keys: List[str] | None = None
t_eval: ndarray | None = None
t_span: tuple
y0: list