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

Add PrecompileTools.jl #154

Merged
merged 2 commits into from
Nov 27, 2024
Merged
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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ Clp_jll = "06985876-5285-5a41-9fcb-8948a742cc53"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
OpenBLAS32_jll = "656ef2d0-ae68-5445-9ca0-591084a874a2"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
Clp_jll = "=100.1700.601, =100.1700.700, =100.1700.900, =100.1700.901"
LinearAlgebra = "1.6"
MathOptInterface = "1.1"
OpenBLAS32_jll = "0.3.10"
PrecompileTools = "1"
julia = "1.6"

[extras]
Expand Down
37 changes: 33 additions & 4 deletions src/Clp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module Clp

import Clp_jll
import Clp_jll: libClp
import LinearAlgebra
import MathOptInterface as MOI
import OpenBLAS32_jll
Expand All @@ -17,9 +17,10 @@ function __init__()
LinearAlgebra.BLAS.lbt_forward(OpenBLAS32_jll.libopenblas_path)
end
end
global libClp = Clp_jll.libClp
version = VersionNumber(
"$(Clp_VersionMajor()).$(Clp_VersionMinor()).$(Clp_VersionRelease())",
Clp_VersionMajor(),
Clp_VersionMinor(),
Clp_VersionRelease(),
)
if !(v"1.17.2" <= version <= v"1.17.9")
error(
Expand All @@ -34,7 +35,6 @@ end

include("libClp.jl")
include("MOI_wrapper/MOI_wrapper.jl")
include("precompile.jl")

# Clp exports all `Clp_xxx` symbols. If you don't want all of these symbols in
# your environment, then use `import Clp` instead of `using Clp`.
Expand All @@ -43,4 +43,33 @@ for sym in filter(s -> startswith("$s", "Clp_"), names(@__MODULE__, all = true))
@eval export $sym
end

import PrecompileTools

PrecompileTools.@setup_workload begin
PrecompileTools.@compile_workload begin
let
model = MOI.Utilities.CachingOptimizer(
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
MOI.instantiate(Clp.Optimizer; with_bridge_type = Float64),
)
MOI.set(model, MOI.Silent(), true)
x = MOI.add_variables(model, 3)
sets = (MOI.GreaterThan(0.0), MOI.LessThan(2.0), MOI.EqualTo(1.0))
for i in 1:3, f in (x[i], 1.0 * x[1] + 2.0 * x[2])
MOI.supports_constraint(model, typeof(f), typeof(sets[i]))
MOI.add_constraint(model, f, sets[i])
end
f = 1.0 * x[1] + x[2] + x[3]
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
MOI.supports(model, MOI.ObjectiveFunction{typeof(f)}())
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.optimize!(model)
MOI.get(model, MOI.TerminationStatus())
MOI.get(model, MOI.PrimalStatus())
MOI.get(model, MOI.DualStatus())
MOI.get(model, MOI.VariablePrimal(), x)
end
end
end

end
21 changes: 0 additions & 21 deletions src/precompile.jl

This file was deleted.

Loading