From ccd5bec74b9547ef724edc12cf016dbe9fd013f3 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 27 Nov 2024 15:07:26 +1300 Subject: [PATCH] Add PrecompileTools.jl --- Project.toml | 2 ++ src/Clp.jl | 37 +++++++++++++++++++++++++++++++++---- src/precompile.jl | 21 --------------------- 3 files changed, 35 insertions(+), 25 deletions(-) delete mode 100644 src/precompile.jl diff --git a/Project.toml b/Project.toml index 62ad71a..cad0919 100644 --- a/Project.toml +++ b/Project.toml @@ -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] diff --git a/src/Clp.jl b/src/Clp.jl index e9c6cea..ded1e84 100644 --- a/src/Clp.jl +++ b/src/Clp.jl @@ -5,7 +5,7 @@ module Clp -import Clp_jll +import Clp_jll: libClp import LinearAlgebra import MathOptInterface as MOI import OpenBLAS32_jll @@ -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( @@ -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`. @@ -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 diff --git a/src/precompile.jl b/src/precompile.jl deleted file mode 100644 index 61bab13..0000000 --- a/src/precompile.jl +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (c) 2013: Clp.jl contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. - -function warmup() - bridge = MOI.instantiate(Optimizer; with_bridge_type=Float64) - no_bridge = MOI.instantiate(Optimizer) - cache = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) - MOI.optimize!(bridge, cache) - MOI.optimize!(no_bridge, cache) - return -end - -function _precompile_() - ccall(:jl_generating_output, Cint, ()) == 1 || return nothing - precompile(warmup, ()) - return -end - -_precompile_()