Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running optimizations with maps as input #875

Open
TorkelE opened this issue Jan 22, 2025 · 0 comments
Open

Running optimizations with maps as input #875

TorkelE opened this issue Jan 22, 2025 · 0 comments

Comments

@TorkelE
Copy link
Member

TorkelE commented Jan 22, 2025

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant