Problem using ModellingToolkit and Galacticoptim to solve a vector/matrix optimization problem

Hey folks, I was trying to resolve a problem using MTK and GalacticOptim to solve a simple optimization problem. The issue is that I am no really getting an error message that tells me where the problem is.

Here is the code:

using ModelingToolkit, GalacticOptim
using LinearAlgebra
@variables x[1:4]
@parameters Q, R
A = [1 1 1 1; 1 2 3 4; 1 3 6 10; 1 4 10 20]
B = [1 1 1 1; 1 2 3 4; 1 3 6 10; 1 4 10 20]
loss_quad = x'*Q*x + x'*R*x 
u1 = [1.,1.,1.,1.]
p = [
    Q => A,
    R => B
]
sys2 = OptimizationSystem(loss_quad,[x],[Q, R])
prob2 = OptimizationProblem(sys2, u1, p ,grad=true,hess=true)
solve(prob2,Newton())

But the error message I get is just.:

ERROR: syntax: invalid let syntax around /xxx/.julia/packages/SymbolicUtils/JmtMa/src/code.jl:283
Stacktrace:
 [1] top-level scope
   @ REPL[52]:100: 

I tried looking around for other examples. My guess is that it has to do with how u1 or p are specified, but not sure. If anyone has a suggestion it would be appreciated.

Array variables aren’t supported yet (though @shashi is very close to done!). So the error is something about the fact that Q => A where A is an array. If you hardcode the parameters it would work though.

Oh thanks @ChrisRackauckas .

I tried to hardcode it like this to get around the array.

p = [
    Q => [1. 1. 1. 1.; 1. 2. 3. 4.; 1. 3. 6. 10.; 1. 4. 10. 20.],
    R => [1. 1. 1. 1.; 1. 2. 3. 4.; 1. 3. 6. 10.; 1. 4. 10. 20.]
]

Still hitting the same error. I will keep playing with it though. I was working through some other MTK tutorials to just get a better feel for the syntax. I think it is probably just some small dumb thing. Thanks again.

That’s still an array, not like Q => 1.0. You could do @parameters Q[1:4,1:4] and then do Q[1] => ..., etc. right now. That’s the current limitation I mentioned.

Oh I got you. Yeah that makes sense. Sorry I did not understand the first time.

Is there any update on this questions? I am unable to get it to work with vector of variables/parameters.

Start a new thread with a concrete MWE to work from. Things should work.