Skip to content

Running optimizations with maps as input #875

@TorkelE

Description

@TorkelE

In MTK and various SciML packages commonly to have e.g. parameter sets on the form of maps, e.g.:

using ModelongToolkit
@parameters p1 p2
x0 = [p1 => 0.0, p2 => 0.0]

Many of these packages also use SciML/Optimization to e.g. find optimal parameter sets. It would be useful if SciML/Optimization could accept these objects in their runs, e.g.

using ModelongToolkit, Optimization, OptimizationOptimJL
@parameters p1 p2
rosenbrock(x, p) = (1.0 - x[2][1])^2 + 100.0 * (x[2][2] - x[2][1]^2)^2
x0 = [p1 => 0.0, p2 => 0.0]
prob = OptimizationProblem(rosenbrock, x0, [])
sol = solve(prob, NelderMead())

Currently, one have to extract the various values manually, but this seems burdensome and also prone to potentially causing errors.

I have tried to create an OptimiationSystem, but

using Optimization, OptimizationOptimJL
@parameters p1 p2
rosenbrock(x, p) = (1.0 - x[2][1])^2 + 100.0 * (x[2][2] - x[2][1]^2)^2
@named sys = OptimizationSystem(rosenbrock, [p1, p2], [])
sys = complete(sys)
x0 = [p1 => 0.0, p2 => 0.0]
prob = OptimizationProblem(sys, x0, [])

gives a

ERROR: MethodError: no method matching collect_constants!(::Vector{SymbolicUtils.BasicSymbolic}, ::typeof(rosenbrock))
The function `collect_constants!` exists, but no method is defined for this combination of argument types.

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