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, Flux
julia> 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: ... 0
julia> 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: ... 17

Gray-box

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

julia> using ExaModels, MathOptAI, Flux
julia> 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: ... 0
julia> 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, MathOptAI
julia> 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: ... 0
julia> 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; config = Dict(Flux.relu => MathOptAI.ReLUEpigraph), );ERROR: UndefVarError: `chain` not defined in `Main` Suggestion: check for spelling errors or missing imports.
julia> yERROR: UndefVarError: `y` not defined in `Main` Suggestion: check for spelling errors or missing imports.
julia> coreAn ExaCore Float type: ...................... Float64 Array type: ...................... Vector{Float64} Backend: ......................... Nothing number of objective patterns: .... 0 number of constraint patterns: ... 0