### Install and Build MadNLPPardiso Source: https://madsuite.org/MadNLP.jl/stable/installation Install the MadNLPPardiso package and then build it. This process requires a C compiler. ```julia pkg> add MadNLPPardiso pkg> build MadNLPPardiso ``` -------------------------------- ### Re-run MadNLP with Different Initial Point Source: https://madsuite.org/MadNLP.jl/stable/quickstart This example demonstrates how to re-initialize the optimization problem with a new starting point (`x0`) and run MadNLP again. This is useful for exploring different local optima in non-convex problems. ```julia x0 = ones(2) nlp = HS15Model(x0) results = madnlp(nlp) nothing ``` ```text This is MadNLP version v0.9.1, running with MUMPS v5.8.2 Number of nonzeros in constraint Jacobian............: 4 Number of nonzeros in Lagrangian Hessian.............: 3 Total number of variables............................: 2 variables with only lower bounds: 0 variables with lower and upper bounds: 0 variables with only upper bounds: 1 Total number of equality constraints.................: 0 Total number of inequality constraints...............: 2 inequality constraints with only lower bounds: 2 inequality constraints with lower and upper bounds: 0 inequality constraints with only upper bounds: 0 iter objective inf_pr inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls 0 5.8004900e+01 5.20e-01 8.04e+01 1.49e+00 -1.0 - 0.00e+00 1 0 1 5.5900651e+01 5.15e-01 7.60e+01 1.43e+00 -1.0 - 9.17e-03 1 1h 2 5.3726392e+01 5.10e-01 8.07e+01 2.01e+00 -1.0 - 1.04e-02 1 1h ``` -------------------------------- ### Install MadNLPHSL Source: https://madsuite.org/MadNLP.jl/stable/installation Add the MadNLPHSL package after successfully installing HSL_jll. ```julia pkg> add MadNLPHSL ``` -------------------------------- ### Import MadNLPGPU and CUDA Source: https://madsuite.org/MadNLP.jl/stable/tutorials/gpu Import the necessary packages for using MadNLP on the GPU. This is the initial setup step. ```julia using MadNLPGPU using CUDA ``` -------------------------------- ### Run MadNLP with Initial Solution Source: https://madsuite.org/MadNLP.jl/stable/tutorials/warmstart Solve the optimization problem using the `madnlp` function, starting from the previously obtained initial solution `x0`. This performs a warm start. ```julia results = madnlp(nlp) nothing ``` -------------------------------- ### Install MadNLP Source: https://madsuite.org/MadNLP.jl/stable/installation Use this command to add the MadNLP package to your Julia environment. ```julia pkg> add MadNLP ``` -------------------------------- ### Solve KKT System with SparseKKTSystem Source: https://madsuite.org/MadNLP.jl/stable/tutorials/kktsystem This snippet demonstrates how to solve the KKT system using MadNLP's SparseKKTSystem and LapackCPUSolver. Ensure MadNLP is installed and the necessary models are defined. ```julia nlp = HS15Model() results = madnlp(nlp; kkt_system=MadNLP.SparseKKTSystem, linear_solver=LapackCPUSolver) nothing ``` -------------------------------- ### Develop HSL_jll.jl Package Source: https://madsuite.org/MadNLP.jl/stable/installation Install HSL_jll.jl by developing the package from a local path. Ensure you have obtained the necessary license. ```julia import Pkg Pkg.develop(path = "/full/path/to/HSL_jll.jl") ``` -------------------------------- ### Install MadNLPGPU for GPU Support Source: https://madsuite.org/MadNLP.jl/stable/installation Add the MadNLPGPU package to enable GPU acceleration. It automatically detects NVIDIA or AMD GPUs. ```julia pkg> add MadNLPGPU ``` -------------------------------- ### Access Initial Solution with get_x0 Source: https://madsuite.org/MadNLP.jl/stable/tutorials/warmstart Retrieve the initial primal variable stored in `nlp.meta.x0` using the `get_x0` function. This is useful for understanding the starting point of the optimization. ```julia x0 = NLPModels.get_x0(nlp) ``` -------------------------------- ### MadNLP Optimization Iteration Log (Early Stage) Source: https://madsuite.org/MadNLP.jl/stable/tutorials/quasi_newton This log shows the initial iterations of the MadNLP optimization process, highlighting rapid changes in objective and infeasibility values. It is useful for observing the algorithm's behavior at the start of a run. ```text iter objective inf_pr inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls 0 4.8810842e+01 2.22e-16 1.71e+01 0.00e+00 -1.0 - 0.00e+00 1 0 1 2.2956342e+00 1.50e+03 2.04e+02 0.00e+00 -1.0 - 1.25e-01 1 4f 2 4.4967927e+00 3.76e+02 5.48e+01 0.00e+00 -1.0 - 1.00e+00 1 1h ``` -------------------------------- ### Get KKT Matrix from AbstractKKTSystem Source: https://madsuite.org/MadNLP.jl/stable/man/linear_solvers Retrieve the assembled KKT matrix from an AbstractKKTSystem instance. Ensure the KKT system is properly assembled before calling this function. ```julia K = MadNLP.get_kkt(kkt) ``` -------------------------------- ### Get KKT System Components Source: https://madsuite.org/MadNLP.jl/stable/tutorials/kktsystem Provides basic functions to retrieve components of the KKT system, such as the number of variables, the KKT matrix in CSC format, and the Jacobian callback. ```julia MadNLP.num_variables(kkt::DiagonalHessianKKTSystem) = length(kkt.diag_hess) MadNLP.get_kkt(kkt::DiagonalHessianKKTSystem) = kkt.aug_com MadNLP.get_jacobian(kkt::DiagonalHessianKKTSystem) = kkt.jac_callback ``` -------------------------------- ### MadNLP Solver Output Source: https://madsuite.org/MadNLP.jl/stable/tutorials/gpu Example output from the MadNLP solver, detailing iteration progress, infeasibilities, and final solution status. This output is useful for diagnosing convergence issues. ```text This is MadNLP version v0.9.1, running with cuDSS v0.7.1 Number of nonzeros in constraint Jacobian............: 84 Number of nonzeros in Lagrangian Hessian.............: 5250 Total number of variables............................: 84 variables with only lower bounds: 0 variables with lower and upper bounds: 84 variables with only upper bounds: 0 Total number of equality constraints.................: 0 Total number of inequality constraints...............: 42 inequality constraints with only lower bounds: 0 inequality constraints with lower and upper bounds: 0 inequality constraints with only upper bounds: 42 iter objective inf_pr inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls 0 0.0000000e+00 1.04e+02 1.00e+00 1.00e+01 -1.0 - 0.00e+00 0 0 1 1.4808378e+01 1.00e+02 2.64e+01 6.04e+00 -1.0 - 3.37e-02 1 1h 2 1.3660555e+04 2.50e+01 1.79e+02 1.87e+00 -1.0 - 1.00e+00 1 1h 3 1.5757708e+04 2.11e+01 1.55e+02 8.19e-01 -1.0 - 1.66e-01 1 1h 4 2.2700976e+04 1.19e+01 1.31e+02 3.46e-01 -1.0 - 4.94e-01 1 1h 5 3.6245598e+04 2.96e+00 2.13e+02 2.84e-01 -1.0 - 1.00e+00 1 1h 6 4.0274013e+04 1.53e+00 1.64e+02 1.19e-01 -1.0 - 5.59e-01 1 1h 7 4.5453607e+04 3.61e-01 1.98e+02 1.16e-01 -1.0 - 1.00e+00 1 1h 8 4.7405169e+04 7.22e-02 1.00e+02 1.00e-01 -1.0 - 1.00e+00 1 1h 9 4.7892154e+04 8.03e-03 3.84e+01 9.05e-02 -1.0 - 1.00e+00 1 1h iter objective inf_pr inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls 10 4.7949829e+04 3.07e-04 6.16e+00 7.82e-02 -1.0 - 1.00e+00 1 1h 11 4.7951497e+04 1.23e-06 5.90e-02 7.81e-02 -1.0 - 1.00e+00 1 1h 12 4.7947424e+04 3.39e-06 1.21e-03 2.85e-03 -2.5 - 1.00e+00 1 1f 13 4.7947303e+04 4.19e-09 1.24e-06 7.80e-06 -5.0 - 1.00e+00 1 1h Number of Iterations....: 13 (scaled) (unscaled) Objective...............: 4.7947302735661782e+04 4.7947302735661782e+04 Dual infeasibility......: 1.2358625376867822e-06 1.2358625376867822e-06 Constraint violation....: 4.1921440895476697e-09 4.1921440895476697e-09 Complementarity.........: 7.8004282261790513e-06 7.8004282261790513e-06 Overall NLP error.......: 7.8004282261790513e-06 7.8004282261790513e-06 Number of objective function evaluations = 14 Number of objective gradient evaluations = 14 Number of constraint evaluations = 14 Number of constraint Jacobian evaluations = 14 Number of Lagrangian Hessian evaluations = 13 Number of KKT factorizations = 13 Number of KKT backsolves = 13 Total wall secs in initialization = 1.257 s Total wall secs in linear solver = unavailable Total wall secs in NLP function evaluations = 0.004 s Total wall secs in solver (w/o init./fun./lin. alg.) = unavailable Total wall secs = 8.150 s EXIT: Optimal Solution Found (tol = 1.0e-04). ``` -------------------------------- ### KKT System Creation and Initialization Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Functions for creating and initializing KKT systems. ```APIDOC ## Create KKT System `MadNLP.create_kkt_system` — Function ``` create_kkt_system( ::Type{KKT}, cb::AbstractCallback, ind_cons::NamedTuple, linear_solver::Type{LinSol}; opt_linear_solver=default_options(linear_solver), hessian_approximation=ExactHessian, ) where {KKT<:AbstractKKTSystem, LinSol<:AbstractLinearSolver} ``` Instantiate a new KKT system with type `KKT`, associated to the the nonlinear program encoded inside the callback `cb`. The `NamedTuple` `ind_cons` stores the indexes of all the variables and constraints in the callback `cb`. In addition, the user should pass the linear solver `linear_solver` that will be used to solve the KKT system after it has been assembled. ## Initialize KKT System `MadNLP.initialize!` — Function ``` initialize!(kkt::AbstractKKTSystem) ``` Initialize KKT system with default values. Called when we initialize the `MadNLPSolver` storing the current KKT system `kkt`. ``` -------------------------------- ### Initialize KKT System Source: https://madsuite.org/MadNLP.jl/stable/man/kkt Initializes the KKT system after it has been built. This step is necessary before using the KKT system within an interior-point algorithm. ```julia MadNLP.initialize!(kkt); ``` ```julia 3-element Vector{Float64}: 0.0 0.0 0.0 ``` -------------------------------- ### Create KKT System Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Instantiate a new KKT system with a specified type, callback, constraint indices, and linear solver. Optional arguments for linear solver options and Hessian approximation can be provided. ```julia create_kkt_system( ::Type{KKT}, cb::AbstractCallback, ind_cons::NamedTuple, linear_solver::Type{LinSol}; opt_linear_solver=default_options(linear_solver), hessian_approximation=ExactHessian, ) where {KKT<:AbstractKKTSystem, LinSol<:AbstractLinearSolver} ``` -------------------------------- ### Configure and Run MadNLP Source: https://madsuite.org/MadNLP.jl/stable/tutorials/kktsystem Instantiates an optimization model and solves it using MadNLP with the DiagonalHessianKKTSystem and LapackCPUSolver. Ensure the necessary model and solver are imported. ```julia nlp = HS15Model() results = madnlp(nlp; kkt_system=DiagonalHessianKKTSystem, linear_solver=LapackCPUSolver) nothing ``` -------------------------------- ### Get Dual Values Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Returns the dual values (y, z) stored in the KKT vector. ```julia dual(X::AbstractKKTVector) ``` -------------------------------- ### Get Primal Values Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Returns the primal values (x, s) stored in the KKT vector. ```julia primal(X::AbstractKKTVector) ``` -------------------------------- ### Get Nonzero Count of Jacobian Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Returns the number of non-zero elements in the Jacobian matrix. ```julia nnz_jacobian ``` -------------------------------- ### Load Quadmath Library Source: https://madsuite.org/MadNLP.jl/stable/tutorials/multiprecision Import the Quadmath library to enable working with quadruple-precision floating-point numbers. ```julia using Quadmath ``` -------------------------------- ### Get Full KKT Vector Values Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Returns all values stored within the KKT vector. ```julia full(X::AbstractKKTVector) ``` -------------------------------- ### Create Sparse KKT System Source: https://madsuite.org/MadNLP.jl/stable/man/kkt Instantiates a sparse KKT system using the `create_kkt_system` function. Requires the KKT system type, a callback function `cb`, and the chosen linear solver. ```julia kkt = MadNLP.create_kkt_system( MadNLP.SparseKKTSystem, cb, linear_solver, ) ``` ```julia MadNLP.SparseKKTSystem{Float64, Vector{Float64}, SparseArrays.SparseMatrixCSC{Float64, Int32}, MadNLP.ExactHessian{Float64, Vector{Float64}}, LapackCPUSolver{Float64, SparseArrays.SparseMatrixCSC{Float64, Int32}}, Vector{Int64}, Vector{Int32}}([0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], MadNLP.ExactHessian{Float64, Vector{Float64}}(), [2.0e-323, 6.34436211249205e-310, 6.3443652045335e-310, 6.3443652045999e-310], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0], [6.34437148191976e-310, 6.34437148191976e-310], [6.3442752171701e-310], [6.34427528331247e-310, 6.34430136495017e-310], [6.34427522052977e-310], [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0], sparse(Int32[1, 2, 5, 6, 2, 5, 6, 3, 5, 4, 6, 5, 6], Int32[1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0], 6, 6), [1, 5, 8, 10, 1, 2, 5, 3, 6, 4, 7, 9, 11, 12, 13], [0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0], sparse(Int32[1, 2, 1, 2, 1, 2], Int32[1, 1, 2, 2, 3, 4], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], 2, 4), [1, 3, 2, 4, 5, 6], LapackCPUSolver{Float64, SparseArrays.SparseMatrixCSC{Float64, Int32}}(sparse(Int32[1, 2, 5, 6, 2, 5, 6, 3, 5, 4, 6, 5, 6], Int32[1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 6], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0], 6, 6), [6.3443751916674e-310 6.34430040933314e-310 … 6.3443651934443e-310 NaN; 6.3443713372534e-310 6.34437195755003e-310 … 2.5e-323 6.34437325290557e-310; … ; 6.3443004186113e-310 6.34436900948325e-310 … 6.3443651934443e-310 6.34436900948325e-310; 5.0e-324 6.3443732524518e-310 … 2.5e-323 6.3443721236952e-310], 6, Float64[], Float64[], Float64[], [384.0, 0.0, 3.466909703e-315, 6.3443794058355e-310, 0.0, 1.51e-321, 5.0e-324, 0.0, 0.0, 3.466909703e-315 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 8.0e-323, 3.88e-321], 384, [128411514206256], -1, Base.RefValue{Int64}(0), [1, 1, 0, 0, 128411514810656, 128411589880704], MadNLP.LapackOptions(MadNLP.BUNCHKAUFMAN), MadNLP.MadNLPLogger(MadNLP.INFO, MadNLP.INFO, nothing)), [1, 2], [3, 4], [1]) ``` -------------------------------- ### Initialize LapackCPUSolver with KKT Matrix Source: https://madsuite.org/MadNLP.jl/stable/man/linear_solvers Create a LapackCPUSolver instance using the assembled KKT matrix. This solver does not copy the matrix, maintaining a reference for direct updates. ```julia linear_solver = LapackCPUSolver(K) ``` -------------------------------- ### Get Upper-Bound Dual Values Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Returns the dual values (ω) associated with the upper-bound stored in the KKT vector. ```julia dual_ub(X::AbstractKKTVector) ``` -------------------------------- ### Instantiate Model on CPU Source: https://madsuite.org/MadNLP.jl/stable/tutorials/gpu Instantiate your optimization model on the CPU using the specified data type and parameters. This is a prerequisite for wrapping it with SparseWrapperModel. ```julia nlp_cpu = airport_model(Float64, nothing) ``` -------------------------------- ### Import ExaModels for GPU Optimization Source: https://madsuite.org/MadNLP.jl/stable/tutorials/gpu Import the ExaModels package, which is recommended for implementing optimization models that run entirely on the GPU. ```julia using ExaModels ``` -------------------------------- ### Get Lower-Bound Dual Values Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Returns the dual values (ν) associated with the lower-bound stored in the KKT vector. ```julia dual_lb(X::AbstractKKTVector) ``` -------------------------------- ### Get Primal and Dual Values Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Returns both the primal (x, s) and dual (y, z) values stored in the KKT vector. ```julia primal_dual(X::AbstractKKTVector) ``` -------------------------------- ### Display Model Summary Source: https://madsuite.org/MadNLP.jl/stable/tutorials/gpu This output provides a summary of the instantiated ExaModel, detailing the number of variables, constraints, and their types (free, lower/upper bounded, etc.), along with sparsity information for the Hessian and Jacobian. ```julia An ExaModel{Float64, CUDA.CuArray{Float64, 1, CUDA.DeviceMemory}, ...} Problem name: Generic All variables: ████████████████████ 84 All constraints: ████████████████████ 42 free: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 free: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 lower: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 lower: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 upper: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 upper: ████████████████████ 42 low/upp: ████████████████████ 84 low/upp: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 fixed: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 fixed: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 infeas: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 infeas: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 nnzh: (-47.06% sparsity) 5250 linear: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 nonlinear: ████████████████████ 42 nnzj: ( 97.62% sparsity) 84 lin_nnzj: (------% sparsity) nln_nnzj: ( 97.62% sparsity) 84 ``` -------------------------------- ### Get Number of Dual Values Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Retrieves the total count of dual values (y, z) within a given KKT vector. ```julia number_dual(X::AbstractKKTVector) ``` -------------------------------- ### Get Number of Primal Values Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Retrieves the total count of primal values (x, s) within a given KKT vector. ```julia number_primal(X::AbstractKKTVector) ``` -------------------------------- ### Initialize KKT System Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Initialize the KKT system with default values. This function is called during the initialization of the `MadNLPSolver` that stores the KKT system. ```julia initialize!(kkt::AbstractKKTSystem) ``` -------------------------------- ### Create SparseCallback for KKT System Source: https://madsuite.org/MadNLP.jl/stable/man/kkt Instantiate a SparseCallback to wrap an NLPModel for KKT system assembly. This is typically done before each iteration of an interior-point algorithm. ```julia cb = MadNLP.create_callback( MadNLP.SparseCallback, nlp, ) ``` -------------------------------- ### Get KKT Matrix Pointer Source: https://madsuite.org/MadNLP.jl/stable/lib/kkt Return a pointer to the KKT matrix implemented in `kkt`. This pointer is intended for use with a linear solver. ```julia get_kkt(kkt::AbstractKKTSystem)::AbstractMatrix ``` -------------------------------- ### Initial Solve with MadNLP Source: https://madsuite.org/MadNLP.jl/stable/tutorials/warmstart Perform the first solve of the optimization problem using the instantiated solver. ```julia results = MadNLP.solve!(solver) ``` -------------------------------- ### Initialize Linear Solver Source: https://madsuite.org/MadNLP.jl/stable/tutorials/kktsystem Initializes the linear solver with the sparse matrix in CSC format. This prepares the system for solving linear equations. ```julia _linear_solver = linear_solver(aug_com; opt = opt_linear_solver) ``` -------------------------------- ### Instantiate and Solve with MadNLP Source: https://madsuite.org/MadNLP.jl/stable/quickstart Creates an instance of the custom HS15Model, initializes a MadNLP solver, and solves the optimization problem. ```julia x0 = zeros(2) # initial position nlp = HS15Model(x0) solver = MadNLP.MadNLPSolver(nlp; print_level=MadNLP.INFO) results = MadNLP.solve!(solver) nothing ``` -------------------------------- ### Solve JuMP Model on GPU with MadNLP Source: https://madsuite.org/MadNLP.jl/stable/tutorials/gpu This example demonstrates how to solve a JuMP model on the GPU by specifying `CuArray` as the `array_type` and `CUDSSSolver` as the `linear_solver` when optimizing. ```julia using CUDA using JuMP using MadNLP, MadNLPGPU model = Model(MadNLP.Optimizer) @variable(model, x1 <= 0.5) @variable(model, x2) @objective(model, Min, 100.0 * (x2 - x1^2)^2 + (1.0 - x1)^2) @constraint(model, x1 * x2 >= 1.0) @constraint(model, x1 + x2^2 >= 0.0) JuMP.set_optimizer_attribute(model, "array_type", CuArray) JuMP.set_optimizer_attribute(model, "linear_solver", CUDSSSolver) JuMP.optimize!(model) # Solve the model on the GPU! ``` -------------------------------- ### Set Initial Guess from Solution Source: https://madsuite.org/MadNLP.jl/stable/tutorials/warmstart Copy the previously found solution to the initial guess vector of the NLP model. This ensures the algorithm starts from a known point. ```julia copyto!(NLPModels.get_x0(nlp), results.solution) ``` -------------------------------- ### Get KKT Matrix Source: https://madsuite.org/MadNLP.jl/stable/man/kkt Retrieves a reference to the internal KKT matrix stored within the `kkt` object. This matrix is automatically updated whenever `kkt` is assembled. ```julia kkt_matrix = MadNLP.get_kkt(kkt) ``` ```julia 6×6 SparseArrays.SparseMatrixCSC{Float64, Int32} with 13 stored entries: 1.0 ⋅ ⋅ ⋅ ⋅ ⋅ 2.0 5.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 8.0 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 10.0 ⋅ ⋅ 3.0 6.0 9.0 ⋅ 12.0 ⋅ 4.0 7.0 ⋅ 11.0 ⋅ 13.0 ``` -------------------------------- ### Precompiling MadNLPGPU Source: https://madsuite.org/MadNLP.jl/stable/tutorials/gpu This output indicates the precompilation process for the MadNLPGPU package, showing the time taken and successful completion. ```julia Precompiling packages... 14040.0 ms ✓ MadNLPGPU 1 dependency successfully precompiled in 16 seconds. 123 already precompiled. ``` -------------------------------- ### Tune LBFGS max_history in MadNLP Source: https://madsuite.org/MadNLP.jl/stable/tutorials/quasi_newton Increase the LBFGS `max_history` to 20 to use more past iterates for the low-rank approximation. This example also specifies the `LapackCPUSolver` and `MadNLP.CompactLBFGS` for the optimization. ```julia qn_options = MadNLP.QuasiNewtonOptions(; max_history=20) results_qn = madnlp( nlp; linear_solver=LapackCPUSolver, hessian_approximation=MadNLP.CompactLBFGS, quasi_newton_options=qn_options, ) nothing ``` ```text This is MadNLP version v0.9.1, running with Lapack-CPU (BUNCHKAUFMAN) Number of nonzeros in constraint Jacobian............: 30 Number of nonzeros in Lagrangian Hessian.............: 975 Total number of variables............................: 30 variables with only lower bounds: 0 variables with lower and upper bounds: 0 variables with only upper bounds: 0 Total number of equality constraints.................: 10 Total number of inequality constraints...............: 0 inequality constraints with only lower bounds: 0 inequality constraints with lower and upper bounds: 0 inequality constraints with only upper bounds: 0 iter objective inf_pr inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls 0 4.8810842e+01 2.22e-16 1.71e+01 0.00e+00 -1.0 - 0.00e+00 1 0 1 2.2956342e+00 1.50e+03 2.04e+02 0.00e+00 -1.0 - 1.25e-01 1 4f 2 4.4967927e+00 3.76e+02 5.48e+01 0.00e+00 -1.0 - 1.00e+00 1 1h 3 8.7093834e+00 9.38e+01 1.37e+01 0.00e+00 -1.0 - 1.00e+00 1 1h 4 1.4770500e+01 2.32e+01 3.20e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 5 1.8176499e+01 9.94e+00 1.50e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 6 2.5109575e+01 2.32e+00 1.92e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 7 2.8512602e+01 2.52e+00 2.52e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 8 1.2759872e+01 3.54e+01 1.13e+01 0.00e+00 -1.0 - 1.00e+00 1 1h 9 1.5624022e+01 1.58e+01 2.83e+00 0.00e+00 -1.0 - 1.00e+00 1 1h iter objective inf_pr inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls 10 2.1982310e+01 5.68e+00 1.86e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 11 2.2542843e+01 4.22e+00 1.14e+00 0.00e+00 -1.0 - 5.00e-01 1 2h 12 2.7255011e+01 1.47e+00 2.96e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 13 2.9232894e+01 1.25e+00 2.66e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 14 2.9261067e+01 9.81e-01 3.03e+00 0.00e+00 -1.0 - 5.00e-01 1 2h 15 2.7142323e+01 2.39e+00 3.27e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 16 2.7776481e+01 1.35e+00 1.98e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 17 3.0166747e+01 7.86e-01 1.80e+00 0.00e+00 -1.0 - 1.00e+00 1 1h 18 3.0609464e+01 3.09e-01 8.42e-01 0.00e+00 -1.0 - 1.00e+00 1 1h 19 3.2450081e+01 6.00e-02 5.04e-01 0.00e+00 -1.7 - 1.00e+00 1 1h iter objective inf_pr inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls 20 3.2636130e+01 3.88e-02 3.94e-01 0.00e+00 -1.7 - 1.00e+00 1 1h 21 3.2706987e+01 9.35e-03 1.66e-01 0.00e+00 -1.7 - 1.00e+00 1 1h 22 3.2699721e+01 6.51e-03 9.41e-02 0.00e+00 -2.5 - 1.00e+00 1 1h 23 3.2682575e+01 5.11e-03 1.14e-01 0.00e+00 -2.5 - 1.00e+00 1 1h 24 3.2701207e+01 4.15e-03 1.48e-01 0.00e+00 -2.5 - 1.00e+00 1 1h 25 3.2712954e+01 1.75e-03 4.88e-02 0.00e+00 -2.5 - 1.00e+00 1 1h 26 3.2719381e+01 2.29e-04 2.32e-02 0.00e+00 -2.5 - 1.00e+00 1 1h 27 3.2720051e+01 3.26e-05 6.65e-03 0.00e+00 -3.8 - 1.00e+00 1 1h 28 3.2720061e+01 2.64e-05 7.96e-03 0.00e+00 -3.8 - 1.00e+00 1 1h 29 3.2715805e+01 6.76e-04 2.85e-02 0.00e+00 -3.8 - 1.00e+00 1 1h iter objective inf_pr inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls 30 3.2702239e+01 2.73e-03 5.82e-02 0.00e+00 -3.8 - 1.00e+00 1 1h 31 3.2697960e+01 2.28e-03 7.47e-02 0.00e+00 -3.8 - 1.00e+00 1 1h 32 3.2707411e+01 2.46e-03 1.24e-01 0.00e+00 -3.8 - 1.00e+00 1 1h 33 3.2709995e+01 9.33e-04 1.60e-02 0.00e+00 -3.8 - 1.00e+00 1 1h 34 3.2712746e+01 6.45e-04 2.11e-02 0.00e+00 -3.8 - 1.00e+00 1 1h 35 3.2704283e+01 3.24e-03 5.49e-02 0.00e+00 -3.8 - 1.00e+00 1 1h 36 3.2709923e+01 1.48e-03 2.22e-02 0.00e+00 -3.8 - 1.00e+00 1 1h 37 3.2715749e+01 4.96e-04 5.36e-02 0.00e+00 -3.8 - 1.00e+00 1 1h 38 3.2714941e+01 4.33e-04 2.54e-03 0.00e+00 -3.8 - 1.00e+00 1 1h ``` -------------------------------- ### Configure MadNLP with HybridKKT for GPU Source: https://madsuite.org/MadNLP.jl/stable/tutorials/gpu Use HybridKKT.jl for accurate solutions by employing the Golub & Greif augmented Lagrangian formulation. This strategy is more accurate but slightly slower than Lifted-KKT. ```julia using HybridKKT results = madnlp( nlp; linear_solver=MadNLPGPU.CUDSSSolver, kkt_system=HybridKKT.HybridCondensedKKTSystem, equality_treatment=MadNLP.EnforceEquality, fixed_variable_treatment=MadNLP.MakeParameter, ) ``` -------------------------------- ### Instantiate MadNLP Solver Source: https://madsuite.org/MadNLP.jl/stable/lib/ipm Instantiate a new `MadNLPSolver` associated with the nonlinear program `nlp::AbstractNLPModel`. Options are passed as optional arguments. The constructor allocates memory for the interior-point algorithm. ```julia MadNLPSolver(nlp::AbstractNLPModel{T, VT}; options...) where {T, VT} ```