@@ -590,9 +590,13 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
590590 return obj_nonlinprog! (Ŷ0, U0, mpc, Ue, Ŷe, ΔŨ)
591591 end
592592 if ! isnothing (hess)
593- _, ∇J_opt, ∇²J_opt = value_gradient_and_hessian (J!, hess, mpc. Z̃, J_cache... )
593+ prep_∇²J = prepare_hessian (J!, hess, mpc. Z̃, J_cache... )
594+ _, ∇J_opt, ∇²J_opt = value_gradient_and_hessian (J!, prep_∇²J, hess, mpc. Z̃, J_cache... )
595+ ∇²J_ncolors = get_ncolors (prep_∇²J)
594596 else
595- ∇J_opt, ∇²J_opt = gradient (J!, mpc. gradient, mpc. Z̃, J_cache... ), nothing
597+ prep_∇J = prepare_gradient (J!, mpc. gradient, mpc. Z̃, J_cache... )
598+ ∇J_opt = gradient (J!, prep_∇J, mpc. gradient, mpc. Z̃, J_cache... )
599+ ∇²J_opt, ∇²J_ncolors = nothing , nothing
596600 end
597601 # --- inequality constraint derivatives ---
598602 ∇g_cache = (
@@ -605,7 +609,9 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
605609 gi .= @views g[i_g]
606610 return nothing
607611 end
608- g_opt, ∇g_opt = value_and_jacobian (gi!, gi, mpc. jacobian, mpc. Z̃, ∇g_cache... )
612+ prep_∇g = prepare_jacobian (gi!, gi, mpc. jacobian, mpc. Z̃, ∇g_cache... )
613+ g_opt, ∇g_opt = value_and_jacobian (gi!, gi, prep_∇g, mpc. jacobian, mpc. Z̃, ∇g_cache... )
614+ ∇g_ncolors = get_ncolors (prep_∇g)
609615 if ! isnothing (hess) && ngi > 0
610616 nonlincon = optim[:nonlinconstraint ]
611617 λi = try
@@ -631,9 +637,11 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
631637 gi .= @views g[i_g]
632638 return dot (λi, gi)
633639 end
634- ∇²ℓg_opt = hessian (ℓ_gi, hess, mpc. Z̃, Constant (λi), ∇²g_cache... )
640+ prep_∇²ℓg = prepare_hessian (ℓ_gi, hess, mpc. Z̃, Constant (λi), ∇²g_cache... )
641+ ∇²ℓg_opt = hessian (ℓ_gi, prep_∇²ℓg, hess, mpc. Z̃, Constant (λi), ∇²g_cache... )
642+ ∇²ℓg_ncolors = get_ncolors (prep_∇²ℓg)
635643 else
636- ∇²ℓg_opt = nothing
644+ ∇²ℓg_opt, ∇²ℓg_ncolors = nothing , nothing
637645 end
638646 # --- equality constraint derivatives ---
639647 geq_cache = (
@@ -645,7 +653,9 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
645653 update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g, geq, mpc, Z̃)
646654 return nothing
647655 end
648- geq_opt, ∇geq_opt = value_and_jacobian (geq!, geq, mpc. jacobian, mpc. Z̃, geq_cache... )
656+ prep_∇geq = prepare_jacobian (geq!, geq, mpc. jacobian, mpc. Z̃, geq_cache... )
657+ geq_opt, ∇geq_opt = value_and_jacobian (geq!, geq, prep_∇geq, mpc. jacobian, mpc. Z̃, geq_cache... )
658+ ∇geq_ncolors = get_ncolors (prep_∇geq)
649659 if ! isnothing (hess) && con. neq > 0
650660 nonlinconeq = optim[:nonlinconstrainteq ]
651661 λeq = try
@@ -670,25 +680,37 @@ function addinfo!(info, mpc::NonLinMPC{NT}) where NT<:Real
670680 update_predictions! (ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, K, X̂0, gc, g, geq, mpc, Z̃)
671681 return dot (λeq, geq)
672682 end
673- ∇²ℓgeq_opt = hessian (ℓ_geq, hess, mpc. Z̃, Constant (λeq), ∇²geq_cache... )
683+ prep_∇²ℓgeq = prepare_hessian (ℓ_geq, hess, mpc. Z̃, Constant (λeq), ∇²geq_cache... )
684+ ∇²ℓgeq_opt = hessian (ℓ_geq, prep_∇²ℓgeq, hess, mpc. Z̃, Constant (λeq), ∇²geq_cache... )
685+ ∇²ℓgeq_ncolors = get_ncolors (prep_∇²ℓgeq)
674686 else
675- ∇²ℓgeq_opt = nothing
687+ ∇²ℓgeq_opt, ∇²ℓgeq_ncolors = nothing , nothing
676688 end
677689 info[:∇J ] = ∇J_opt
678690 info[:∇²J ] = ∇²J_opt
691+ info[:∇²J_ncolors ] = ∇²J_ncolors
679692 info[:g ] = g_opt
680693 info[:∇g ] = ∇g_opt
694+ info[:∇g_ncolors ] = ∇g_ncolors
681695 info[:∇²ℓg ] = ∇²ℓg_opt
696+ info[:∇²ℓg_ncolors ] = ∇²ℓg_ncolors
682697 info[:geq ] = geq_opt
683698 info[:∇geq ] = ∇geq_opt
699+ info[:∇geq_ncolors ] = ∇geq_ncolors
684700 info[:∇²ℓgeq ] = ∇²ℓgeq_opt
701+ info[:∇²ℓgeq_ncolors ] = ∇²ℓgeq_ncolors
685702 # --- non-Unicode fields ---
686703 info[:nablaJ ] = ∇J_opt
687704 info[:nabla2J ] = ∇²J_opt
705+ info[:nabla2J_ncolors ] = ∇²J_ncolors
688706 info[:nablag ] = ∇g_opt
707+ info[:nablag_ncolors ] = ∇g_ncolors
689708 info[:nabla2lg ] = ∇²ℓg_opt
709+ info[:nabla2lg_ncolors ] = ∇²ℓg_ncolors
690710 info[:nablageq ] = ∇geq_opt
711+ info[:nablageq_ncolors ] = ∇geq_ncolors
691712 info[:nabla2lgeq ] = ∇²ℓgeq_opt
713+ info[:nabla2lgeq_ncolors ] = ∇²ℓgeq_ncolors
692714 return info
693715end
694716
0 commit comments