JuMP Interface (Experimental)

JuMP to an ExaModel

We have an experimental interface to JuMP model. A JuMP model can be directly converted to a ExaModel. It is as simple as this:

using ExaModels, JuMP, CUDA

N = 10
jm = Model()

@variable(jm, x[i=1:N], start = mod(i, 2) == 1 ? -1.2 : 1.0)
@constraint(
    jm,
    s[i=1:(N-2)],
    3x[i+1]^3 + 2x[i+2] - 5 + sin(x[i+1] - x[i+2])sin(x[i+1] + x[i+2]) + 4x[i+1] -
    x[i]exp(x[i] - x[i+1]) - 3 == 0.0
)
@objective(jm, Min, sum(100(x[i-1]^2 - x[i])^2 + (x[i-1] - 1)^2 for i = 2:N))

em = ExaModel(jm; backend = CUDABackend())
An ExaModel{Float64, CUDACore.CuArray{Float64, 1, CUDACore.DeviceMemory}, ...}

  Problem name: Generic
   All variables: ████████████████████ 10     All constraints: ████████████████████ 8     
            free: ████████████████████ 10                free: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0     
           lower: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                lower: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0     
           upper: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                upper: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0     
         low/upp: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0              low/upp: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0     
           fixed: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0                fixed: ████████████████████ 8     
          infeas: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0               infeas: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0     
            nnzh: (-212.73% sparsity)   172             linear: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0     
                                                    nonlinear: ████████████████████ 8     
                                                         nnzj: (  0.00% sparsity)   80    
                                                     lin_nnzj: (------% sparsity)         
                                                     nln_nnzj: (  0.00% sparsity)   80    

Here, note that only scalar objective/constraints created via @constraint and @objective API are supported. Older syntax like @NLconstraint and @NLobjective are not supported. We can solve the model using any of the solvers supported by ExaModels. For example, we can use MadNLP. Note that CUDSS must be loaded alongside MadNLPGPU: it is the default linear solver for GPU sparse models and it triggers MadNLPGPU's CUDA extension, which provides the GPU KKT machinery.

using MadNLPGPU, CUDSS

result = madnlp(em)
"Execution stats: Optimal Solution Found (tol = 1.0e-04)."

JuMP Optimizer

Alternatively, one can use the Optimizer interface provided by ExaModels. This feature can be used as follows.

using ExaModels, JuMP, CUDA
using MadNLP, MadNLPGPU, CUDSS

set_optimizer(jm, () -> ExaModels.Optimizer(MadNLP.madnlp, CUDABackend()))
optimize!(jm)
This is MadNLP version v0.10.0, running with cuDSS v0.7.1

Number of nonzeros in constraint Jacobian............:       80
Number of nonzeros in Lagrangian Hessian.............:      172

Total number of variables............................:       10
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:        0
Total number of inequality constraints...............:        8
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        8
        inequality constraints with only upper bounds:        0

iter    objective    inf_pr   inf_du inf_compl lg(mu) lg(rg) alpha_pr ir ls
   0  2.0570000e+03 2.48e+01 1.00e+02 3.96e-04  -1.0     -   0.00e+00  0  0 
   1  2.0474072e+03 2.47e+01 2.97e+01 4.03e-02  -1.0     -   4.00e-03  1  1h
   2  1.1009058e+03 1.49e+01 2.24e+01 2.02e-02  -1.0     -   1.00e+00  1  1h
   3  1.1598223e+02 2.15e+00 5.34e+01 2.00e-02  -1.0     -   1.00e+00  1  1h
   4  6.5263509e+00 1.12e-01 4.74e+00 2.00e-02  -1.0     -   1.00e+00  1  1h
   5  6.2326771e+00 1.64e-03 2.08e-02 2.00e-02  -1.0     -   1.00e+00  1  1h
   6  6.2324576e+00 1.18e-06 1.22e-05 3.87e-04  -3.8     -   1.00e+00  1  1h
   7  6.2323021e+00 5.36e-11 1.98e-06 8.81e-05  -5.0     -   1.00e+00  1  1h

Number of Iterations....: 7

                                   (scaled)                 (unscaled)
Objective...............:   7.8690682927808819e-01    6.2323020878824593e+00
Dual infeasibility......:   1.9831098474476505e-06    1.5706229991785394e-05
Constraint violation....:   5.3644531098327470e-11    5.3644531098327470e-11
Complementarity.........:   1.1122043961248802e-05    8.8086588173090524e-05
Overall NLP error.......:   8.8086588173090524e-05    8.8086588173090524e-05

Number of objective function evaluations              = 8
Number of objective gradient evaluations              = 8
Number of constraint evaluations                      = 8
Number of constraint Jacobian evaluations             = 8
Number of Lagrangian Hessian evaluations              = 7
Number of KKT factorizations                          = 7
Number of KKT backsolves                              = 7

Total wall secs in initialization                     =  0.637 s
Total wall secs in linear solver                      =  unavailable
Total wall secs in NLP function evaluations           =  0.019 s
Total wall secs in solver (w/o init./fun./lin. alg.)  =  unavailable
Total wall secs                                       =  3.680 s

EXIT: Optimal Solution Found (tol = 1.0e-04).

Again, only scalar objective/constraints created via @constraint and @objective API are supported. Older syntax like @NLconstraint and @NLobjective are not supported.


This page was generated using Literate.jl.