Skip to content

Commit 0da5429

Browse files
authored
fix: correct interpretation for compile with AutoReverseDiff (#613)
* fix: correct interpretation for `compile` with `AutoReverseDiff` * Fix static arrays * Wrong arg order
1 parent 40ef1a7 commit 0da5429

6 files changed

Lines changed: 281 additions & 108 deletions

File tree

DifferentiationInterface/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DifferentiationInterface"
22
uuid = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
33
authors = ["Guillaume Dalle", "Adrian Hill"]
4-
version = "0.6.20"
4+
version = "0.6.21"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

DifferentiationInterface/docs/src/explanation/backends.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,18 @@ Most operators fall back on `AutoForwardDiff`.
144144

145145
### ReverseDiff
146146

147-
Wherever possible, preparation records a [tape](https://juliadiff.org/ReverseDiff.jl/dev/api/#The-AbstractTape-API) of the function's execution.
148-
This tape is computed from the arguments `x` and `contexts...` provided at preparation time.
147+
With `AutoReverseDiff(compile=false)`, preparation preallocates a [config](https://juliadiff.org/ReverseDiff.jl/dev/api/#The-AbstractConfig-API).
148+
149+
With `AutoReverseDiff(compile=true)`, preparation records a [tape](https://juliadiff.org/ReverseDiff.jl/dev/api/#The-AbstractTape-API) of the function's execution.
150+
This tape is computed from the input `x` provided at preparation time.
149151
It is control-flow dependent, so only one branch is recorded at each `if` statement.
150152

151153
!!! danger
152154
If your function has value-specific control flow (like `if x[1] > 0` or `if c == 1`), you may get silently wrong results whenever it takes new branches that were not taken during preparation.
153155
You must make sure to run preparation with an input and contexts whose values trigger the correct control flow for future executions.
154156

157+
Whenever contexts are provided, tape recording is deactivated in all cases, because otherwise the context values would be hardcoded into a tape.
158+
155159
### Symbolics
156160

157161
For all operators, preparation generates an [executable function](https://docs.sciml.ai/Symbolics/stable/manual/build_function/) from the symbolic expression of the differentiated function.

DifferentiationInterface/ext/DifferentiationInterfaceReverseDiffExt/DifferentiationInterfaceReverseDiffExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using ReverseDiff.DiffResults:
2020
DiffResults, DiffResult, GradientResult, HessianResult, MutableDiffResult
2121
using LinearAlgebra: dot, mul!
2222
using ReverseDiff:
23+
ReverseDiff,
2324
CompiledGradient,
2425
CompiledHessian,
2526
CompiledJacobian,
@@ -29,7 +30,6 @@ using ReverseDiff:
2930
HessianTape,
3031
JacobianConfig,
3132
JacobianTape,
32-
compile,
3333
gradient,
3434
gradient!,
3535
hessian,

0 commit comments

Comments
 (0)