diff --git a/src/core/control.jl b/src/core/control.jl index 10d2fa5..4a6df06 100644 --- a/src/core/control.jl +++ b/src/core/control.jl @@ -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 diff --git a/test/testoptimization.jl b/test/testoptimization.jl index 25b35f9..55c9c6f 100755 --- a/test/testoptimization.jl +++ b/test/testoptimization.jl @@ -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())