Skip to content

Commit

Permalink
Fix libblastrampoline with Ipopt_jll (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Feb 20, 2024
1 parent 339e502 commit 732090e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
11 changes: 8 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ uuid = "7c4d4715-977e-5154-bfe0-e096adeac482"
version = "1.2.0"

[deps]
Ipopt_jll = "9cc047cb-c261-5740-88fc-0cf96f7bdcc7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
OpenBLAS32_jll = "656ef2d0-ae68-5445-9ca0-591084a874a2"

[compat]
Ipopt_jll = "=300.1400.400"
Ipopt_jll = "=300.1400.400, =300.1400.1400"
LinearAlgebra = "<0.0.1, 1.6"
MathOptInterface = "1.18"
OpenBLAS32_jll = "0.3.12, 0.3.24"
Test = "<0.0.1, 1.6"
julia = "1.6"

[extras]
Ipopt_jll = "9cc047cb-c261-5740-88fc-0cf96f7bdcc7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Ipopt_jll", "Test"]
36 changes: 29 additions & 7 deletions src/AmplNLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,27 @@

module AmplNLWriter

import LinearAlgebra
import MathOptInterface as MOI
import OpenBLAS32_jll

function __init__()
if VERSION >= v"1.8"
config = LinearAlgebra.BLAS.lbt_get_config()
if !any(lib -> lib.interface == :lp64, config.loaded_libs)
LinearAlgebra.BLAS.lbt_forward(OpenBLAS32_jll.libopenblas_path)
end
end
return
end

function _get_blas_loaded_libs()
if VERSION >= v"1.8"
config = LinearAlgebra.BLAS.lbt_get_config()
return join([lib.libname for lib in config.loaded_libs], ";")
end
return ""
end

"""
AbstractSolverCommand
Expand Down Expand Up @@ -47,13 +67,15 @@ function call_solver(
stdout::IO,
)
solver.f() do solver_path
ret = run(
pipeline(
`$(solver_path) $(nl_filename) -AMPL $(options)`,
stdin = stdin,
stdout = stdout,
),
)
# Solvers like Ipopt_jll use libblastrampoline. That requires us to set
# the BLAS library via the LBT_DEFAULT_LIBS environment variable.
# Provide a default in case the user doesn't set.
lbt_default_libs = get(ENV, "LBT_DEFAULT_LIBS", _get_blas_loaded_libs())
cmd = `$(solver_path) $(nl_filename) -AMPL $(options)`
if !isempty(lbt_default_libs)
cmd = addenv(cmd, "LBT_DEFAULT_LIBS" => lbt_default_libs)
end
ret = run(pipeline(cmd; stdin = stdin, stdout = stdout))
if ret.exitcode != 0
error("Nonzero exit code: $(ret.exitcode)")
end
Expand Down
2 changes: 1 addition & 1 deletion test/MINLPTests/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[compat]
Bonmin_jll = "100.800.801"
Couenne_jll = "0.500.801"
Ipopt_jll = "=300.1400.400"
Ipopt_jll = "=300.1400.400, =300.1400.1400"
JuMP = "1"
MINLPTests = "0.6"
SHOT_jll = "100.100.0"
Expand Down

0 comments on commit 732090e

Please sign in to comment.