Comments (4)
Why don't we get a BoundsError()
when using the vectors provided by ipopt?
from ipopt.jl.
Some of the backtrace was showing signs of LLVM, so it might have to do with codegen/LLVM compiling the function on the first call and having it hit an error while exception-handled by Ipopt instead of Julia? If I run the problematic code once with the solveProblem
line commented out, then run it again with it uncommented, I get a backtrace from Ipopt that makes sense going through Ipopt::OrigIpoptNLP::InitializeStructures
etc.
from ipopt.jl.
Hmm, the mix of julia and c++ exceptions seems pretty broken currently.
from ipopt.jl.
Closing because this seems to work okay.
function eval_f(x::Vector{Float64})
# !!! The x[5] is out-of-bounds !!!
return x[1] * x[4] * (x[1] + x[2] + x[3]) + x[5]
end
function eval_g(x::Vector{Float64}, g::Vector{Float64})
g[1] = x[1] * x[2] * x[3] * x[4]
g[2] = x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2
end
function eval_grad_f(x::Vector{Float64}, grad_f::Vector{Float64})
grad_f[1] = x[1] * x[4] + x[4] * (x[1] + x[2] + x[3])
grad_f[2] = x[1] * x[4]
grad_f[3] = x[1] * x[4] + 1
grad_f[4] = x[1] * (x[1] + x[2] + x[3])
end
function eval_jac_g(x::Vector{Float64}, mode, rows::Vector{Int32}, cols::Vector{Int32}, values::Vector{Float64})
if mode == :Structure
# Constraint (row) 1
rows[1] = 1; cols[1] = 1
rows[2] = 1; cols[2] = 2
rows[3] = 1; cols[3] = 3
rows[4] = 1; cols[4] = 4
# Constraint (row) 2
rows[5] = 2; cols[5] = 1
rows[6] = 2; cols[6] = 2
rows[7] = 2; cols[7] = 3
rows[8] = 2; cols[8] = 4
else
# Constraint (row) 1
values[1] = x[2]*x[3]*x[4] # 1,1
values[2] = x[1]*x[3]*x[4] # 1,2
values[3] = x[1]*x[2]*x[4] # 1,3
values[4] = x[1]*x[2]*x[3] # 1,4
# Constraint (row) 2
values[5] = 2*x[1] # 2,1
values[6] = 2*x[2] # 2,2
values[7] = 2*x[3] # 2,3
values[8] = 2*x[4] # 2,4
end
end
function eval_h(x::Vector{Float64}, mode, rows::Vector{Int32}, cols::Vector{Int32}, obj_factor::Float64, lambda::Vector{Float64}, values::Vector{Float64})
if mode == :Structure
# Symmetric matrix, fill the lower left triangle only
idx = 1
for row = 1:4
for col = 1:row
rows[idx] = row
cols[idx] = col
idx += 1
end
end
else
# Again, only lower left triangle
# Objective
values[1] = obj_factor * (2*x[4]) # 1,1
values[2] = obj_factor * ( x[4]) # 2,1
values[3] = 0 # 2,2
values[4] = obj_factor * ( x[4]) # 3,1
values[5] = 0 # 3,2
values[6] = 0 # 3,3
values[7] = obj_factor * (2*x[1] + x[2] + x[3]) # 4,1
values[8] = obj_factor * ( x[1]) # 4,2
values[9] = obj_factor * ( x[1]) # 4,3
values[10] = 0 # 4,4
# First constraint
values[2] += lambda[1] * (x[3] * x[4]) # 2,1
values[4] += lambda[1] * (x[2] * x[4]) # 3,1
values[5] += lambda[1] * (x[1] * x[4]) # 3,2
values[7] += lambda[1] * (x[2] * x[3]) # 4,1
values[8] += lambda[1] * (x[1] * x[3]) # 4,2
values[9] += lambda[1] * (x[1] * x[2]) # 4,3
# Second constraint
values[1] += lambda[2] * 2 # 1,1
values[3] += lambda[2] * 2 # 2,2
values[6] += lambda[2] * 2 # 3,3
values[10] += lambda[2] * 2 # 4,4
end
end
prob = createProblem(
4,
[1.0, 1.0, 1.0, 1.0],
[5.0, 5.0, 5.0, 5.0],
2,
[25.0, 40.0],
[Inf, 40.0],
8,
10,
eval_f,
eval_g,
eval_grad_f,
eval_jac_g,
eval_h,
)
prob.x = [1.0, 5.0, 5.0, 1.0]
solvestat = solveProblem(prob)
julia> solvestat = solveProblem(prob)
This is Ipopt version 3.13.2, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).
Number of nonzeros in equality constraint Jacobian...: 4
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 10
Total number of variables............................: 4
variables with only lower bounds: 0
variables with lower and upper bounds: 4
variables with only upper bounds: 0
Total number of equality constraints.................: 1
Total number of inequality constraints...............: 1
inequality constraints with only lower bounds: 1
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 0
ERROR: BoundsError: attempt to access 4-element Array{Float64,1} at index [5]
Stacktrace:
[1] getindex at ./array.jl:809 [inlined]
[2] eval_f(::Array{Float64,1}) at ./REPL[38]:2
[3] eval_f_wrapper(::Int32, ::Ptr{Float64}, ::Int32, ::Ptr{Float64}, ::Ptr{Nothing}) at /Users/oscar/.julia/dev/Ipopt/src/Ipopt.jl:143
[4] solveProblem(::IpoptProblem) at /Users/oscar/.julia/dev/Ipopt/src/Ipopt.jl:361
[5] top-level scope at REPL[45]:1
from ipopt.jl.
Related Issues (20)
- add `MathOptInterface.Name()` attribute HOT 1
- `max_wall_time` is still not working HOT 5
- Allow user to specify the Ipopt binary HOT 2
- copy_to does not copy attributes for variable bound constraints HOT 6
- Only evaluate QP callbacks if needed HOT 1
- Problem with HSL solvers since updating to MacOS 13.0 HOT 3
- double free or corruption (out) error HOT 20
- Linking full hsl library to Ipopt.jl on ubuntu HOT 19
- julia 0.6.0 install Ipopt cannot connect to mumps dependency HOT 2
- Add support for GetIpoptCurrentViolations
- Incorrect number of Hessian structure (nonzero entries) HOT 10
- Does Ipopt.jl support giving hessian matrix in JuMP directly, without using the C_wrapper? HOT 2
- pointer being freed was not allocated HOT 33
- Invalid number in NLP function or derivative detected. HOT 8
- Issue with non-negative variable tolerance. HOT 2
- does not allow Ipopt_jll current version HOT 2
- Add some pre-built "debugging" callbacks HOT 1
- Crash on Windows when optimizing with SPRAL_jll HOT 11
- Using Ipopt in parallel threads HOT 4
- "double free or corruption" when providing duplicate hessian entries via MathOptInterface HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ipopt.jl.