# \#forwarddiff

**URL:** https://discourse.julialang.org/tag/forwarddiff/363.md

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

---

## [How to use ForwardDiff.jl with inv and matrix exponential?](https://discourse.julialang.org/t/how-to-use-forwarddiff-jl-with-inv-and-matrix-exponential/137880)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 15\
**Last updated:** [July 4, 2026, 8:31pm UTC](https://discourse.julialang.org/t/how-to-use-forwarddiff-jl-with-inv-and-matrix-exponential/137880 "2026-07-04T20:31:45Z")

</div>

I have a question listed here: Why does ForwardDiff.jl give me all-zero Jacobian matrix?, and I found it might be due to part of the function which contains inv and exp (matrix exponential…) from ExponentialUtilities. I …

---

## [How does ForwardDiff.jl and FiniteDiff.jl handle edge-hitting cases?](https://discourse.julialang.org/t/how-does-forwarddiff-jl-and-finitediff-jl-handle-edge-hitting-cases/137828)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 3\
**Last updated:** [June 27, 2026, 11:18pm UTC](https://discourse.julialang.org/t/how-does-forwarddiff-jl-and-finitediff-jl-handle-edge-hitting-cases/137828 "2026-06-27T23:18:02Z")

</div>

Hi guys, I am using ForwardDiff.jl to calculate the parameter uncertainty in my model (see below about the more detailed information…). I am wondering, how does ForwardDiff.jl and FiniteDiff.jl handle the edge-hitting p…

---

## [Sensitivity Analysis on ODE system](https://discourse.julialang.org/t/sensitivity-analysis-on-ode-system/137757)

<div class="topic-metadata">

**Author:** [@violabini](https://discourse.julialang.org/u/violabini)\
**Replies:** 4\
**Last updated:** [June 25, 2026, 9:40am UTC](https://discourse.julialang.org/t/sensitivity-analysis-on-ode-system/137757 "2026-06-25T09:40:40Z")

</div>

Hi everyone, I am trying to use automatic differentiation in julia to compute the Jacobian of my outputs wrt my design variables for local sensitivity, but my ODEs are nearly coupled as for example du\[3\]=A\*du\[2\]+B u\[1\].…

---

## [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…

---

## [ForwardDiff Lie brackets allocate with StaticArrays](https://discourse.julialang.org/t/forwarddiff-lie-brackets-allocate-with-staticarrays/137248)

<div class="topic-metadata">

**Author:** [@tremelow](https://discourse.julialang.org/u/tremelow)\
**Replies:** 0\
**Last updated:** [May 22, 2026, 9:34pm UTC](https://discourse.julialang.org/t/forwarddiff-lie-brackets-allocate-with-staticarrays/137248 "2026-05-22T21:34:52Z")

</div>

I’m working on a code where I need Lie brackets of Lie brackets, but computing the Jacobian of a Lie bracket allocates data. Here’s a MWE using StaticArrays using BenchmarkTools import ForwardDiff f(x::SVector{2,T}) wh…

---

## [AD over runtime-selected fields in nested structs — design patterns?](https://discourse.julialang.org/t/ad-over-runtime-selected-fields-in-nested-structs-design-patterns/136882)

<div class="topic-metadata">

**Author:** [@stevenhughes](https://discourse.julialang.org/u/stevenhughes)\
**Replies:** 4\
**Last updated:** [April 26, 2026, 12:10pm UTC](https://discourse.julialang.org/t/ad-over-runtime-selected-fields-in-nested-structs-design-patterns/136882 "2026-04-26T12:10:49Z")

</div>

We have a framework where users define models as nested structs and declare at runtime which fields are optimization variables. The framework then needs to differentiate constraints/objectives with respect to those selec…

---

## [Automatic differentiation of function using \`LinearProblem\`](https://discourse.julialang.org/t/automatic-differentiation-of-function-using-linearproblem/136063)

<div class="topic-metadata">

**Author:** [@NoFishLikeIan](https://discourse.julialang.org/u/NoFishLikeIan)\
**Replies:** 8\
**Last updated:** [March 22, 2026, 2:08pm UTC](https://discourse.julialang.org/t/automatic-differentiation-of-function-using-linearproblem/136063 "2026-03-22T14:08:42Z")

</div>

I am trying to optimise a function f: \\mathbb{R}^n \\to \\mathbb{R} which internally solves a linear problem, informally something like f(w) = g(x) where x solves A(w) x= b(x). To do this I am using LinearSolve and automa…

---

## [Parameter sensitivity of ODE with parameter-dependent event](https://discourse.julialang.org/t/parameter-sensitivity-of-ode-with-parameter-dependent-event/103602)

<div class="topic-metadata">

**Author:** [@Neodym](https://discourse.julialang.org/u/Neodym)\
**Replies:** 4\
**Last updated:** [February 2, 2026, 11:28am UTC](https://discourse.julialang.org/t/parameter-sensitivity-of-ode-with-parameter-dependent-event/103602 "2026-02-02T11:28:17Z")

</div>

Hey, I’m trying to get parameter sensitivities of an ODE problem with a parameter-dependent time-event. Just throwing AD at the problem doesn’t seem to work: using OrdinaryDiffEq using SciMLSensitivity using ForwardDi…

---

## [Best way to forcibly passify a result using ForwardDiff?](https://discourse.julialang.org/t/best-way-to-forcibly-passify-a-result-using-forwarddiff/135283)

<div class="topic-metadata">

**Author:** [@afleming](https://discourse.julialang.org/u/afleming)\
**Replies:** 3\
**Last updated:** [January 28, 2026, 10:30am UTC](https://discourse.julialang.org/t/best-way-to-forcibly-passify-a-result-using-forwarddiff/135283 "2026-01-28T10:30:33Z")

</div>

I’m working on the implementation of a time-stepping method and would like to force that part of the computation always be a passive value (in the AD sense). The function in question is a simple broadcasted computation,…

---

## [Issue with Binomial distribution and recent ForwardDiff versions](https://discourse.julialang.org/t/issue-with-binomial-distribution-and-recent-forwarddiff-versions/134347)

<div class="topic-metadata">

**Author:** [@Pablo\_Marchant](https://discourse.julialang.org/u/Pablo_Marchant)\
**Replies:** 2\
**Last updated:** [December 12, 2025, 3:57pm UTC](https://discourse.julialang.org/t/issue-with-binomial-distribution-and-recent-forwarddiff-versions/134347 "2025-12-12T15:57:48Z")

</div>

Hi, recently I noticed some code I’ve been using broke after updating Forward Diff. The issue came from sampling with Turing using a binomial likelihood. Digging into it it boiled down to this: using ForwardDiff using …

---

## [ForwardDiff with ModelingToolkit: Type conversion error in MTKParameters with DAE systems](https://discourse.julialang.org/t/forwarddiff-with-modelingtoolkit-type-conversion-error-in-mtkparameters-with-dae-systems/134145)

<div class="topic-metadata">

**Author:** [@Danijel-Zadravec](https://discourse.julialang.org/u/Danijel-Zadravec)\
**Replies:** 2\
**Last updated:** [December 1, 2025, 12:21pm UTC](https://discourse.julialang.org/t/forwarddiff-with-modelingtoolkit-type-conversion-error-in-mtkparameters-with-dae-systems/134145 "2025-12-01T12:21:26Z")

</div>

Hi everyone, I’m encountering a MethodError when trying to follow this example from the ModelingToolkit documentation. The problem seems to be related with dual number propagation in ODEProblems that have the property: …

---

## [Type Stabled Jacobian of a Hessian](https://discourse.julialang.org/t/type-stabled-jacobian-of-a-hessian/134148)

<div class="topic-metadata">

**Author:** [@JPCAM](https://discourse.julialang.org/u/JPCAM)\
**Replies:** 3\
**Last updated:** [November 28, 2025, 11:41am UTC](https://discourse.julialang.org/t/type-stabled-jacobian-of-a-hessian/134148 "2025-11-28T11:41:28Z")

</div>

I’ve run into a type-stability issue when trying to compute third-order derivatives with ForwardDiff. I have a potential function that takes a vector as input. Computing the Hessian with ForwardDiff.hessian works well a…

---

## [Optimization with AD of complex struct-based architecture](https://discourse.julialang.org/t/optimization-with-ad-of-complex-struct-based-architecture/133436)

<div class="topic-metadata">

**Author:** [@stevenhughes](https://discourse.julialang.org/u/stevenhughes)\
**Replies:** 3\
**Last updated:** [October 27, 2025, 7:44am UTC](https://discourse.julialang.org/t/optimization-with-ad-of-complex-struct-based-architecture/133436 "2025-10-27T07:44:15Z")

</div>

Hi everyone, I’m working on adding automatic differentiation to an optimization framework and running into some fundamental architectural issues. The framework uses a Directed Acyclic Graph modeled after Fig. 7 in this …

---

## [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(…

---

## [How to debug ODE model aborting midway on sensitivity computation](https://discourse.julialang.org/t/how-to-debug-ode-model-aborting-midway-on-sensitivity-computation/132096)

<div class="topic-metadata">

**Author:** [@Neodym](https://discourse.julialang.org/u/Neodym)\
**Replies:** 9\
**Last updated:** [September 15, 2025, 9:25pm UTC](https://discourse.julialang.org/t/how-to-debug-ode-model-aborting-midway-on-sensitivity-computation/132096 "2025-09-15T21:25:06Z")

</div>

Hi there, I have an ODE model that results from the spatial discretization of a PDE including reaction terms. The rate coefficient of the reaction is calculated from an interpolation that is provided externally. I can …

---

## [ForwardDiff.jl Jacobian with NonlinearSolve.jl](https://discourse.julialang.org/t/forwarddiff-jl-jacobian-with-nonlinearsolve-jl/132353)

<div class="topic-metadata">

**Author:** [@Jskacines](https://discourse.julialang.org/u/Jskacines)\
**Replies:** 1\
**Last updated:** [September 13, 2025, 5:39pm UTC](https://discourse.julialang.org/t/forwarddiff-jl-jacobian-with-nonlinearsolve-jl/132353 "2025-09-13T17:39:14Z")

</div>

Hello, I am new to Julia, so let me know if i’m missing any basics. I am using NonlinearSolve.jl to solve a nonlinear system, and I wish to take the jacobian of this solution with respect to input parameters. The code …

---

## [How to use Autodiff in Gridap.jl](https://discourse.julialang.org/t/how-to-use-autodiff-in-gridap-jl/131652)

<div class="topic-metadata">

**Author:** [@Sigmund](https://discourse.julialang.org/u/Sigmund)\
**Replies:** 4\
**Last updated:** [August 23, 2025, 5:45pm UTC](https://discourse.julialang.org/t/how-to-use-autodiff-in-gridap-jl/131652 "2025-08-23T17:45:57Z")

</div>

TLDR: I want to solve an optimal control problem using automatic differentiation (Gridap uses ForwardDiff.jl), but i get an error when i try to find the gradient of the objective function. The objective function depends …

---

## [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…

---

## [Custom ForwardDiff rule for ternary function](https://discourse.julialang.org/t/custom-forwarddiff-rule-for-ternary-function/131257)

<div class="topic-metadata">

**Author:** [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Replies:** 2\
**Last updated:** [August 2, 2025, 8:38am UTC](https://discourse.julialang.org/t/custom-forwarddiff-rule-for-ternary-function/131257 "2025-08-02T08:38:49Z")

</div>

I’m trying to define a custom ForwardDiff.jl differentiation rule for the bivariate normal cumulative function BvN(h, k, r). What I did so far works for first derivatives, but it doesn’t work for mixed higher derivatives…

---

## [How to forward differentiate a complex function?](https://discourse.julialang.org/t/how-to-forward-differentiate-a-complex-function/130127)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 19\
**Last updated:** [June 24, 2025, 10:13am UTC](https://discourse.julialang.org/t/how-to-forward-differentiate-a-complex-function/130127 "2025-06-24T10:13:02Z")

</div>

Hello, I have a very basic question, but I haven’t found any solution. I want to differentiate a holomorphic complex function. My function is f(z) = \[z^3 + exp(im\*z), exp(im\*z^2) + 1\] And I differentiate it using Dif…

---

## [ForwardDiff Allocations](https://discourse.julialang.org/t/forwarddiff-allocations/130006)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 3\
**Last updated:** [June 19, 2025, 2:26am UTC](https://discourse.julialang.org/t/forwarddiff-allocations/130006 "2025-06-19T02:26:15Z")

</div>

I ran into a strange issue where very small changes to a non-allocating function affect whether it’s ForwardDiff.gradient! is allocating or not. Here is an MWE. It’s a vastly simplified version of my original structure,…

---

## [ForwardDiff over closed interval](https://discourse.julialang.org/t/forwarddiff-over-closed-interval/129629)

<div class="topic-metadata">

**Author:** [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Replies:** 4\
**Last updated:** [June 6, 2025, 1:32pm UTC](https://discourse.julialang.org/t/forwarddiff-over-closed-interval/129629 "2025-06-06T13:32:43Z")

</div>

I need to optimize a function f(u) defined over a closed domain u =\[0,1\]. I was happily using Newton’s method and FowardDiff for this until I tried upgrading to v1.0. Now, ForwardDiff intentionally gives the derivative o…

---

## [Compiler specialisation in automatic differentiation](https://discourse.julialang.org/t/compiler-specialisation-in-automatic-differentiation/129020)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Replies:** 3\
**Last updated:** [May 19, 2025, 8:16am UTC](https://discourse.julialang.org/t/compiler-specialisation-in-automatic-differentiation/129020 "2025-05-19T08:16:46Z")

</div>

I am working with finite element method code. In this context, it is (very!!!) useful to use forward automatic differentiation to differentiate the function that, from degrees of freedom, compute the element’s contribut…

---

## [Optimizing the computation of jacobians for multiple shooting implementation](https://discourse.julialang.org/t/optimizing-the-computation-of-jacobians-for-multiple-shooting-implementation/128976)

<div class="topic-metadata">

**Author:** [@jackyarndley](https://discourse.julialang.org/u/jackyarndley)\
**Replies:** 10\
**Last updated:** [May 13, 2025, 9:38pm UTC](https://discourse.julialang.org/t/optimizing-the-computation-of-jacobians-for-multiple-shooting-implementation/128976 "2025-05-13T21:38:36Z")

</div>

Hi, I’ve been working with multiple shooting for trajectory optimization. I am currently using the sparse backend from DifferentiationInterface.jl and using DifferentialEquations.jl to perform the integration. A snippet …

---

## [Are forward-mode derivatives calculated in parallel?](https://discourse.julialang.org/t/are-forward-mode-derivatives-calculated-in-parallel/128870)

<div class="topic-metadata">

**Author:** [@Bizzi](https://discourse.julialang.org/u/Bizzi)\
**Replies:** 1\
**Last updated:** [May 9, 2025, 10:57am UTC](https://discourse.julialang.org/t/are-forward-mode-derivatives-calculated-in-parallel/128870 "2025-05-09T10:57:47Z")

</div>

When I calculate the output of a function and a directional derivative using forward-mode autodiff (ForwardDiff, TaylorDiff etc), is the calculation of the derivatives carried out in parallel? By parallel I mean: assumi…

---

## [Why does forward diff yield totally different gradients compared to my manual perturbation](https://discourse.julialang.org/t/why-does-forward-diff-yield-totally-different-gradients-compared-to-my-manual-perturbation/127918)

<div class="topic-metadata">

**Author:** [@Xu\_Shan](https://discourse.julialang.org/u/Xu_Shan)\
**Replies:** 1\
**Last updated:** [April 10, 2025, 12:52pm UTC](https://discourse.julialang.org/t/why-does-forward-diff-yield-totally-different-gradients-compared-to-my-manual-perturbation/127918 "2025-04-10T12:52:29Z")

</div>

Guys, I am trying to use ForwardDiff.jl to calculate the gradients (Jacobians) of the model cost function to parameters (at the values of a “pre-set” local\_optim). I found ForwardDiff.jl yields a totally different Jacobi…

---

## [Sensitivity of an SDE with non-diagonal noise](https://discourse.julialang.org/t/sensitivity-of-an-sde-with-non-diagonal-noise/127714)

<div class="topic-metadata">

**Author:** [@stochasticguy](https://discourse.julialang.org/u/stochasticguy)\
**Replies:** 2\
**Last updated:** [April 4, 2025, 9:17pm UTC](https://discourse.julialang.org/t/sensitivity-of-an-sde-with-non-diagonal-noise/127714 "2025-04-04T21:17:10Z")

</div>

Hi everyone, I’m simulating an SDE with non-diagonal noise and I’m trying to compute the gradient (using ForwardDiff) of a loss function that uses the SDE solution. When I try to compute the gradient the following error…

---

## [Understanding dependancy issues and CompatHelper](https://discourse.julialang.org/t/understanding-dependancy-issues-and-compathelper/127676)

<div class="topic-metadata">

**Author:** [@franckgaga](https://discourse.julialang.org/u/franckgaga)\
**Replies:** 5\
**Last updated:** [April 3, 2025, 6:10pm UTC](https://discourse.julialang.org/t/understanding-dependancy-issues-and-compathelper/127676 "2025-04-03T18:10:14Z")

</div>

First congratz on all contributors for the ForwardDiff.jl v1.0 release! I have a package that depends on ForwardDiff, both directly and indirectly. I received the automatic PR of CompatHelper. The tests failed in the PR…

---

## [Cholesky Decomposition combined with ForwardDiff.jl](https://discourse.julialang.org/t/cholesky-decomposition-combined-with-forwarddiff-jl/126892)

<div class="topic-metadata">

**Author:** [@CeterisPartybus](https://discourse.julialang.org/u/CeterisPartybus)\
**Replies:** 6\
**Last updated:** [March 16, 2025, 7:11pm UTC](https://discourse.julialang.org/t/cholesky-decomposition-combined-with-forwarddiff-jl/126892 "2025-03-16T19:11:57Z")

</div>

Short version: I would like to use automatic differentiation on my user defined function that includes a Cholesky decomposition. However, I get the following error: ERROR: Function iszero requires primal value(s). A dua…

---

## [Avoiding redundant computation when using Zygote and ForwardDiff for forward-over-reverse hessians](https://discourse.julialang.org/t/avoiding-redundant-computation-when-using-zygote-and-forwarddiff-for-forward-over-reverse-hessians/126827)

<div class="topic-metadata">

**Author:** [@IvanBioli](https://discourse.julialang.org/u/IvanBioli)\
**Replies:** 4\
**Last updated:** [March 12, 2025, 8:53am UTC](https://discourse.julialang.org/t/avoiding-redundant-computation-when-using-zygote-and-forwarddiff-for-forward-over-reverse-hessians/126827 "2025-03-12T08:53:29Z")

</div>

I am computing the Hessian of a function using a combination of Zygote (reverse-mode AD) and ForwardDiff (forward-mode AD). A MWE of my current implementation is as follows: using Zygote, ForwardDiff, DiffResults # Def…

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