Skip to content

Warning about SecondOrder ADtype was not provided #59

@Balinus

Description

@Balinus

When testing my package, I have lots of warning about SecondOrder ADtype was not provided.

Warning: The selected optimization algorithm requires second order derivatives, but SecondOrder ADtype was not provided.
│ So a SecondOrder with ADTypes.AutoForwardDiff() for both inner and outer will be created, this can be suboptimal and not work in some cases so
│ an explicit SecondOrder ADtype is recommended.

I asked an agent to trace back this warning and it proposed the following patch with an explicit SecondOrder formulation. Before doing any PR, does that make sense? (I am not an expert on such matter...!)

diff --git a/Project.toml b/Project.toml
--- a/Project.toml
+++ b/Project.toml
@@
 [deps]
 DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
+DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
 DiskArrays = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"
 Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
 FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
@@
 [compat]
 Dagger = "0.18, 0.19"
 DataStructures = "0.18,0.19.3"
+DifferentiationInterface = "0.7"
 DiskArrays = "0.4.10"
 Graphs = "1"
 Interpolations = "0.14, 0.15, 0.16"

diff --git a/src/executionplan.jl b/src/executionplan.jl
--- a/src/executionplan.jl
+++ b/src/executionplan.jl
@@
-using Ipopt, Optimization, OptimizationIpopt
+using Ipopt, Optimization, OptimizationIpopt
+using DifferentiationInterface: SecondOrder
 import OptimizationOptimJL
 using DiskArrays: DiskArrays, eachchunk, arraysize_from_chunksize
 using Statistics: mean
@@
 function optimize_loopranges(op::GMDWop,max_cache;tol_low=0.2,tol_high = 0.05,max_order=2,x0 = nothing, force_regular=false)
  lb = [0.0,map(_->1.0,op.windowsize)...]
  ub = [max_cache,op.windowsize...]
  x0 = x0 === nothing ? [1.5 for _ in op.windowsize] : x0
  totsize = op.windowsize
  input_chunkspecs = get_chunkspec.(op.inars,(totsize,))
  output_chunkspecs = get_chunkspec.(op.outspecs,op.f.outtype)
  chunkspecs = (input_chunkspecs..., output_chunkspecs...)
-  optprob = OptimizationFunction(compute_time, Optimization.AutoForwardDiff(), cons = all_constraints!)
+  optprob = OptimizationFunction(
+    compute_time,
+    SecondOrder(Optimization.AutoForwardDiff(), Optimization.AutoForwardDiff()),
+    cons = all_constraints!,
+  )
  prob = OptimizationProblem(optprob, x0, chunkspecs, lcons = lb, ucons = ub)
  sol = solve(prob, OptimizationOptimJL.IPNewton())
  @debug "Optimized Loop sizes: ", sol.u
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions