# \#differentiation

**URL:** https://discourse.julialang.org/tag/differentiation/110.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Exact Network Surgery and Reactive Computational Graphs in Julia with NeuroDSL](https://discourse.julialang.org/t/exact-network-surgery-and-reactive-computational-graphs-in-julia-with-neurodsl/138303)

<div class="topic-metadata">

**Author:** [@Khemais\_Abdallah](https://discourse.julialang.org/u/Khemais_Abdallah)\
**Replies:** 14\
**Last updated:** [July 22, 2026, 12:21pm UTC](https://discourse.julialang.org/t/exact-network-surgery-and-reactive-computational-graphs-in-julia-with-neurodsl/138303 "2026-07-22T12:21:01Z")

</div>

Exact Network Surgery and Reactive Computational Graphs in Julia with NeuroDSL Hi everyone, I’d like to share some recent theoretical and systems results from NeuroDSL, a persistent, reactive computational graph framewo…

---

## [Why does ForwardDiff.jl give me all-zero Jacobian matrix?](https://discourse.julialang.org/t/why-does-forwarddiff-jl-give-me-all-zero-jacobian-matrix/137714)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 5\
**Last updated:** [June 22, 2026, 7:45am UTC](https://discourse.julialang.org/t/why-does-forwarddiff-jl-give-me-all-zero-jacobian-matrix/137714 "2026-06-22T07:45:14Z")

</div>

Hi guys, I am using one Julia-based model from https://github.com/LandEcosystems/Sindbad.jl, and tries to use ForwardDiff.jl to calculate the Jacobian of the cost function to the optimized parameters. I run the pipeline…

---

## [Differentiation of incomplete Beta function](https://discourse.julialang.org/t/differentiation-of-incomplete-beta-function/49675)

<div class="topic-metadata">

**Author:** [@arzwa](https://discourse.julialang.org/u/arzwa)\
**Replies:** 4\
**Last updated:** [October 5, 2025, 12:55pm UTC](https://discourse.julialang.org/t/differentiation-of-incomplete-beta-function/49675 "2025-10-05T12:55:22Z")

</div>

First, to give some context: my use case is equivalent to the following contrived example, in which I would like to define a (Turing.jl) probabilistic program that uses a discretized Beta mixture model. @model themodel(…

---

## [Plugging DifferentiationInterface.jl into pytorch](https://discourse.julialang.org/t/plugging-differentiationinterface-jl-into-pytorch/132598)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 5\
**Last updated:** [September 23, 2025, 7:32pm UTC](https://discourse.julialang.org/t/plugging-differentiationinterface-jl-into-pytorch/132598 "2025-09-23T19:32:28Z")

</div>

I preface this with saying that I really am not very experienced with both pytorch and juliatorch, and apologize for any misunderstandings that I have. We are developing a physics simulation ecosystem that can be differ…

---

## [Automatic differentiation of complex functions: simple workaround](https://discourse.julialang.org/t/automatic-differentiation-of-complex-functions-simple-workaround/75775)

<div class="topic-metadata">

**Author:** [@wsshin](https://discourse.julialang.org/u/wsshin)\
**Replies:** 7\
**Last updated:** [September 11, 2025, 9:53am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-complex-functions-simple-workaround/75775 "2025-09-11T09:53:48Z")

</div>

I would like to share a simple technique to perform automatic differentiation (AD) of complex functions. I developed this technique a few months ago and have been using it successfully for past few months. The techniqu…

---

## [How should constant literals be typed in Differentiable Code?](https://discourse.julialang.org/t/how-should-constant-literals-be-typed-in-differentiable-code/131965)

<div class="topic-metadata">

**Author:** [@stevenhughes](https://discourse.julialang.org/u/stevenhughes)\
**Replies:** 0\
**Last updated:** [August 30, 2025, 2:32pm UTC](https://discourse.julialang.org/t/how-should-constant-literals-be-typed-in-differentiable-code/131965 "2025-08-30T14:32:49Z")

</div>

Hello, I wrote code that I now need to make differentiable. I’ve read the best practice docs, and my code is differentiating (REPL compile times are seriously painful though). I use AI to read my code to help me impro…

---

## [Differentiation of struct based simulations and applications](https://discourse.julialang.org/t/differentiation-of-struct-based-simulations-and-applications/131319)

<div class="topic-metadata">

**Author:** [@stevenhughes](https://discourse.julialang.org/u/stevenhughes)\
**Replies:** 5\
**Last updated:** [August 5, 2025, 12:03pm UTC](https://discourse.julialang.org/t/differentiation-of-struct-based-simulations-and-applications/131319 "2025-08-05T12:03:54Z")

</div>

Hello, I’m building an aerospace simulator and solver in Julia. It’s coming together well, and I plan to release the first public version in about a month. The system models spacecraft, maneuvers, events, and so on, and…

---

## [Support for adjoint sensitivities with \`SciMLStructures\` in ODE problems](https://discourse.julialang.org/t/support-for-adjoint-sensitivities-with-scimlstructures-in-ode-problems/131049)

<div class="topic-metadata">

**Author:** [@albangossard](https://discourse.julialang.org/u/albangossard)\
**Replies:** 2\
**Last updated:** [July 25, 2025, 6:15pm UTC](https://discourse.julialang.org/t/support-for-adjoint-sensitivities-with-scimlstructures-in-ode-problems/131049 "2025-07-25T18:15:02Z")

</div>

Hi all, In complex geoscientific models, it’s common to have many simulation parameters that need to be passed into the ODE function. At the same time, we often want to compute gradients with respect to some of these pa…

---

## [Combining \`SparseDiffTools.jl\` and \`OrdinaryDiffEq.jl\`](https://discourse.julialang.org/t/combining-sparsedifftools-jl-and-ordinarydiffeq-jl/130555)

<div class="topic-metadata">

**Author:** [@DanDoe](https://discourse.julialang.org/u/DanDoe)\
**Replies:** 8\
**Last updated:** [July 9, 2025, 10:53am UTC](https://discourse.julialang.org/t/combining-sparsedifftools-jl-and-ordinarydiffeq-jl/130555 "2025-07-09T10:53:43Z")

</div>

I managed to get the sparsity structure detection (via SparseDiffTools.j) of the rhs! function (the RHS of the ODE problem fed into OrdinaryDiffEq.jl) for our code Trixi.jl to run. Can I supply the cache = sparse\_jacob…

---

## [Calling C Code with Automatic Differentiation in Julia](https://discourse.julialang.org/t/calling-c-code-with-automatic-differentiation-in-julia/129503)

<div class="topic-metadata">

**Author:** [@fgittins](https://discourse.julialang.org/u/fgittins)\
**Replies:** 6\
**Last updated:** [June 2, 2025, 7:39am UTC](https://discourse.julialang.org/t/calling-c-code-with-automatic-differentiation-in-julia/129503 "2025-06-02T07:39:48Z")

</div>

Hi all, I’m reaching out to see if anyone in the Julia community has experience or advice on calling C code from Julia in a way that still supports automatic differentiation (AD). My motivation I’m working on a project…

---

## [Best way to prevent AD to differentiate through useless or zero gradient function](https://discourse.julialang.org/t/best-way-to-prevent-ad-to-differentiate-through-useless-or-zero-gradient-function/126927)

<div class="topic-metadata">

**Author:** [@FerreolS](https://discourse.julialang.org/u/FerreolS)\
**Replies:** 2\
**Last updated:** [March 13, 2025, 9:05pm UTC](https://discourse.julialang.org/t/best-way-to-prevent-ad-to-differentiate-through-useless-or-zero-gradient-function/126927 "2025-03-13T21:05:03Z")

</div>

I want to minimize a function of the type: x = \\textrm{argmin}\_x \\min\_a || f(x) a - y ||^2 as it is quadratic in a we know the optimum in a is a(x) = (f(x)^T f(x))^{-1} f(x)^T y so we minimize x = \\text{argmin}\_x …

---

## [Difficulty when differentiating with DifferentiationInterface.jl and Mooncake.jl](https://discourse.julialang.org/t/difficulty-when-differentiating-with-differentiationinterface-jl-and-mooncake-jl/125982)

<div class="topic-metadata">

**Author:** [@Nikos\_Gianniotis](https://discourse.julialang.org/u/Nikos_Gianniotis)\
**Replies:** 3\
**Last updated:** [February 17, 2025, 5:23pm UTC](https://discourse.julialang.org/t/difficulty-when-differentiating-with-differentiationinterface-jl-and-mooncake-jl/125982 "2025-02-17T17:23:25Z")

</div>

Hello everyone. I am stuck with the following problem for which I have created below a MWE. It concerns automatic differentiation using DifferentiationInterface.jl together with Mooncake.jl. From the error message I get,…

---

## [Warning secondorder ADtype in optimization.jl](https://discourse.julialang.org/t/warning-secondorder-adtype-in-optimization-jl/122539)

<div class="topic-metadata">

**Author:** [@JADekker](https://discourse.julialang.org/u/JADekker)\
**Replies:** 3\
**Last updated:** [November 12, 2024, 10:27am UTC](https://discourse.julialang.org/t/warning-secondorder-adtype-in-optimization-jl/122539 "2024-11-12T10:27:52Z")

</div>

Hi, I’m trying to replicate the example from Optim.jl · Optimization.jl, i.e. I’m running using Optimization, OptimizationOptimJL function RunTest() rosenbrock(x, p) = (p\[1\] - x\[1\])^2 + p\[2\] \* (x\[2\] - x\[1\]^2)^2 …

---

## [Correct way of computing adjoints/gradients with dense solution of ODE](https://discourse.julialang.org/t/correct-way-of-computing-adjoints-gradients-with-dense-solution-of-ode/121964)

<div class="topic-metadata">

**Author:** [@facusapienza](https://discourse.julialang.org/u/facusapienza)\
**Replies:** 5\
**Last updated:** [October 31, 2024, 6:17pm UTC](https://discourse.julialang.org/t/correct-way-of-computing-adjoints-gradients-with-dense-solution-of-ode/121964 "2024-10-31T18:17:18Z")

</div>

Hi all, I am trying to use the interpolated solution of my ODE for adjoint sensitivity analysis. Since I have a very small system of ODEs (n=3), I am interested in evaluating the performance of continuous adjoint method…

---

## [Jacobian calculation with FastDifferentiation.jl](https://discourse.julialang.org/t/jacobian-calculation-with-fastdifferentiation-jl/118501)

<div class="topic-metadata">

**Author:** [@niro](https://discourse.julialang.org/u/niro)\
**Replies:** 2\
**Last updated:** [August 23, 2024, 6:38pm UTC](https://discourse.julialang.org/t/jacobian-calculation-with-fastdifferentiation-jl/118501 "2024-08-23T18:38:15Z")

</div>

Hi there, I wanted to test this package to compute the Jacobian of a relatively lengthy function. However, I encounter an issue because the result is apparently not correct if I compare with other methods. Yet, the cod…

---

## [ZeroTangent definition](https://discourse.julialang.org/t/zerotangent-definition/118069)

<div class="topic-metadata">

**Author:** [@mary](https://discourse.julialang.org/u/mary)\
**Replies:** 2\
**Last updated:** [August 12, 2024, 4:55am UTC](https://discourse.julialang.org/t/zerotangent-definition/118069 "2024-08-12T04:55:02Z")

</div>

Hi, I am using chainrulecore for gradient calculation and rrule. I am trying to follow tutorial 18 of gridap. I cant understand the ZeroTangent in the code why we are using that and what it is suppose to do. I’ve read s…

---

## [ForwardDiff tagcount with custom diff rules](https://discourse.julialang.org/t/forwarddiff-tagcount-with-custom-diff-rules/117534)

<div class="topic-metadata">

**Author:** [@dchang10](https://discourse.julialang.org/u/dchang10)\
**Replies:** 4\
**Last updated:** [July 27, 2024, 4:00pm UTC](https://discourse.julialang.org/t/forwarddiff-tagcount-with-custom-diff-rules/117534 "2024-07-27T16:00:26Z")

</div>

I’m writing a custom gradient for a function that takes two derivatives using ForwardDiff. I receive an error unless I specify the tag for the returned Dual. I figured that the tag I should return depends on the tag coun…

---

## [Generating finite-difference stencils](https://discourse.julialang.org/t/generating-finite-difference-stencils/85876)

<div class="topic-metadata">

**Author:** [@dorn-gerhard](https://discourse.julialang.org/u/dorn-gerhard)\
**Replies:** 19\
**Last updated:** [July 23, 2024, 10:39pm UTC](https://discourse.julialang.org/t/generating-finite-difference-stencils/85876 "2024-07-23T22:39:44Z")

</div>

Regarding the second suggested approach in the topic title: discrete derivatives (without interpolating data) Is there a Julia package that performs discrete derivatives (e.g. using some higher order stencils) also for …

---

## [Automatic differentiation with density matrix in yao](https://discourse.julialang.org/t/automatic-differentiation-with-density-matrix-in-yao/115467)

<div class="topic-metadata">

**Author:** [@stone44](https://discourse.julialang.org/u/stone44)\
**Replies:** 9\
**Last updated:** [June 21, 2024, 12:21pm UTC](https://discourse.julialang.org/t/automatic-differentiation-with-density-matrix-in-yao/115467 "2024-06-21T12:21:47Z")

</div>

Hey there, i am currently implementing a quantum variational algorithm, where my goal is to minimize a cost function, where i use a gradient based optimzer. Since i have no analytically closed form of my gradient, i am …

---

## [GTPSA.jl: A Julia interface to the new GTPSA library for fast, high-order automatic differentiation](https://discourse.julialang.org/t/gtpsa-jl-a-julia-interface-to-the-new-gtpsa-library-for-fast-high-order-automatic-differentiation/115370)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 13\
**Last updated:** [June 11, 2024, 3:06am UTC](https://discourse.julialang.org/t/gtpsa-jl-a-julia-interface-to-the-new-gtpsa-library-for-fast-high-order-automatic-differentiation/115370 "2024-06-11T03:06:04Z")

</div>

GTPSA.jl is a new Julia package that provides a full-featured interface to the Generalised Truncated Power Series Algebra library for computing Taylor expansions, or Truncated Power Series (TPSs) of real and complex mult…

---

## [Optimization with LBFGS gives DimensionMismatch("dimensions must match")](https://discourse.julialang.org/t/optimization-with-lbfgs-gives-dimensionmismatch-dimensions-must-match/22167)

<div class="topic-metadata">

**Author:** [@mzhenirovskyy](https://discourse.julialang.org/u/mzhenirovskyy)\
**Replies:** 9\
**Last updated:** [April 14, 2024, 7:39pm UTC](https://discourse.julialang.org/t/optimization-with-lbfgs-gives-dimensionmismatch-dimensions-must-match/22167 "2024-04-14T19:39:36Z")

</div>

My objective function has to solve an ODE. When I use the gradient-free algorithm (e.g NelderMead) to do optimization, everything is OK. But with gradient-based (e.g. LBFGS) I get the error: DimensionMismatch(“dimension…

---

## [Is there a differentiable implementation of matrix square root?](https://discourse.julialang.org/t/is-there-a-differentiable-implementation-of-matrix-square-root/112334)

<div class="topic-metadata">

**Author:** [@marcsgil](https://discourse.julialang.org/u/marcsgil)\
**Replies:** 5\
**Last updated:** [March 31, 2024, 10:15pm UTC](https://discourse.julialang.org/t/is-there-a-differentiable-implementation-of-matrix-square-root/112334 "2024-03-31T22:15:47Z")

</div>

Hello! I’m trying to make the following code work: using ForwardDiff, LinearAlgebra # Fidelity between two density matrices function fidelity(ρ::AbstractMatrix, σ::AbstractMatrix) sqrt\_ρ = sqrt(ρ) abs2(tr(sqrt…

---

## [What range of LinearAlgebra does Enzyme support?](https://discourse.julialang.org/t/what-range-of-linearalgebra-does-enzyme-support/111552)

<div class="topic-metadata">

**Author:** [@ToPo](https://discourse.julialang.org/u/ToPo)\
**Replies:** 6\
**Last updated:** [March 14, 2024, 3:08am UTC](https://discourse.julialang.org/t/what-range-of-linearalgebra-does-enzyme-support/111552 "2024-03-14T03:08:21Z")

</div>

Hi all, I would like to use the LinearAlgebra package in Enzyme. Since Julia’s sparse matrix package, SparseArrays, did not seem to be available, I created my own sparse-matrix library. When I looked at the Enzyme tes…

---

## [Forward differentiation and differential equations](https://discourse.julialang.org/t/forward-differentiation-and-differential-equations/21002)

<div class="topic-metadata">

**Author:** [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Replies:** 13\
**Last updated:** [November 7, 2023, 9:01am UTC](https://discourse.julialang.org/t/forward-differentiation-and-differential-equations/21002 "2023-11-07T09:01:46Z")

</div>

I am trying to use forward AD in combination with solving an ODE using DifferentialEquations.jl. I want to use an own loss function. However, with the is-in-place version there is a type assertion error. I have come up w…

---

## [Differentiation (Zygote, but the issue is likely in ChainRules) return different types with \`Diagonal\`](https://discourse.julialang.org/t/differentiation-zygote-but-the-issue-is-likely-in-chainrules-return-different-types-with-diagonal/108608)

<div class="topic-metadata">

**Author:** [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Replies:** 2\
**Last updated:** [January 10, 2024, 7:09pm UTC](https://discourse.julialang.org/t/differentiation-zygote-but-the-issue-is-likely-in-chainrules-return-different-types-with-diagonal/108608 "2024-01-10T19:09:24Z")

</div>

Dear All, We are hacking a bit AbstractGP.jl and we have found an inconsistency in the returned type of Diagonal, which causes Zygote to complain. An MWE adapted from GPs is using LinearAlgebra, Zygote K = \[1.0009999…

---

## [Taking gradients of a matrix exponential](https://discourse.julialang.org/t/taking-gradients-of-a-matrix-exponential/107865)

<div class="topic-metadata">

**Author:** [@Bizzi](https://discourse.julialang.org/u/Bizzi)\
**Replies:** 10\
**Last updated:** [January 2, 2024, 3:48pm UTC](https://discourse.julialang.org/t/taking-gradients-of-a-matrix-exponential/107865 "2024-01-02T15:48:45Z")

</div>

I’m having trouble differentiating simple matrix exponentials. ForwardDiff and ReverseDiff can’t really do it, while Zygote’s result is type-unstable. using Zygote, ForwardDiff, ReverseDiff M = rand(2,2) ReverseDiff.gr…

---

## [Creating AD-friendly functions](https://discourse.julialang.org/t/creating-ad-friendly-functions/100914)

<div class="topic-metadata">

**Author:** [@Bizzi](https://discourse.julialang.org/u/Bizzi)\
**Replies:** 2\
**Last updated:** [June 28, 2023, 3:16pm UTC](https://discourse.julialang.org/t/creating-ad-friendly-functions/100914 "2023-06-28T15:16:26Z")

</div>

Hello everyone. I’m in the process of creating a chained composition of functions, similar to a Flux or Lux network, which I’ll later differentiate for the purpose of solving differential equations. Following the discus…

---

## [Zygote.jl: How to get the gradient of sparse matrix](https://discourse.julialang.org/t/zygote-jl-how-to-get-the-gradient-of-sparse-matrix/59067)

<div class="topic-metadata">

**Author:** [@Richard-Li](https://discourse.julialang.org/u/Richard-Li)\
**Replies:** 11\
**Last updated:** [June 13, 2023, 5:17pm UTC](https://discourse.julialang.org/t/zygote-jl-how-to-get-the-gradient-of-sparse-matrix/59067 "2023-06-13T17:17:20Z")

</div>

Hi there, I am trying to differentiate through sparse matrix, and here is the MWE: using LinearAlgebra using SparseArrays using ChainRulesCore using Zygote Zygote.@adjoint function SparseMatrixCSC{T,N}(arr) where {T,N}…

---

## [Using Flux: gradient on DifferentialEquations: solve results in an error](https://discourse.julialang.org/t/using-flux-gradient-on-differentialequations-solve-results-in-an-error/79564)

<div class="topic-metadata">

**Author:** [@vtac](https://discourse.julialang.org/u/vtac)\
**Replies:** 11\
**Last updated:** [May 8, 2023, 9:56am UTC](https://discourse.julialang.org/t/using-flux-gradient-on-differentialequations-solve-results-in-an-error/79564 "2023-05-08T09:56:27Z")

</div>

I am trying to take the derivative of a function that is defined as the solution of an ODE. But gradient throws an error: using Flux: gradient using DifferentialEquations: Tsit5, ODEProblem, solve using DiffEqSensitivit…

---

## [Automatic differentiation in different cases](https://discourse.julialang.org/t/automatic-differentiation-in-different-cases/98268)

<div class="topic-metadata">

**Author:** [@Djamil\_Lakhdar-Hamin](https://discourse.julialang.org/u/Djamil_Lakhdar-Hamin)\
**Replies:** 2\
**Last updated:** [May 3, 2023, 8:10pm UTC](https://discourse.julialang.org/t/automatic-differentiation-in-different-cases/98268 "2023-05-03T20:10:57Z")

</div>

I am trying to figure out : how to automatically differentiate some function f(x1,x2,x3…) for vector of numbers. I want to use one package preferably , but if I have to mix, I want to mix zygote with ForwardDiff. I th…

[Next page](https://discourse.julialang.org/tag/differentiation/110.md?match_all_tags=true&page=1&tags%5B%5D=differentiation)
