rxnfit.solver_backend module
Central ODE driver: SciPy solve_ivp with optional numbalsoda for LSODA.
Implements the integration policy described in docs/spec_docs/numbalsoda2.md.
Notes
Numbalsoda is considered only for
method="LSODA", non-time-dependent rate laws, and a non-emptyt_evalgrid.Import failures, unsupported RHS, or integrator errors trigger a one-time
UserWarning(per reason) and fall back to RK45 viascipy.integrate.solve_ivp().If
time_dependentis true, LSODA requests are coerced to RK45 without calling numbalsoda.
- class rxnfit.solver_backend.LsodaImplicitTEvalMode(*values)
Bases:
EnumImplicit
t_evalconstruction mode for LSODA (names are part of the API).Each member selects the grid recipe documented in numbalsoda2.md section 5.5.
- COMPUTE_RSS = 2
- EVAL_ODE_FIT = 4
- INTEGRATE_DATASETS = 3
- SOLVE_SYSTEM = 1
- rxnfit.solver_backend.build_t_eval_when_none_for_lsoda(mode: LsodaImplicitTEvalMode, *, t_span=None, t_start=None, t_exp_col=None, t_exp=None, t_points=None) ndarray
Build a sorted unique
float64time grid for LSODA whent_evalis omitted.- Parameters:
mode – Which recipe to apply (
SOLVE_SYSTEM,COMPUTE_RSS, etc.).t_span – Required for
SOLVE_SYSTEMandINTEGRATE_DATASETSas(t0, t1).t_start – Dataset start time for
INTEGRATE_DATASETS.t_exp_col – Experimental times for
COMPUTE_RSS.t_exp – Concatenated experimental times for
INTEGRATE_DATASETS.t_points – Observation times for
EVAL_ODE_FIT.
- Returns:
One-dimensional
float64array in non-decreasing order with duplicates removed.- Raises:
ValueError – If required keyword arguments for
modeare missing or invalid.
- rxnfit.solver_backend.solve_ode(system_rhs, t_span, y0, t_eval=None, method='RK45', rtol=1e-06, atol=None, time_dependent=False)
Integrate
dy/dt = system_rhs(t, y)via SciPy or numbalsoda.Non-LSODA methods delegate to
scipy.integrate.solve_ivp(). Formethod="LSODA", seedocs/spec_docs/numbalsoda2.md: effectivet_spanfollowst_evalwhen rates are not time-dependent; callers must supplyt_evalor build it withbuild_t_eval_when_none_for_lsoda().- Parameters:
system_rhs – Callable
(t, y)returningdy/dt(SciPy convention).t_span – Interval
(t0, t1). For LSODA witht_evalsupplied, the solver uses the min/max oft_evalinternally (spec section 5.2).y0 – Initial state vector.
t_eval – Times where the solution is sampled. Required for LSODA (non-empty unless falling back to RK45 for an empty grid).
method –
solve_ivpmethod name, or"LSODA"to try numbalsoda.rtol – Relative integration tolerance.
atol – Absolute tolerance;
Noneselects library defaults.time_dependent – If True, LSODA is coerced to RK45 (internal callers set this from the kinetic model).
- Returns:
Object compatible with
scipy.integrate.OdeResult(t,y,success,message, …).
Note
Direct callers must set
time_dependent=Trueonly when rates depend on time (callable dict branch orhas_time_dependent_rates); otherwise behavior is undefined (see numbalsoda2.md section 14).