Skip to content

Commit d1a2d70

Browse files
authored
Add PrecompileTools.jl (#308)
1 parent c7467dc commit d1a2d70

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

Project.toml

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ version = "2.0.2"
55

66
[deps]
77
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
8+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
89
SCS_jll = "f4f2fc5b-1d94-523c-97ea-2ab488bedf4b"
910
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1011

11-
[extensions]
12-
SCSSCS_GPU_jllExt = ["SCS_GPU_jll"]
13-
SCSSCS_MKL_jllExt = ["SCS_MKL_jll"]
14-
1512
[weakdeps]
1613
SCS_GPU_jll = "af6e375f-46ec-5fa0-b791-491b0dfa44a4"
1714
SCS_MKL_jll = "3f2553a9-4106-52be-b7dd-865123654657"
1815

16+
[extensions]
17+
SCSSCS_GPU_jllExt = ["SCS_GPU_jll"]
18+
SCSSCS_MKL_jllExt = ["SCS_MKL_jll"]
19+
1920
[compat]
2021
MathOptInterface = "1.20"
2122
Pkg = "<0.0.1, ^1.6"
23+
PrecompileTools = "1"
2224
SCS_GPU_jll = "=3.2.4, =3.2.6, =3.2.7"
2325
SCS_MKL_jll = "=3.2.4, =3.2.6, =3.2.7"
2426
SCS_jll = "=3.2.4, =3.2.6, =3.2.7"

src/SCS.jl

+42
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,46 @@ struct MKLDirectSolver <: LinearSolver end
2626

2727
export scs_solve
2828

29+
import PrecompileTools
30+
31+
PrecompileTools.@setup_workload begin
32+
PrecompileTools.@compile_workload begin
33+
model = MOI.Utilities.CachingOptimizer(
34+
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
35+
MOI.instantiate(SCS.Optimizer; with_bridge_type = Float64),
36+
)
37+
MOI.set(model, MOI.Silent(), true)
38+
x = MOI.add_variables(model, 3)
39+
MOI.supports(model, MOI.VariableName(), typeof(x[1]))
40+
MOI.set(model, MOI.VariableName(), x[1], "x1")
41+
MOI.set(model, MOI.VariablePrimalStart(), x[1], 0.0)
42+
sets = (MOI.GreaterThan(0.0), MOI.LessThan(0.0), MOI.GreaterThan(0.0))
43+
for (i, set) in enumerate(sets)
44+
MOI.add_constrained_variable(model, set)
45+
MOI.supports_constraint(model, typeof(x[i]), typeof(set))
46+
MOI.add_constraint(model, x[i], set)
47+
MOI.supports_constraint(model, typeof(1.0 * x[i]), typeof(set))
48+
c = MOI.add_constraint(model, 1.0 * x[i] + 0.0, set)
49+
MOI.supports(model, MOI.ConstraintName(), typeof(c))
50+
MOI.set(model, MOI.ConstraintName(), c, "c1")
51+
end
52+
f = 1.0 * x[1] + x[2] + x[3]
53+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
54+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
55+
g_vov = MOI.VectorOfVariables(x)
56+
g_vaf = MOI.Utilities.vectorize(1.0 .* x)
57+
for set in (MOI.ExponentialCone(), MOI.SecondOrderCone(3))
58+
MOI.add_constraint(model, g_vov, set)
59+
MOI.add_constraint(model, g_vaf, set)
60+
end
61+
MOI.supports(model, MOI.ObjectiveFunction{typeof(f)}())
62+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
63+
MOI.optimize!(model)
64+
MOI.get(model, MOI.TerminationStatus())
65+
MOI.get(model, MOI.PrimalStatus())
66+
MOI.get(model, MOI.DualStatus())
67+
MOI.get(model, MOI.VariablePrimal(), x)
68+
end
69+
end
70+
2971
end

0 commit comments

Comments
 (0)