-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
Document that nonlinear expressions cannot be built outside of a macro #2060
Comments
There are multiple things going on
julia> @NLobjective(m, Min, f(x))
ERROR: Unexpected array VariableRef[x[1,1] x[1,2]; x[2,1] x[2,2]] in nonlinear expression. Nonlinear expressions may contain only scalar expressions.
It's unfortunate that we don't throw a better error message, but we can't expect to catch every error thrown by arbitrary functions in Julia that are operated on The syntax you're looking for is something like julia> f(x...) = LinearAlgebra.norm(reshape(collect(x), 2, 2))
f (generic function with 1 method)
julia> m = Model(with_optimizer(Ipopt.Optimizer))
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: SolverName() attribute not implemented by the optimizer.
julia> @variable(m, x[1:2, 1:2] >= 0)
2×2 Array{VariableRef,2}:
x[1,1] x[1,2]
x[2,1] x[2,2]
julia> register(m, :f, 4, f, autodiff=true)
julia> @NLobjective(m, Min, f(x...)) |
This has come up a few times: https://stackoverflow.com/questions/62622919/jump-constraints-involving-matrix-inverse Task for the sprint:
|
I am sorry if this is something very trivial, but I am trying to run the following code: using JuMP, Ipopt, LinearAlgebra
FP = Model(solver=IpoptSolver())
@variable(FP, x[1:2,1:2] >= 0)
@objective(FP, Max, 0)
@NLconstraint(FP, inv(x) <= 0.5*I)
status = solve(FP) But it raises the following error:
I understand that this is related to not being able to define nonlinear expressions with vector inputs. I have tried the workaround mentioned above by defining a f(x...) first, but it still doesn't work for me and throws the following error:
My code for the second case is as follows: using JuMP, Ipopt, LinearAlgebra
f(x...) = LinearAlgebra.inv(reshape(collect(x), 2, 2))
FP = Model(solver=IpoptSolver())
@variable(FP, x[1:2,1:2] >= 0)
@objective(FP, Max, 0)
JuMP.register(FP, :f, 4, f, autodiff=true)
@NLconstraint(FP, f(x...) <= 0.5*I)
status = solve(FP) Could you please help me figure out the problem here? |
This seems to be working after upgrading to the latest version of JuMP. |
Hello,
I'm trying to optimize an Array of parameters to minimize the norm between a function of these parameters and some measured data - here is an example of what I am trying to do:
I get a stack overflow error which seems to be triggered by taking the
norm
of anArray{VariableRef}
or anArray{GenericAffExpr}
.Minimum reproducible example:
The text was updated successfully, but these errors were encountered: