Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit e440023

Browse files
Add Const activity for trailing data arguments
Enzyme v0.12 now requires that all inputs are marked with an activity, and so these need to manually be marked const.
1 parent 7cfed2b commit e440023

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

ext/OptimizationEnzymeExt.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true}, x,
2828
Const(f.f),
2929
Enzyme.Duplicated(θ, res),
3030
Const(p),
31-
args...)
31+
Const.(args)...)
3232
end
3333
end
3434
else
@@ -43,7 +43,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true}, x,
4343
Const(f),
4444
Enzyme.Duplicated(θ, bθ),
4545
Const(p),
46-
args...),
46+
Const.(args)...),
4747
return nothing
4848
end
4949
function hess(res, θ, args...)
@@ -77,13 +77,13 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true}, x,
7777
f,
7878
Enzyme.Duplicated(x, dx),
7979
Const(p),
80-
args...)
80+
Const.(args)...)
8181
return dx
8282
end
8383
hv = function (H, θ, v, args...)
8484
H .= Enzyme.autodiff(Enzyme.Forward, f2, DuplicatedNoNeed, Duplicated(θ, v),
8585
Const(_f), Const(f.f), Const(p),
86-
args...)[1]
86+
Const.(args)...)[1]
8787
end
8888
else
8989
hv = f.hv
@@ -168,7 +168,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true},
168168
Const(f.f),
169169
Enzyme.Duplicated(θ, res),
170170
Const(p),
171-
args...)
171+
Const.(args)...)
172172
end
173173
else
174174
grad = (G, θ, args...) -> f.grad(G, θ, p, args...)
@@ -179,7 +179,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true},
179179
Enzyme.autodiff_deferred(Enzyme.Reverse, Const(firstapply), Active, Const(f),
180180
Enzyme.Duplicated(θ, bθ),
181181
Const(p),
182-
args...)
182+
Const.(args)...)
183183
return nothing
184184
end
185185
function hess(res, θ, args...)
@@ -194,7 +194,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true},
194194
Enzyme.BatchDuplicated(bθ, vdbθ),
195195
Const(f.f),
196196
Const(p),
197-
args...)
197+
Const.(args)...)
198198

199199
for i in eachindex(θ)
200200
res[i, :] .= vdbθ[i]
@@ -211,13 +211,13 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{true},
211211
f,
212212
Enzyme.Duplicated(x, dx),
213213
Const(p),
214-
args...)
214+
Const.(args)...)
215215
return dx
216216
end
217217
hv = function (H, θ, v, args...)
218218
H .= Enzyme.autodiff(Enzyme.Forward, f2, DuplicatedNoNeed, Duplicated(θ, v),
219219
Const(f.f), Const(p),
220-
args...)[1]
220+
Const.(args)...)[1]
221221
end
222222
else
223223
hv = f.hv
@@ -285,7 +285,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false}, x
285285
Const(f.f),
286286
Enzyme.Duplicated(θ, res),
287287
Const(p),
288-
args...)
288+
Const.(args)...)
289289
return res
290290
end
291291
end
@@ -301,7 +301,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false}, x
301301
Const(f),
302302
Enzyme.Duplicated(θ, bθ),
303303
Const(p),
304-
args...),
304+
Const.(args)...),
305305
return nothing
306306
end
307307
function hess(θ, args...)
@@ -316,7 +316,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false}, x
316316
Enzyme.BatchDuplicated(bθ, vdbθ),
317317
Const(f.f),
318318
Const(p),
319-
args...)
319+
Const.(args)...)
320320

321321
reduce(vcat, [reshape(vdbθ[i], (1, length(vdbθ[i]))) for i in eachindex(θ)])
322322
end
@@ -334,13 +334,13 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false}, x
334334
f,
335335
Enzyme.Duplicated(x, dx),
336336
Const(p),
337-
args...)
337+
Const.(args)...)
338338
return dx
339339
end
340340
hv = function (θ, v, args...)
341341
Enzyme.autodiff(Enzyme.Forward, f2, DuplicatedNoNeed, Duplicated(θ, v),
342342
Const(_f), Const(f.f), Const(p),
343-
args...)[1]
343+
Const.(args)...)[1]
344344
end
345345
else
346346
hv = f.hv
@@ -425,7 +425,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false},
425425
Const(f.f),
426426
Enzyme.Duplicated(θ, res),
427427
Const(p),
428-
args...)
428+
Const.(args)...)
429429
return res
430430
end
431431
end
@@ -441,7 +441,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false},
441441
Const(f),
442442
Enzyme.Duplicated(θ, bθ),
443443
Const(p),
444-
args...),
444+
Const.(args)...),
445445
return nothing
446446
end
447447
function hess(θ, args...)
@@ -456,7 +456,7 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false},
456456
Enzyme.BatchDuplicated(bθ, vdbθ),
457457
Const(f.f),
458458
Const(p),
459-
args...)
459+
Const.(args)...)
460460

461461
reduce(vcat, [reshape(vdbθ[i], (1, length(vdbθ[i]))) for i in eachindex(θ)])
462462
end
@@ -474,13 +474,13 @@ function OptimizationBase.instantiate_function(f::OptimizationFunction{false},
474474
f,
475475
Enzyme.Duplicated(x, dx),
476476
Const(p),
477-
args...)
477+
Const.(args)...)
478478
return dx
479479
end
480480
hv = function (θ, v, args...)
481481
Enzyme.autodiff(Enzyme.Forward, f2, DuplicatedNoNeed, Duplicated(θ, v),
482482
Const(_f), Const(f.f), Const(p),
483-
args...)[1]
483+
Const.(args)...)[1]
484484
end
485485
else
486486
hv = f.hv

0 commit comments

Comments
 (0)