Multiplication of matrix expression and variables leads to stack overflow and matmul error

I have an optimal orbital transfer problem:

h = 2
n = 6
m = 3

model = Model(NLopt.Optimizer)
set_optimizer_attribute(model, "algorithm", :AUGLAG)
local_optimizer = NLopt.Opt(:LD_LBFGS, n*(h+1) + m*h)
local_optimizer.xtol_rel = 1e-4
set_optimizer_attribute(model, "local_optimizer", local_optimizer)

@variables model begin
X[1:6, 1:h+1]
U[1:3, 1:h]
27000.0 <= T[1:h]
end

Trying to multiply an expression matrix

B
6×3 Matrix{Any}:
  ((2 X[1,1]²) / (X[1,1] * sqrt(3.986004415e14 / X[1,1]))) * (X[2,1] * sin(X[6,1]))                 …  0
  (1.0 / (X[1,1] * sqrt(3.986004415e14 / X[1,1]))) * ((X[1,1] * (-X[2,1]² + 1)) * sin(X[6,1]))         0
 0                                                                                                      (((X[1,1] * (-X[2,1]² + 1)) / (1.0 + (X[2,1] * cos(X[6,1])))) * cos(X[6,1] + X[4,1])) / (X[1,1] * sqrt(3.986004415e14 / X[1,1]))
  (-(X[1,1] * (-X[2,1]² + 1)) * cos(X[6,1])) / (X[2,1] * (X[1,1] * sqrt(3.986004415e14 / X[1,1])))      -((((X[1,1] * (-X[2,1]² + 1)) / (1.0 + (X[2,1] * cos(X[6,1])))) * sin(X[6,1] + X[4,1])) * cos(X[3,1])) / ((X[1,1] * sqrt(3.986004415e14 / X[1,1])) * sin(X[3,1]))
 0                                                                                                      (((X[1,1] * (-X[2,1]² + 1)) / (1.0 + (X[2,1] * cos(X[6,1])))) * sin(X[6,1] + X[4,1])) / ((X[1,1] * sqrt(3.986004415e14 / X[1,1])) * sin(X[3,1]))
  ((X[1,1] * (-X[2,1]² + 1)) * cos(X[6,1])) / (X[2,1] * (X[1,1] * sqrt(3.986004415e14 / X[1,1])))   …  0

with

U[:, i] = JuMP.VariableRef[U[1,1], U[2,1], U[3,1]]

by executing:

B1 = B(X[:,1])
B1*U[:,1]

Results in the following stack overflow error:

operate(::typeof(*), ::Matrix{Any}, ::Vector{JuMP.VariableRef})@LinearAlgebra.jl:403
mul(::Matrix{Any}, ::Vector{JuMP.VariableRef})@shortcuts.jl:58
*(::Matrix{Any}, ::Vector{JuMP.VariableRef})@dispatch.jl:360
 [ Repeated 100 times ]
operate(::typeof(*), ::Matrix{Any}, ::Vector{JuMP.VariableRef})@LinearAlgebra.jl:403
mul(::Matrix{Any}, ::Vector{JuMP.VariableRef})@shortcuts.jl:58
*(::Matrix{Any}, ::Vector{JuMP.VariableRef})@dispatch.jl:360

Whereas doing:

B1*U[:,:]

Gives the correct result, a 6x2 matrix.

Help in understanding and resolving the problem is appreciated!

1 Like

Please link when cross-posting: Multiplication of matrix expression and variables leads to stack overflow and matmul error · Issue #3714 · jump-dev/JuMP.jl · GitHub

2 Likes

The issue was resolved by upgrading the packages to the latest release.