Skip to content

Commit f820ac9

Browse files
authored
Add SnoopPrecompile directives (#2080)
1 parent 40b81c5 commit f820ac9

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
1414
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
1515
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1616
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
17+
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
1718
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1819
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1920
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
@@ -30,6 +31,7 @@ JSONSchema = "1"
3031
MutableArithmetics = "1"
3132
NaNMath = "0.3, 1"
3233
OrderedCollections = "1"
34+
SnoopPrecompile = "1"
3335
SpecialFunctions = "0.8, 1, 2"
3436
julia = "1.6"
3537

src/MathOptInterface.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,36 @@ we provide this `MOI.IndexMap` as an alias.
269269
"""
270270
const IndexMap = Utilities.IndexMap
271271

272+
import SnoopPrecompile
273+
274+
SnoopPrecompile.@precompile_setup begin
275+
SnoopPrecompile.@precompile_all_calls begin
276+
let
277+
optimizer =
278+
() -> Utilities.MockOptimizer(
279+
Utilities.UniversalFallback(Utilities.Model{Float64}()),
280+
)
281+
model = Utilities.CachingOptimizer(
282+
Utilities.UniversalFallback(Utilities.Model{Float64}()),
283+
instantiate(optimizer; with_bridge_type = Float64),
284+
)
285+
set(model, Silent(), true)
286+
x = add_variables(model, 3)
287+
add_constraint(model, x[1], ZeroOne())
288+
add_constraint(model, x[2], Integer())
289+
add_constraint(model, x[1], GreaterThan(0.0))
290+
add_constraint(model, x[2], LessThan(0.0))
291+
add_constraint(model, x[3], EqualTo(0.0))
292+
f = 1.0 * x[1] + x[2] + x[3]
293+
add_constraint(model, f, GreaterThan(0.0))
294+
add_constraint(model, f, LessThan(0.0))
295+
add_constraint(model, f, EqualTo(0.0))
296+
y, _ = add_constrained_variables(model, Nonnegatives(2))
297+
set(model, ObjectiveSense(), MAX_SENSE)
298+
set(model, ObjectiveFunction{typeof(f)}(), f)
299+
optimize!(model)
300+
end
301+
end
302+
end
303+
272304
end

src/instantiate.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const _INSTANTIATE_NOT_CALLABLE_MESSAGE =
8787
Create an instance of optimizer by calling `optimizer_constructor`.
8888
Then check that the type returned is an empty [`ModelLike`](@ref).
8989
"""
90-
function _instantiate_and_check(optimizer_constructor)
90+
function _instantiate_and_check((@nospecialize optimizer_constructor))
9191
if !applicable(optimizer_constructor)
9292
error(_INSTANTIATE_NOT_CALLABLE_MESSAGE)
9393
end
@@ -143,7 +143,7 @@ problem incrementally (see [`supports_incremental_interface`](@ref)), then a
143143
model.
144144
"""
145145
function instantiate(
146-
optimizer_constructor;
146+
(@nospecialize optimizer_constructor);
147147
with_bridge_type::Union{Nothing,Type} = nothing,
148148
)
149149
optimizer = _instantiate_and_check(optimizer_constructor)

0 commit comments

Comments
 (0)