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:
objectIntegrate 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 reuserxnfit.plot_resultsandrxnfit.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
Noneif integration failed.
- eval_fit_metrics(expdata_df, solution=None, verbose=True, recompute=True)
Return
{'rss', 'tss', 'r2'}usingfit_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 raiseValueErrorif species columns required byfunction_namesare missing fromexpdata_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;Noneplots every species.subplot_layout –
(rows, cols)when several DataFrames are supplied;Nonepicks a vertical stack.
- Returns:
None. The plotting helper returns(fig, axes), which this method does not pass through.- Raises:
ValueError – Passed through when
speciesnames are absent from the ODE species list (seeplot_time_course_solutions()).
- solve_system()
Integrate the model and cache
ode_constructandsolution.- Returns:
A pair
(ode_construct, solution).solutionisNoneonly when integration raises; otherwise it is the integrator output (checksuccesson 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 likefunction_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:
objectUser-facing options for
RxnODEsolver.- y0
Initial state (species concentrations in
function_namesorder).- 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 -> floator(t) -> dictwhen 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_valuesandsymbolic_rate_const_keysmust 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