Skip to content

Commit

Permalink
Use rtol and atol with solve_ivp
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe S. S. Schneider authored and schneiderfelipe committed Nov 27, 2020
1 parent cdae256 commit 42e3b46
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 5 deletions.
Binary file modified docs/_static/drc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/first-order.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/michaelis-menten-dydt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/michaelis-menten-tof.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/michaelis-menten.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_static/simple-first-order.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion overreact/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def get_drc(
compounds,
y0,
t_span=None,
method="BDF",
method="Radau",
qrrho=True,
scale="l mol-1 s-1",
temperature=298.15,
Expand Down
18 changes: 14 additions & 4 deletions overreact/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
if _found_jax:
import jax.numpy as jnp
from jax import jacfwd
from jax import jit
from jax.config import config

config.update("jax_enable_x64", True)
else:
jnp = np


def get_y(dydt, y0, t_span=None, method="BDF"):
def get_y(dydt, y0, t_span=None, method="Radau", rtol=1e-3, atol=1e-6):
"""Simulate a reaction scheme from its rate function.
This uses scipy's ``solve_ivp`` under the hood.
Expand All @@ -48,6 +47,8 @@ def get_y(dydt, y0, t_span=None, method="BDF"):
Integration method to use. See `scipy.integrade.solve_ivp` for details.
Kinetics problems are very often stiff and, as such, "RK45" is
normally unsuited. "Radau", "BDF" or "LSODA" are good choices.
rtol, atol : array-like
See `scipy.integrade.solve_ivp` for details.
Returns
-------
Expand Down Expand Up @@ -114,7 +115,16 @@ def get_y(dydt, y0, t_span=None, method="BDF"):
if hasattr(dydt, "jac"):
jac = dydt.jac

res = _solve_ivp(dydt, t_span, y0, method=method, dense_output=True, jac=jac)
res = _solve_ivp(
dydt,
t_span,
y0,
method=method,
dense_output=True,
rtol=rtol,
atol=atol,
jac=jac,
)
y = res.sol

def r(t):
Expand Down Expand Up @@ -213,7 +223,7 @@ def _dydt(t, y, k=k_adj, M=M):
return jnp.dot(A, r)

if _found_jax:
_dydt = jit(_dydt)
_dydt = _dydt

def _jac(t, y, k=k_adj, M=M):
# _jac(t, y)[i, j] == d f_i / d y_j
Expand Down

0 comments on commit 42e3b46

Please sign in to comment.