# Open discussion on the state of differentiable physics in Julia

**URL:** <https://discourse.julialang.org/t/open-discussion-on-the-state-of-differentiable-physics-in-julia/72900>\
**Category:** Community\
**Tags:** sciml, ad, dp\
**Created:** [December 10, 2021, 4:07pm UTC](https://discourse.julialang.org/t/open-discussion-on-the-state-of-differentiable-physics-in-julia/72900 "2021-12-10T16:07:42Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [December 11, 2021, 3:51am UTC](https://discourse.julialang.org/t/open-discussion-on-the-state-of-differentiable-physics-in-julia/72900/8 "2021-12-11T03:51:16Z")

</div>

> [@JordiBolibar](#):
>
> Now, I must ask: what is the best strategy for these intermediate hard cases mixing linear algebra and mutation right now? From your analysis I see two potential ways out (but correct me if I’m wrong):
> 
> 1. Using Zygote, I know that in practice it can work for my problem, since I already have a manual implementation of it. The issue there is the fact that in order to avoid mutations one needs a ton of buffers and allocations, making any long forward run extremely memory costly to differentiate. A potential way to compensate that would be using a very efficient solver in order to minimize time stepping. Would that be enough to apply Zygote for such cases or one would still be limited to very short simulations (i.e. limited number of ODEs)? Otherwise, would there be any other way to optimize the code in order to use Zygote for such a problem?
> 2. Using Enzyme, I’ve encountered exactly the issue you mentioned, a BLAS call which is not supported. Enzyme seems like a perfect solution in order to avoid any memory allocation, but given the frequent use of linear algebra in this sort of physical problems, it also seems pretty daunting. Would it be feasible, for my problem, to use ChainRules for some functions in order to make it work, or that wouldn’t help at all with the lack of support for linear algebra?

1 is probably easiest. Take the performance hit of non-mutation and go with it. As your problem size increases, if you’re using an implicit method, progressively more time will be spent in the factorization and matrix multiplications (which grows as O(n^3)) and thus the [allocations won’t matter after awhile](https://www.stochasticlifestyle.com/when-do-micro-optimizations-matter-in-scientific-computing/). The hard place of course are the “midsized” problems for which the asymptotic behavior is not a good enough reason to leave off performance tricks. Still, it’s what I’d recommend today.

For 2, you cannot just use ChainRules with Enzyme easily. That’s kind of the whole problem there: when the code gets down to the LLVM level where Enzyme acts, there’s no guarantee that your function calls even exist anymore. Those calls may have been inlined by Julia, and so there would be no way to intercept it in that case. Fancy tricks can probably be used to get a lot of cases (and it has to get fancy even just to support allocations in the first place, or any dynamism), but I wouldn’t expect an average user to hack on that at all. Instead, BLAS support should be coming soon (it’s actively being worked on by some of the Julia Lab students), and that should be most of what’s needed in most cases.

---

_[View the full topic](https://discourse.julialang.org/t/open-discussion-on-the-state-of-differentiable-physics-in-julia/72900)._
