Skip to content

Add support for model parameters in ExaModels #147

@frapac

Description

@frapac

I am investigating the solution of optimization problems with parameters in ExaModels. Currently, the following syntax is breaking:

N = 10
params = rand(N)

core = ExaModels.ExaCore(Float64)
x = ExaModels.variable(core, N)
expr = ExaModels.constraint(core, x[i] + params[i] for i in 1:N; lcon=0.0, ucon=Inf)

The current solution is to pass the parameters directly in the iterator, like

N = 10
params = rand(N)

core = ExaModels.ExaCore(Float64)
x = ExaModels.variable(core, N)
expr = ExaModels.constraint(core, x[i]+p for (i, p) in zip(1:N, params); lcon=0.0, ucon=Inf)

However, that means that if we change the parameters, they are not easy to update in the model, as that means modifying the iterator inplace.

I am wondering if we should add a new object in the expression tree to make parameters first-class citizen in ExaModels. A potential syntax would be

N = 10
params = rand(N)

core = ExaModels.ExaCore(Float64)
x = ExaModels.variable(core, N)
p = ExaModels.parameters(params)
expr = ExaModels.constraint(core, x[i] + p[i] for i in 1:N; lcon=0.0, ucon=Inf)

An idea would be to implement a new node as:

struct Parameter{I} <: AbstractNode
     i::I
end

and implements the same functions as for Var.

The values of the parameters would be stored in a vector inside ExaCore. If we do that, it would be very easy to update the parameters.

cc @klamike

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions