ExaModels.jl

ExaModels.jl is an algebraic modeling and automatic differentiation tool in Julia Language, specialized for SIMD abstraction of nonlinear programs.

The upstream documentation is available at https://exanauts.github.io/ExaModels.jl/stable/.

Supported layers

ExaModels supports the following predictors:

Basic example

Use MathOptAI.add_predictor to embed various predictors into an ExaCore:

julia> using ExaModels, MathOptAI, Fluxjulia> chain = Flux.Chain(           Flux.Dense(2 => 2, Flux.relu),           Flux.Scale(2),           Flux.Dense(2 => 2, Flux.sigmoid),           Flux.softmax,           Flux.Dense(2 => 2, Flux.softplus),           Flux.Dense(2 => 2, Flux.tanh),       );julia> core = ExaModels.ExaCore(; concrete = Val(true))An ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 0julia> core, x = ExaModels.add_var(core, 2)(An ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 0, Variable  x ∈ R^{2})julia> (core, y), _ = MathOptAI.add_predictor(core, chain, x);julia> yVariable  x ∈ R^{2}julia> coreAn ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 16

Gray-box

Use the gray_box = true keyword to embed the network as a vector nonlinear operator:

julia> using ExaModels, MathOptAI, Fluxjulia> chain = Flux.Chain(           Flux.Dense(2 => 2, Flux.relu),           Flux.Scale(2),       );julia> core = ExaModels.ExaCore(; concrete = Val(true))An ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 0julia> core, x = ExaModels.add_var(core, 2)(An ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 0, Variable  x ∈ R^{2})julia> (core, y), _ = MathOptAI.add_predictor(core, chain, x; gray_box = true);julia> yVariable  x ∈ R^{2}julia> coreAn ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 0

Change how layers are formulated

Pass a dictionary to the config keyword that maps Flux activation functions to a MathOptAI predictor:

julia> using ExaModels, Flux, MathOptAIjulia> predictor = Flux.Chain(Flux.Dense(1 => 2, Flux.relu), Flux.Dense(2 => 1));julia> core = ExaModels.ExaCore(; concrete = Val(true))An ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 0julia> core, x = ExaModels.add_var(core, 2)(An ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 0, Variable  x ∈ R^{2})julia> (core, y), _ = MathOptAI.add_predictor(           core,           predictor,           x;           config = Dict(Flux.relu => MathOptAI.ReLUEpigraph),       );julia> yVariable  x ∈ R^{1}julia> coreAn ExaCore  Float type: ...................... Float64  Array type: ...................... Vector{Float64}  Backend: ......................... Nothing  number of objective patterns: .... 0  number of constraint patterns: ... 5