Skip to content

Commit

Permalink
Merge d6ab682 into 870f037
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst committed Aug 10, 2018
2 parents 870f037 + d6ab682 commit 794763e
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 88 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ os:
- linux
- osx
julia:
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
sudo: false
addons:
apt_packages:
- gfortran
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("Ipopt")'
- julia -e 'Pkg.test("Ipopt", coverage=true)'
# uncomment the following lines to override the default test script
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("Ipopt"); Pkg.test("Ipopt"; coverage=true)'
after_success:
- echo $TRAVIS_JULIA_VERSION
- julia -e 'Pkg.add("Coverage"); cd(Pkg.dir("Ipopt")); using Coverage; Coveralls.submit(process_folder())'
- julia -e 'using Pkg, Ipopt; Pkg.add("Coverage"); cd(joinpath(dirname(pathof(Ipopt)), "..")); using Coverage; Coveralls.submit(process_folder())'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Ipopt.jl
[![Build Status](https://travis-ci.org/JuliaOpt/Ipopt.jl.svg?branch=master)](https://travis-ci.org/JuliaOpt/Ipopt.jl)
[![Coverage Status](https://img.shields.io/coveralls/JuliaOpt/Ipopt.jl.svg)](https://coveralls.io/r/JuliaOpt/Ipopt.jl)

[![Ipopt](http://pkg.julialang.org/badges/Ipopt_0.6.svg)](http://pkg.julialang.org/?pkg=Ipopt&ver=0.6)
[![Ipopt](http://pkg.julialang.org/badges/Ipopt_0.7.svg)](http://pkg.julialang.org/?pkg=Ipopt&ver=0.7)
[![Ipopt](http://pkg.julialang.org/badges/Ipopt_0.7.svg)](http://pkg.julialang.org/?pkg=Ipopt&ver=1.0)

**Ipopt.jl** is a [Julia](http://julialang.org/) interface to the [Ipopt](http://www.coin-or.org/Ipopt/documentation/documentation.html) nonlinear solver.

Expand Down
5 changes: 2 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
julia 0.6
MathProgBase 0.5 0.8
julia 0.7
MathProgBase 0.7
MathOptInterface 0.4 0.5
BinaryProvider 0.2
BinDeps
Compat 0.67.1
36 changes: 13 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1.0
- julia_version: latest

platform:
- x86 # 32-bit
- x64 # 64-bit

branches:
only:
- master
- /release-.*/

notifications:
- provider: Email
Expand All @@ -18,24 +20,12 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# if there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Ipopt\"); Pkg.build(\"Ipopt\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"Ipopt\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"
3 changes: 1 addition & 2 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using BinaryProvider
using BinDeps
using Compat

# BinaryBuilder artifacts for linux currently assume libgfortran.so.4
# is present, so they will not work for any source builds of Julia itself
# when a GCC version older than 7 was used. BinaryBuilder also does not
# support FreeBSD or non-glibc Linux distributions. Continue building from
# source on non-apple unices while these limitations apply.
use_BinaryProvider = Compat.Sys.isapple() || Compat.Sys.iswindows()
use_BinaryProvider = Sys.isapple() || Sys.iswindows()

@BinDeps.setup
if use_BinaryProvider
Expand Down
41 changes: 19 additions & 22 deletions src/Ipopt.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
__precompile__()

module Ipopt
using Compat
using Compat.LinearAlgebra
using LinearAlgebra, Libdl

if isfile(joinpath(dirname(@__FILE__),"..","deps","deps.jl"))
include("../deps/deps.jl")
Expand All @@ -23,10 +20,10 @@ function __init__()
# Sets up the library paths so that we can run the ipopt binary from Julia.
# TODO: Restructure into a function that wraps the call to the binary and
# doesn't leave environment variables changed.
julia_libdir = joinpath(dirname(first(filter(x -> occursin("libjulia", x), Compat.Libdl.dllist()))), "julia")
@static if Compat.Sys.isapple()
julia_libdir = joinpath(dirname(first(filter(x -> occursin("libjulia", x), Libdl.dllist()))), "julia")
@static if Sys.isapple()
ENV["DYLD_LIBRARY_PATH"] = string(get(ENV, "DYLD_LIBRARY_PATH", ""), ":", julia_libdir)
elseif Compat.Sys.islinux()
elseif Sys.islinux()
ENV["LD_LIBRARY_PATH"] = string(get(ENV, "LD_LIBRARY_PATH", ""), ":", julia_libdir)
end
end
Expand Down Expand Up @@ -64,7 +61,7 @@ mutable struct IpoptProblem
:Min)
# Free the internal IpoptProblem structure when
# the Julia IpoptProblem instance goes out of scope
@compat finalizer(freeProblem, prob)
finalizer(freeProblem, prob)
# Return the object we just made
prob
end
Expand Down Expand Up @@ -187,30 +184,30 @@ function createProblem(n::Int, x_L::Vector{Float64}, x_U::Vector{Float64},
@assert m == length(g_L) == length(g_U)
# Wrap callbacks
eval_f_cb = @cfunction(eval_f_wrapper, Cint,
(Cint, Ptr{Float64}, Cint, Ptr{Float64}, Ptr{Cvoid}))
(Cint, Ptr{Float64}, Cint, Ptr{Float64}, Ptr{Cvoid}))
eval_g_cb = @cfunction(eval_g_wrapper, Cint,
(Cint, Ptr{Float64}, Cint, Cint, Ptr{Float64}, Ptr{Cvoid}))
(Cint, Ptr{Float64}, Cint, Cint, Ptr{Float64}, Ptr{Cvoid}))
eval_grad_f_cb = @cfunction(eval_grad_f_wrapper, Cint,
(Cint, Ptr{Float64}, Cint, Ptr{Float64}, Ptr{Cvoid}))
(Cint, Ptr{Float64}, Cint, Ptr{Float64}, Ptr{Cvoid}))
eval_jac_g_cb = @cfunction(eval_jac_g_wrapper, Cint,
(Cint, Ptr{Float64}, Cint, Cint, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Float64}, Ptr{Cvoid}))
(Cint, Ptr{Float64}, Cint, Cint, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Float64}, Ptr{Cvoid}))
eval_h_cb = @cfunction(eval_h_wrapper, Cint,
(Cint, Ptr{Float64}, Cint, Float64, Cint, Ptr{Float64}, Cint, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Float64}, Ptr{Cvoid}))
(Cint, Ptr{Float64}, Cint, Float64, Cint, Ptr{Float64}, Cint, Cint, Ptr{Cint}, Ptr{Cint}, Ptr{Float64}, Ptr{Cvoid}))

ret = ccall((:CreateIpoptProblem, libipopt), Ptr{Cvoid},
(Cint, Ptr{Float64}, Ptr{Float64}, # Num vars, var lower and upper bounds
Cint, Ptr{Float64}, Ptr{Float64}, # Num constraints, con lower and upper bounds
Cint, Cint, # Num nnz in constraint Jacobian and in Hessian
Cint, # 0 for C, 1 for Fortran
Ptr{Cvoid}, Ptr{Cvoid}, # Callbacks for eval_f, eval_g
Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), # Callbacks for eval_grad_f, eval_jac_g, eval_h
n, x_L, x_U, m, g_L, g_U, nele_jac, nele_hess, 1,
eval_f_cb, eval_g_cb, eval_grad_f_cb, eval_jac_g_cb, eval_h_cb)
(Cint, Ptr{Float64}, Ptr{Float64}, # Num vars, var lower and upper bounds
Cint, Ptr{Float64}, Ptr{Float64}, # Num constraints, con lower and upper bounds
Cint, Cint, # Num nnz in constraint Jacobian and in Hessian
Cint, # 0 for C, 1 for Fortran
Ptr{Cvoid}, Ptr{Cvoid}, # Callbacks for eval_f, eval_g
Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}), # Callbacks for eval_grad_f, eval_jac_g, eval_h
n, x_L, x_U, m, g_L, g_U, nele_jac, nele_hess, 1,
eval_f_cb, eval_g_cb, eval_grad_f_cb, eval_jac_g_cb, eval_h_cb)

if ret == C_NULL
error("IPOPT: Failed to construct problem.")
else
return(IpoptProblem(ret, n, m, eval_f, eval_g, eval_grad_f, eval_jac_g, eval_h))
return IpoptProblem(ret, n, m, eval_f, eval_g, eval_grad_f, eval_jac_g, eval_h)
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/MOIWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ function MOI.optimize!(m::IpoptOptimizer)
# Objective gradient callback
function eval_grad_f_cb(x, grad_f)
eval_objective_gradient(m, grad_f, x)
Compat.rmul!(grad_f,objective_scale)
rmul!(grad_f,objective_scale)
end

# Constraint value callback
Expand Down
8 changes: 4 additions & 4 deletions src/MPBWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function MPB.loadproblem!(m::IpoptMathProgModel, numVar::Integer, numConstr::Int
# Objective gradient callback
function eval_grad_f_cb(x, grad_f)
MPB.eval_grad_f(d, grad_f, x)
Compat.rmul!(grad_f, scl)
rmul!(grad_f, scl)
end

# Constraint value callback
Expand Down Expand Up @@ -116,8 +116,8 @@ function MPB.optimize!(m::IpoptMathProgModel)
copyto!(m.inner.x, m.warmstart) # set warmstart
for (name,value) in m.options
sname = string(name)
if match(r"(^resto_)", sname) != nothing
sname = replace(sname, r"(^resto_)", "resto.")
if occursin(r"(^resto_)", sname)
sname = replace(sname, r"(^resto_)" => "resto.")
end
addOption(m.inner, sname, value)
end
Expand Down Expand Up @@ -158,7 +158,7 @@ function MPB.status(m::IpoptMathProgModel)
# :NonIpopt_Exception_Thrown
# :Insufficient_Memory
# :Internal_Error
warn("Ipopt finished with status $stat_sym")
@warn "Ipopt finished with status $stat_sym"
return :Error
end

Expand Down
10 changes: 6 additions & 4 deletions test/MPBWrapper.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Test MathProgBase stuff

using MathProgBase
using Compat.LinearAlgebra
using Compat.SparseArrays
using LinearAlgebra
using SparseArrays

const MathProgBase_test_dir = joinpath(dirname(pathof(MathProgBase)), "..", "test")

solver = IpoptSolver()
sol = linprog([-1,0],[2 1],'<',1.5,solver)
Expand Down Expand Up @@ -30,13 +32,13 @@ sol = linprog([-1,-1],[-1 2],'<',[0],solver)
# @test sol.status == :Unbounded


include(joinpath(Pkg.dir("MathProgBase"),"test","nlp.jl"))
include(joinpath(MathProgBase_test_dir, "nlp.jl"))
nlptest(IpoptSolver())
nlptest_nohessian(IpoptSolver())
convexnlptest(IpoptSolver())
rosenbrocktest(IpoptSolver())

include(joinpath(Pkg.dir("MathProgBase"),"test","quadprog.jl"))
include(joinpath(MathProgBase_test_dir, "quadprog.jl"))
quadprogtest(IpoptSolver())
qpdualtest(IpoptSolver())

Expand Down
3 changes: 0 additions & 3 deletions test/hs071_test.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using Ipopt
using Compat.Test

# hs071
# min x1 * x4 * (x1 + x2 + x3) + x3
# st x1 * x2 * x3 * x4 >= 25
Expand Down
47 changes: 28 additions & 19 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
using Ipopt
using Compat
using Compat.Test
using Test

@testset "Ipopt" begin

@testset "C API" begin
# First of all, test that hs071 example works
include("hs071_test.jl")

# Test setting some options
# String option
println("\nString option")
addOption(prob, "hessian_approximation", "exact")
@test_throws ErrorException addOption(prob, "hessian_approximation", "badoption")
println("\nInt option")
# Int option
addOption(prob, "file_print_level", 3) == nothing
@test_throws ErrorException addOption(prob, "file_print_level", -1)
# Double option
println("\nFloat option")
addOption(prob, "derivative_test_tol", 0.5)
@test_throws ErrorException addOption(prob, "derivative_test_tol", -1.0)

# Test opening an output file
openOutputFile(prob, "blah.txt", 5)
@testset "options" begin
@testset "String option" begin
addOption(prob, "hessian_approximation", "exact")
@test_throws ErrorException addOption(prob, "hessian_approximation", "badoption")
end

@testset "Int option" begin
# Int option
addOption(prob, "file_print_level", 3) == nothing
@test_throws ErrorException addOption(prob, "file_print_level", -1)
end

@testset "Float option" begin
addOption(prob, "derivative_test_tol", 0.5)
@test_throws ErrorException addOption(prob, "derivative_test_tol", -1.0)
end
end

@testset "open output file" begin
openOutputFile(prob, "blah.txt", 5)
end

Ipopt.freeProblem(prob) # Needed before the `rm` on Windows.
# unlink the output file
rm("blah.txt")

# Test that the ipopt binary works
# See https://github.com/JuliaOpt/Ipopt.jl/issues/119 for discussion of the
# known failure on Windows and Julia 0.7.
if !(Compat.Sys.iswindows() && VERSION >= v"0.7-")
if !(Sys.iswindows() && VERSION >= v"0.7-")
@test success(`$(Ipopt.amplexe) -v`)
end
end
Expand All @@ -41,3 +48,5 @@ end
@testset "MathOptInterface" begin
include("MOIWrapper.jl")
end

end

0 comments on commit 794763e

Please sign in to comment.