# Setting \`abstol\` and \`reltol\` when solving the Schrödinger equation with OrdinaryDiffEq

**URL:** <https://discourse.julialang.org/t/setting-abstol-and-reltol-when-solving-the-schrodinger-equation-with-ordinarydiffeq/125534>\
**Category:** Quantum\
**Tags:** question, ode\
**Created:** [February 4, 2025, 2:19pm UTC](https://discourse.julialang.org/t/setting-abstol-and-reltol-when-solving-the-schrodinger-equation-with-ordinarydiffeq/125534 "2025-02-04T14:19:04Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [February 4, 2025, 5:17pm UTC](https://discourse.julialang.org/t/setting-abstol-and-reltol-when-solving-the-schrodinger-equation-with-ordinarydiffeq/125534/5 "2025-02-04T17:17:19Z")

</div>

Indeed, `reltol` fixes the problem. I don’t think I have a good grasp on setting `abstol` and `reltol` reliably. The way I’d usually think about errors in propagators would for the `norm(Ψ - Ψ_exact) < err`, where `Ψ` is the result of the propagator at final time `T`, `Ψ_exact` is the hypothetical analytic solution (in practice, obtained from a solver with all precisions cranked up to the max), and `err` is the error I’d like to prescribe (typically something like `1e-12`). It’s a little non-ideal that there are two error parameters `abstol`, `reltol` that I have to tweak, and I have to get a better understanding of how to connect my `err` with `abstol` and `reltol`.

I suppose the key is the equation given in the “Basic step size control” of the [`CommonSolve.Solve` docstring](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/#CommonSolve.solve-Tuple%7BSciMLBase.AbstractDEProblem,%20Vararg%7BAny%7D%7D), but I have to have a closer look (Unless someone with more experience can give me some guidelines 😉 )

> there’s also no need to include the `saveat = tlist`

Yeah, but there are reasons I need the states exactly on that time grid. But this is really just for the sake of the MWE / comparing with my [normal solver](https://juliaquantumcontrol.github.io/QuantumPropagators.jl/dev/methods/#method_cheby). In my actual code, I use the [integrator interface](https://docs.sciml.ai/DiffEqDocs/stable/basics/integrator/). But I do have to work on a specific time grid ([because that’s how gradients in quantum control work](https://quantum-journal.org/papers/q-2022-12-07-871/)).

> This is not my area, but `Tsit5()` is probably not the best choice for solver for this problem

That’s interesting… I’m very much not an expert in general ODE solver methods. But to my knowledge when people have “traditionally” used ODE solvers for quantum dynamics (as an upgrade from something low-precision like Crank-Nicholson), they’ve typically used RK45. So I just sort of assumed `Tsit5` would be the equivalent-but-better default.

> [@ChrisRackauckas](#):
>
> Standard RK methods are not norm preserving.

The title of the post may be a bit misleading, in that I care about “norm-preserving” only in so far as I care about “correct” in terms of the aforementioned `norm(Ψ - Ψ_exact) < err`, and that I know `Ψ_exact` to have norm 1. It’s not necessarily a problem that errors are reflected in a deviation of the norm. At least that’s pretty easy to detect, and thus possibly preferable to “grossly wrong, but with the correct norm”.

That’s not to say that I wouldn’t want to try solvers that inherently norm-preserving. My “workhorse propagator” of expanding `exp(-i*H*dt)` in Chebychev polynomials (the “correct” solution in my OP) is norm-preserving, after all. But that propagator is piecewise-constant, and the reason I ran into this whole issue was that I wanted to double-check with `OrdinaryDiffEq` that I wasn’t running into time-discretization errors. That is, compare with the solution for the time-continuous (adaptive time step) ODE solver. Which then, with the ill-advised approach of using `OrdinaryDiffEq` as a black box, gave me wildly inaccurate results.

> [@Mason](#):
>
> asking for an `abstol` also hurt accuracy

That’s weird, and a little concerning. But ultimately, I’m really just going to have to nail down how to reliably choose `abstol` and `reltol` based on my more general notion of “error”, and then see what is a good default ODE method for quantum dynamics.

This particular ODE might also be a bit pathological. I’m actually probing here a parameter regime where the adiabatic Landau-Zener transition (where everything would evolve very smoothly) breaks down. Still, it would be good to have a reliable ODE solver in my toolbox that doesn’t require much handholding.

I’ll definitely have a look at `Vern8` and the other solvers Chris mentioned.

Thanks!

---

_[View the full topic](https://discourse.julialang.org/t/setting-abstol-and-reltol-when-solving-the-schrodinger-equation-with-ordinarydiffeq/125534)._
