Skip to content

Commit

Permalink
fix bug upgrading to Enzyme 0.13, add run time activity in autodiff
Browse files Browse the repository at this point in the history
  • Loading branch information
enigne committed Nov 6, 2024
1 parent ed5ea8c commit d016b8e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/control.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ComputeGradient(∂J_∂α::Vector{Float64}, α::Vector{Float64}, femmo
# zero ALL depth of the model, make sure we get correct gradient
dfemmodel = Enzyme.Compiler.make_zero(Base.Core.Typeof(femmodel), IdDict(), femmodel)
# compute the gradient
autodiff(Enzyme.Reverse, costfunction, Active, Duplicated(α, ∂J_∂α), Duplicated(femmodel,dfemmodel))
autodiff(set_runtime_activity(Enzyme.Reverse), costfunction, Active, Duplicated(α, ∂J_∂α), Duplicated(femmodel,dfemmodel))
end#}}}
function CostFunctionx(femmodel::FemModel, α::Vector{Float64}, controlvar_enum::IssmEnum, SId_enum::IssmEnum, cost_enum_list::Vector{IssmEnum}, ::Val{solutionstring}) where solutionstring #{{{
#Update FemModel accordingly
Expand Down
9 changes: 5 additions & 4 deletions test/testoptimization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ md.inversion.dependent_string = ["SurfaceAbsVelMisfit"]
femmodel=DJUICE.ModelProcessor(md, :StressbalanceSolution)
n = length(α)

DJUICE.costfunction(α, femmodel)
# test Enzyme autodiff only
dfemmodel = Enzyme.Compiler.make_zero(Base.Core.Typeof(femmodel), IdDict(), femmodel)
autodiff(Enzyme.Reverse, DJUICE.costfunction, Active, Duplicated(α, ∂J_∂α), Duplicated(femmodel,dfemmodel))
autodiff(set_runtime_activity(Enzyme.Reverse), DJUICE.costfunction, Active, Duplicated(α, ∂J_∂α), Duplicated(femmodel,dfemmodel))

# use user defined grad, errors!
optprob = OptimizationFunction(DJUICE.costfunction, Optimization.AutoEnzyme())
#optprob = OptimizationFunction(DJUICE.costfunction, Optimization.AutoEnzyme())
#prob = Optimization.OptimizationProblem(optprob, α, femmodel, lb=md.inversion.min_parameters, ub=md.inversion.max_parameters)
prob = Optimization.OptimizationProblem(optprob, α, femmodel)
sol = Optimization.solve(prob, Optimization.LBFGS())
#prob = Optimization.OptimizationProblem(optprob, α, femmodel)
#sol = Optimization.solve(prob, Optimization.LBFGS())
#sol = Optimization.solve(prob, Optim.GradientDescent())
#sol = Optimization.solve(prob, Optim.NelderMead())

0 comments on commit d016b8e

Please sign in to comment.