# Best Practices for Debugging DiffEqFlux Errors

**URL:** <https://discourse.julialang.org/t/best-practices-for-debugging-diffeqflux-errors/80618>\
**Category:** Modelling & Simulations\
**Tags:** diffeqflux\
**Created:** [May 6, 2022, 2:22pm UTC](https://discourse.julialang.org/t/best-practices-for-debugging-diffeqflux-errors/80618 "2022-05-06T14:22:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbu](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jbu](https://discourse.julialang.org/u/jbu)\
**Post date:** [May 6, 2022, 2:22pm UTC](https://discourse.julialang.org/t/best-practices-for-debugging-diffeqflux-errors/80618/1 "2022-05-06T14:22:33Z")

</div>

What are best practices for debugging when encountering errors with DiffEqFlux problems?

I’m working on creating a differentiable ODE simulator with DiffEqFlux. It’s an amazing and powerful tool! However, debugging taking gradients through ODEs is frequently more difficult than debugging standard Julia code. For example,

- Error messages can be massive. The names of single types can be 2000+ lines long in a stacktrace.
- Debugger.jl is difficult to use in this case. It causes Julia to interpret the DiffEqFlux + Zygote code, which results in a dramatic runtime performance drop.
- When using [Infiltrator.jl](https://github.com/JuliaDebug/Infiltrator.jl) or printouts during the differentiation process, the intermediate types used for differentiation (e.g. [dual numbers](https://juliadiff.org/ForwardDiff.jl/stable/dev/how_it_works/#Dual-Number-Implementation), adjoints, etc) can be tricky to map back to the original parameters of the simulation.

I would love to know any tips or tricks to isolate and identify bugs when differentiating through DiffEqFlux ODEs / DAEs / etc. Here’s what I’ve tried so far with some success:

- Double check that the model is actually differentiable.
- Check that I can take the gradients of individual sub-functions used within my ODE dynamics function.
- Comment out chunks of the dynamics function, and incrementally uncomment them until the error returns.

Any additional suggestions?

_(This isn’t intended to be negative criticism directed specifically at DiffEqFlux–it’s a fantastic tool and I’m excited to use it going forward! As a fairly new user, I’m simply trying to speed up my debugging process.)_

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 6, 2022, 4:26pm UTC](https://discourse.julialang.org/t/best-practices-for-debugging-diffeqflux-errors/80618/2 "2022-05-06T16:26:19Z")

</div>

I know about this issue and I think the best thing to do is to make a video, which I intend to do
