From 7e665fb023c2033c3667ed5f523b48b468281b82 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 21 Feb 2025 17:26:23 +1300 Subject: [PATCH] Add PrecompileTools.jl --- Project.toml | 10 ++++++---- src/SCS.jl | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 2f669a9..6baed7c 100644 --- a/Project.toml +++ b/Project.toml @@ -5,20 +5,22 @@ version = "2.0.2" [deps] MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" SCS_jll = "f4f2fc5b-1d94-523c-97ea-2ab488bedf4b" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -[extensions] -SCSSCS_GPU_jllExt = ["SCS_GPU_jll"] -SCSSCS_MKL_jllExt = ["SCS_MKL_jll"] - [weakdeps] SCS_GPU_jll = "af6e375f-46ec-5fa0-b791-491b0dfa44a4" SCS_MKL_jll = "3f2553a9-4106-52be-b7dd-865123654657" +[extensions] +SCSSCS_GPU_jllExt = ["SCS_GPU_jll"] +SCSSCS_MKL_jllExt = ["SCS_MKL_jll"] + [compat] MathOptInterface = "1.20" Pkg = "<0.0.1, ^1.6" +PrecompileTools = "1" SCS_GPU_jll = "=3.2.4, =3.2.6, =3.2.7" SCS_MKL_jll = "=3.2.4, =3.2.6, =3.2.7" SCS_jll = "=3.2.4, =3.2.6, =3.2.7" diff --git a/src/SCS.jl b/src/SCS.jl index 453572a..fa042f4 100644 --- a/src/SCS.jl +++ b/src/SCS.jl @@ -26,4 +26,46 @@ struct MKLDirectSolver <: LinearSolver end export scs_solve +import PrecompileTools + +PrecompileTools.@setup_workload begin + PrecompileTools.@compile_workload begin + model = MOI.Utilities.CachingOptimizer( + MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), + MOI.instantiate(SCS.Optimizer; with_bridge_type = Float64), + ) + MOI.set(model, MOI.Silent(), true) + x = MOI.add_variables(model, 3) + MOI.supports(model, MOI.VariableName(), typeof(x[1])) + MOI.set(model, MOI.VariableName(), x[1], "x1") + MOI.set(model, MOI.VariablePrimalStart(), x[1], 0.0) + sets = (MOI.GreaterThan(0.0), MOI.LessThan(0.0), MOI.GreaterThan(0.0)) + for (i, set) in enumerate(sets) + MOI.add_constrained_variable(model, set) + MOI.supports_constraint(model, typeof(x[i]), typeof(set)) + MOI.add_constraint(model, x[i], set) + MOI.supports_constraint(model, typeof(1.0 * x[i]), typeof(set)) + c = MOI.add_constraint(model, 1.0 * x[i] + 0.0, set) + MOI.supports(model, MOI.ConstraintName(), typeof(c)) + MOI.set(model, MOI.ConstraintName(), c, "c1") + end + f = 1.0 * x[1] + x[2] + x[3] + MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) + MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) + g_vov = MOI.VectorOfVariables(x) + g_vaf = MOI.Utilities.vectorize(1.0 .* x) + for set in (MOI.ExponentialCone(), MOI.SecondOrderCone(3)) + MOI.add_constraint(model, g_vov, set) + MOI.add_constraint(model, g_vaf, set) + end + 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