<jupyter_start><jupyter_text>Tutorial 8 - Solver optionsIn [Tutorial 7](./Tutorial%207%20-%20Model%20options.ipynb) we saw how to change the model options. In this tutorial we will show how to pass options to the solver.All models in PyBaMM have a default solver which is typically different depending on whether the model results in a system of ordinary differential equations (ODEs) or differential algebraic equations (DAEs). One of the most common options you will want to change is the solver tolerances. By default all tolerances are set to $10^{-6}$. However, depending on your simulation you may find you want to tighten the tolerances to obtain a more accurate solution, or you may want to loosen the tolerances to reduce the solve time. It is good practice to conduct a tolerance study, where you simulate the same problem with a tighter tolerances and compare the results. We do not show how to do this here, but we give an example of a mesh resolution study in the [next tutorial](./Tutorial%209%20-%20Changing%20the%20mesh.ipynb), which is conducted in a similar way.<jupyter_code>%pip install pybamm -q    # install PyBaMM if it is not installed
import pybamm<jupyter_output>Note: you may need to restart the kernel to use updated packages.<jupyter_text>Here we will change the absolute and relative tolerances, as well as the "mode" of the `CasadiSolver`. For a list of all the solver options  please consult the [documentation](https://pybamm.readthedocs.io/en/latest/source/solvers/index.html).The `CasadiSolver` can operate in a number of modes, including "safe" (default) and "fast". Safe mode performs step-and-check integration and supports event handling (e.g. you can integrate until you hit a certain voltage), and is the recommended for simulations of a full charge or discharge. Fast mode performs direct integration, ignoring events, and is recommended when simulating a drive cycle or other simulation where no events should be triggered.We'll solve the DFN with all the default options in both "safe" and "fast" mode and compare the solutions. For both simulations we'll use $10^{-3}$ for both the absolute and relative tolerance. For demonstration purposes we'll change the cut-off voltage to 3.6V so we can observe the different behaviour of the two solver modes.<jupyter_code># load model and parameters
model = pybamm.lithium_ion.DFN()
param = model.default_parameter_values
param["Lower voltage cut-off [V]"] = 3.6

# load solvers
safe_solver = pybamm.CasadiSolver(atol=1e-3, rtol=1e-3, mode="safe")
fast_solver = pybamm.CasadiSolver(atol=1e-3, rtol=1e-3, mode="fast")

# create simulations
safe_sim = pybamm.Simulation(model, parameter_values=param, solver=safe_solver)
fast_sim = pybamm.Simulation(model, parameter_values=param, solver=fast_solver)

# solve
safe_sim.solve([0, 3600])
print("Safe mode solve time: {}".format(safe_sim.solution.solve_time))
fast_sim.solve([0, 3600])
print("Fast mode solve time: {}".format(fast_sim.solution.solve_time))

# plot solutions
pybamm.dynamic_plot([safe_sim, fast_sim])<jupyter_output>Safe mode solve time: 297.861 ms
Fast mode solve time: 100.307 ms<jupyter_text>We see that both solvers give the same solution up to the time at which the cut-off voltage is reached. At this point the solver using "safe" mode stops, but the solver using "fast" mode carries on integrating until the final time. As its name suggests, "fast" mode integrates more quickly that "safe" mode, but is unsuitable if your simulation required events to be handled.Usually the default solver options provide a good combination of speed and accuracy, but we encourage you to investigate different solvers and options to find the best combination for your problem.In the [next tutorial](./Tutorial%209%20-%20Changing%20the%20mesh.ipynb) we show how to change the mesh.  ReferencesThe relevant papers for this notebook are:<jupyter_code>pybamm.print_citations()<jupyter_output>[1] <NAME>, <NAME>, <NAME>, <NAME>, and <NAME>. CasADi – A software framework for nonlinear optimization and optimal control. Mathematical Programming Computation, 11(1):1–36, 2019. doi:10.1007/s12532-018-0139-4.
[2] <NAME>, <NAME>, and <NAME>. Modeling of galvanostatic charge and discharge of the lithium/polymer/insertion cell. Journal of the Electrochemical society, 140(6):1526–1533, 1993. doi:10.1149/1.2221597.
[3] <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, <NAME>, and others. Array programming with NumPy. Nature, 585(7825):357–362, 2020. doi:10.1038/s41586-020-2649-2.
[4] <NAME>, <NAME>, <NAME>, <NAME>, and <NAME>. An asymptotic derivation of a single particle model with electrolyte. Journal of The Electrochemical Society, 166(15):A3693–A3706, 2019. doi:10.1149/[...]
{'fraction_non_alphanumeric': 0.08847128378378379, 'fraction_numerical': 0.041173986486486486, 'mean_word_length': 5.392712550607287, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '226702', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1327, 'n_words': 604, 'path': 'examples/notebooks/Getting Started/Tutorial 8 - Solver options.ipynb', 'repo_name': 'YannickNoelStephanKuhn/PyBaMM', 'size': '4931'}