55
66AutoModelingToolkit () = AutoModelingToolkit (false , false )
77
8- function instantiate_function (f, x, ad :: AutoModelingToolkit , p, num_cons= 0 )
8+ function instantiate_function (f, x, adtype :: AutoModelingToolkit , p, num_cons= 0 )
99 p = isnothing (p) ? SciMLBase. NullParameters () : p
1010 sys = ModelingToolkit. modelingtoolkitize (OptimizationProblem (f, x, p))
1111
@@ -17,7 +17,7 @@ function instantiate_function(f, x, ad::AutoModelingToolkit, p, num_cons=0)
1717 end
1818
1919 if f. hess === nothing
20- hess_oop, hess_iip = ModelingToolkit. generate_hessian (sys, expression= Val{false }, sparse = ad . obj_sparse)
20+ hess_oop, hess_iip = ModelingToolkit. generate_hessian (sys, expression= Val{false }, sparse = adtype . obj_sparse)
2121 hess (H, u) = (hess_iip (H, u, p); H)
2222 else
2323 hess = f. hess
@@ -41,7 +41,7 @@ function instantiate_function(f, x, ad::AutoModelingToolkit, p, num_cons=0)
4141 end
4242
4343 if f. cons != = nothing && f. cons_j === nothing
44- jac_oop, jac_iip = ModelingToolkit. generate_jacobian (cons_sys, expression= Val{false }, sparse= ad . cons_sparse)
44+ jac_oop, jac_iip = ModelingToolkit. generate_jacobian (cons_sys, expression= Val{false }, sparse= adtype . cons_sparse)
4545 cons_j = function (J, θ)
4646 jac_iip (J, θ, p)
4747 end
@@ -50,13 +50,15 @@ function instantiate_function(f, x, ad::AutoModelingToolkit, p, num_cons=0)
5050 end
5151
5252 if f. cons != = nothing && f. cons_h === nothing
53- cons_hess_oop, cons_hess_iip = ModelingToolkit. generate_hessian (cons_sys, expression= Val{false }, sparse= ad . cons_sparse)
53+ cons_hess_oop, cons_hess_iip = ModelingToolkit. generate_hessian (cons_sys, expression= Val{false }, sparse= adtype . cons_sparse)
5454 cons_h = function (res, θ)
5555 cons_hess_iip (res, θ, p)
5656 end
5757 else
5858 cons_h = f. cons_h
5959 end
6060
61- return OptimizationFunction {true,AutoModelingToolkit,typeof(f.f),typeof(grad),typeof(hess),typeof(hv),typeof(cons),typeof(cons_j),typeof(cons_h)} (f. f, AutoModelingToolkit (), grad, hess, hv, cons, cons_j, cons_h)
61+ return OptimizationFunction {true} (f. f, adtype; grad= grad, hess= hess, hv= hv,
62+ cons= cons, cons_j= cons_j, cons_h= cons_h,
63+ hess_prototype= nothing , cons_jac_prototype= nothing , cons_hess_prototype= nothing )
6264end
0 commit comments