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, CUDA.CuArray{Float64, 1, CUDA.Mem.DeviceBuffer}, ...}

  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    

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:

using MadNLPGPU

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 MadNLPGPU

set_optimizer(jm, () -> ExaModels.MadNLPOptimizer(CUDABackend()))
optimize!(jm)
This is MadNLP version v0.8.2, running with cuDSS v0.1.0

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.................:        8
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 lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  2.0570000e+03 2.48e+01 1.00e+02  -1.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  2.0474072e+03 2.47e+01 2.97e+01  -1.0 2.27e+00    -  1.00e+00 4.00e-03h  1
   2  1.1009058e+03 1.49e+01 2.24e+01  -1.0 2.24e+00    -  1.00e+00 1.00e+00h  1
   3  1.1598223e+02 2.15e+00 5.34e+01  -1.0 2.14e+00    -  1.00e+00 1.00e+00h  1
   4  6.5263510e+00 1.12e-01 4.74e+00  -1.0 1.72e-01    -  1.00e+00 1.00e+00h  1
   5  6.2326771e+00 1.64e-03 2.08e-02  -1.0 5.91e-02    -  1.00e+00 1.00e+00h  1
   6  6.2324576e+00 1.18e-06 1.22e-05  -3.8 1.40e-03    -  9.98e-01 1.00e+00h  1
   7  6.2323021e+00 5.36e-11 1.98e-06  -5.0 3.12e-05    -  8.90e-01 1.00e+00h  1

Number of Iterations....: 7

                                   (scaled)                 (unscaled)
Objective...............:   7.8690682927808753e-01    6.2323020878824540e+00
Dual infeasibility......:   1.9831098140299375e-06    1.5706229727117109e-05
Constraint violation....:   5.3644583980288433e-11    5.3644583980288433e-11
Complementarity.........:   1.1122043961251575e-05    8.8086588173112493e-05
Overall NLP error.......:   8.8086588173112493e-05    8.8086588173112493e-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
Total wall-clock secs in solver (w/o fun. eval./lin. alg.)  =  0.028
Total wall-clock secs in linear solver                      =  0.005
Total wall-clock secs in NLP function evaluations           =  0.005
Total wall-clock secs                                       =  0.039

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.