Integrator configuration
Integrator configuration¶
You can explicitly control which integrator is used for the simulations.
As all integrators have different settings, changing them is done on the integrator object itself, which can be found at Simulator().integrator
.
By default, the Assimulo
integrator is used.
However, that package currenlty requires installation via conda-forge
.
If mxlpy
was installed from pypi
, this package is not available and mxlpy
will fall back to the Scipy
package.
Thus, when setting integrator settings you should always check which integrator you are actually working with, as this otherwise might lead bugs on other systems.
In [1]:
Copied!
from functools import partial
from example_models import get_linear_chain_2v
from mxlpy import Simulator, unwrap
from mxlpy.integrators import Scipy
model = get_linear_chain_2v()
# You can explicitly set an integrator for the simulation
s = Simulator(model, integrator=Scipy)
# You can also change the default settings of each integrator
s = Simulator(model, integrator=partial(Scipy, atol=1e-6, rtol=1e-6))
s.simulate(5)
# You can change integration settings mid simulation
# As not all integrators have the same settings, we recommend explicitly checking
# which integrator is currently set
if isinstance(s.integrator, Scipy):
s.integrator.atol = 1e-8 # set absolute tolerance
s.integrator.rtol = 1e-8 # set relative tolerance
unwrap(s.simulate(10).get_result()).variables.plot()
from functools import partial
from example_models import get_linear_chain_2v
from mxlpy import Simulator, unwrap
from mxlpy.integrators import Scipy
model = get_linear_chain_2v()
# You can explicitly set an integrator for the simulation
s = Simulator(model, integrator=Scipy)
# You can also change the default settings of each integrator
s = Simulator(model, integrator=partial(Scipy, atol=1e-6, rtol=1e-6))
s.simulate(5)
# You can change integration settings mid simulation
# As not all integrators have the same settings, we recommend explicitly checking
# which integrator is currently set
if isinstance(s.integrator, Scipy):
s.integrator.atol = 1e-8 # set absolute tolerance
s.integrator.rtol = 1e-8 # set relative tolerance
unwrap(s.simulate(10).get_result()).variables.plot()
Out[1]:
<Axes: >
In [ ]:
Copied!