Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix primal evaluation #45

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ end
function sumheat(heat::Heat, chkpscheme::Scheme, tsteps::Int64)
# AD: Create shadow copy for derivatives
@checkpoint_struct chkpscheme heat for i in 1:tsteps
# checkpoint_struct_for(advance, heat)
heat.Tlast .= heat.Tnext
advance(heat)
end
Expand All @@ -87,7 +86,7 @@ function heat(scheme::Scheme, tsteps::Int)
heat.Tnext[end] = 0

# Compute gradient
autodiff(Enzyme.ReverseWithPrimal, sumheat, Duplicated(heat, dheat), scheme, tsteps)
autodiff(Enzyme.ReverseWithPrimal, sumheat, Duplicated(heat, dheat), Const(scheme), Const(tsteps))

return heat.Tnext, dheat.Tnext[2:end-1]
end
Expand Down
4 changes: 2 additions & 2 deletions examples/optcontrol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Technique for Resilience. United States: N. p., 2016. https://www.osti.gov/biblio/1364654.

using Checkpointing
using Zygote
using Enzyme


include("optcontrolfunc.jl")
Expand Down Expand Up @@ -69,7 +69,7 @@ function muoptcontrol(scheme, steps, ::EnzymeTool)
end
return model.F[2]
end
autodiff(Enzyme.ReverseWithPrimal, foo, Duplicated(model, bmodel))
autodiff(Enzyme.Reverse, foo, Duplicated(model, bmodel))

F = model.F
L = bmodel.F
Expand Down
5 changes: 3 additions & 2 deletions src/Rules/EnzymeRules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function augmented_primal(
model,
range,
)
primal = func.val(body.val, alg.val, deepcopy(model.val), range.val)
if needs_primal(config)
primal = func.val(body.val, alg.val, model.val, range.val)
return AugmentedReturn(primal, nothing, (model.val,))
else
return AugmentedReturn(nothing, nothing, (model.val,))
Expand Down Expand Up @@ -50,9 +50,10 @@ function augmented_primal(
model,
condition,
)
primal = func.val(body.val, alg.val, deepcopy(model.val), condition.val)
if needs_primal(config)
return AugmentedReturn(
func.val(body.val, alg.val, model.val, condition.val),
primal,
nothing,
(model.val,),
)
Expand Down
Loading