Skip to content

Commit 386dde0

Browse files
SebastianM-Cclaude
andcommitted
Generate cons_h! when lag_h needs it
`lag_h!` requires `cons_h!` for σ=0 case. Now generates `cons_h!` whenever `lag_h==true` to prevent `MethodError`. Co-authored-by: Claude <[email protected]>
1 parent 8d4ac3a commit 386dde0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/OptimizationBase/src/OptimizationDIExt.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ function instantiate_function(
177177

178178
conshess_sparsity = f.cons_hess_prototype
179179
conshess_colors = f.cons_hess_colorvec
180-
if f.cons !== nothing && f.cons_h === nothing && cons_h == true
180+
# Generate cons_h! if explicitly requested OR if lag_h needs it
181+
if f.cons !== nothing && f.cons_h === nothing && (cons_h == true || lag_h == true)
181182
prep_cons_hess = [prepare_hessian(cons_oop, soadtype, x, Constant(i))
182183
for i in 1:num_cons]
183184

@@ -186,7 +187,7 @@ function instantiate_function(
186187
hessian!(cons_oop, H[i], prep_cons_hess[i], soadtype, θ, Constant(i))
187188
end
188189
end
189-
elseif cons_h == true && f.cons !== nothing
190+
elseif (cons_h == true || lag_h == true) && f.cons !== nothing
190191
cons_h! = (res, θ) -> f.cons_h(res, θ, p)
191192
else
192193
cons_h! = nothing

0 commit comments

Comments
 (0)