Skip to content
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

Use .zip upload of knitro14 in CI #284

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ on:
branches: [master]
pull_request:
types: [opened, synchronize, reopened]
# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read
jobs:
test:
name: 'KNITRO'
runs-on: 'ubuntu-latest'
runs-on: '${{ matrix.os }}'
strategy:
fail-fast: false
matrix:
version: ['1.6', '1']
os: ['ubuntu-latest', 'macOS-latest', 'windows-latest']
arch: [x64]
include:
- version: '1'
os: macos-14
arch: aarch64
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: 'x64'
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- shell: bash
env:
ARTELYS_LIC_JUMP_DEV: ${{ secrets.ARTELYS_LIC_8326_JUMP_DEV_2023_11_02 }}
run: |
echo "$ARTELYS_LIC_JUMP_DEV" > ~/artelys_lic.txt
- uses: julia-actions/julia-buildpkg@v1
env:
SECRET_KNITRO_URL: ${{ secrets.SECRET_KNITRO_URL }}
SECRET_KNITRO_LIBIOMP5: ${{ secrets.SECRET_KNITRO_LIBIOMP5 }}
SECRET_KNITRO_ZIP: ${{ secrets.SECRET_KNITRO_ZIP }}
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
Expand Down
20 changes: 7 additions & 13 deletions .github/workflows/minlptests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,29 @@ on:
branches: [master]
pull_request:
types: [opened, synchronize, reopened]
# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read
jobs:
test:
name: KNITRO
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: '1'
arch: 'x64'
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v1
- shell: bash
env:
ARTELYS_LIC_JUMP_DEV: ${{ secrets.ARTELYS_LIC_8326_JUMP_DEV_2023_11_02 }}
run: |
echo "$ARTELYS_LIC_JUMP_DEV" > ~/artelys_lic.txt
- name: "run_minlptests"
env:
SECRET_KNITRO_URL: ${{ secrets.SECRET_KNITRO_URL }}
SECRET_KNITRO_LIBIOMP5: ${{ secrets.SECRET_KNITRO_LIBIOMP5 }}
SECRET_KNITRO_ZIP: ${{ secrets.SECRET_KNITRO_ZIP }}
shell: julia --color=yes {0}
run: |
path = joinpath(ENV["GITHUB_WORKSPACE"], "test", "MINLPTests")
Expand Down
32 changes: 26 additions & 6 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Libdl, Base.Sys
using Libdl

const DEPS_FILE = joinpath(dirname(@__FILE__), "deps.jl")

Expand Down Expand Up @@ -42,14 +42,34 @@ function try_local_installation()
end

function try_ci_installation()
local_filename = joinpath(@__DIR__, "libknitro.so")
download(ENV["SECRET_KNITRO_URL"], local_filename)
download(ENV["SECRET_KNITRO_LIBIOMP5"], joinpath(@__DIR__, "libiomp5.so"))
write_depsfile("", local_filename)
local_filename = joinpath(@__DIR__, "knitro14.zip")
# If these files exist, it is because they have been cached from a separate
# CI job.
if !isfile(local_filename)
download(ENV["SECRET_KNITRO_ZIP"], local_filename)
end
if !isfile("libknitro1400.so")
if Sys.islinux()
run(`unzip $local_filename`)
elseif Sys.isapple()
run(`tar -xf $local_filename`)
elseif Sys.iswindows()
run(`tar -xf $local_filename`)
end
end
filename = if Sys.islinux()
"libknitro1400.so"
elseif Sys.isapple()
joinpath(Sys.ARCH == :x86_64 ? "" : "mac-arm", "libknitro1400.dylib")
else
@assert Sys.iswindows()
"knitro1400.dll"
end
write_depsfile("", joinpath(@__DIR__, filename))
return
end

if get(ENV, "SECRET_KNITRO_URL", "") != ""
if get(ENV, "SECRET_KNITRO_ZIP", "") != ""
try_ci_installation()
else
try_local_installation()
Expand Down
2 changes: 1 addition & 1 deletion examples/qcqp1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function example_qcqp1(; verbose=true)
@testset "Example QCQP1" begin
@test nStatus == 0
@test objSol ≈ 936.0
@test x ≈ [0.0, 0.0, 8.0]
@test isapprox(x, [0.0, 0.0, 8.0]; atol=1e-5)
end
end

Expand Down
1 change: 1 addition & 0 deletions src/C_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Base.unsafe_convert(::Type{Ptr{Cvoid}}, kn::Model) = kn.env.ptr_env::Ptr{Cvoid}

"Free solver object."
function KN_free(model::Model)
@show model.env.ptr_env
if model.env.ptr_env != C_NULL
ret = KN_free(Ref(model.env.ptr_env))
model.env.ptr_env = C_NULL
Expand Down
11 changes: 7 additions & 4 deletions src/KNITRO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Libdl
import MathOptInterface as MOI
import SparseArrays

const _DEPS_FILE = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
const _DEPS_FILE = joinpath(dirname(@__DIR__), "deps", "deps.jl")
if isfile(_DEPS_FILE)
include(_DEPS_FILE)
else
Expand All @@ -19,9 +19,12 @@ end
has_knitro() = endswith(libknitro, Libdl.dlext)

function __init__()
libiomp5 = replace(libknitro, "libknitro" => "libiomp5")
if isfile(libiomp5)
Libdl.dlopen(libiomp5)
for libiomp_name in ("libiomp5.", "libomp.", "libiomp5md.")
libiomp = replace(libknitro, r"libknitro[0-9]+\." => libiomp_name)
if isfile(libiomp)
Libdl.dlopen(libiomp)
break
end
end
version = has_knitro() ? knitro_version() : v"0.0.0"
if version != v"0.0.0" && version < v"11.0"
Expand Down
17 changes: 8 additions & 9 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
complementarity_cache::_ComplementarityCache
# Constraint mappings.
constraint_mapping::Dict{MOI.ConstraintIndex,Union{Cint,Vector{Cint}}}
license_manager::Union{LMcontext,Nothing}
license_manager::LMcontext
options::Dict{String,Any}
# Cache for the solution
x::Vector{Float64}
Expand All @@ -139,11 +139,10 @@ function Optimizer(; license_manager::Union{LMcontext,Nothing}=nothing, kwargs..
if !isempty(kwargs)
error("Unsupported keyword arguments passed to `Optimizer`. Set attributes instead")
end
kc = if isa(license_manager, LMcontext)
KN_new_lm(license_manager)
else
KN_new()
if license_manager === nothing
license_manager = LMcontext()
end
kc = KN_new_lm(license_manager)
return Optimizer(
kc,
_VariableInfo[],
Expand Down Expand Up @@ -178,11 +177,11 @@ function MOI.copy_to(model::Optimizer, src::MOI.ModelLike)
end

function MOI.empty!(model::Optimizer)
p = model.inner.env.ptr_env
@_checked KN_free(model.inner)
model.inner = if isa(model.license_manager, LMcontext)
KN_new_lm(model.license_manager)
else
KN_new()
model.inner = KN_new_lm(model.license_manager)
if p == model.inner.env.ptr_env
error("Bad pointer: $p")
end
empty!(model.variable_info)
model.number_solved = 0
Expand Down
Loading
Loading