diff --git a/Project.toml b/Project.toml index 475e5f39b9..60d0fabe06 100644 --- a/Project.toml +++ b/Project.toml @@ -14,6 +14,7 @@ MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0" NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -30,6 +31,7 @@ JSONSchema = "1" MutableArithmetics = "1" NaNMath = "0.3, 1" OrderedCollections = "1" +SnoopPrecompile = "1" SpecialFunctions = "0.8, 1, 2" julia = "1.6" diff --git a/src/MathOptInterface.jl b/src/MathOptInterface.jl index b58c318ab9..774f3840e3 100644 --- a/src/MathOptInterface.jl +++ b/src/MathOptInterface.jl @@ -269,4 +269,36 @@ we provide this `MOI.IndexMap` as an alias. """ const IndexMap = Utilities.IndexMap +import SnoopPrecompile + +SnoopPrecompile.@precompile_setup begin + SnoopPrecompile.@precompile_all_calls begin + let + optimizer = + () -> Utilities.MockOptimizer( + Utilities.UniversalFallback(Utilities.Model{Float64}()), + ) + model = Utilities.CachingOptimizer( + Utilities.UniversalFallback(Utilities.Model{Float64}()), + instantiate(optimizer; with_bridge_type = Float64), + ) + set(model, Silent(), true) + x = add_variables(model, 3) + add_constraint(model, x[1], ZeroOne()) + add_constraint(model, x[2], Integer()) + add_constraint(model, x[1], GreaterThan(0.0)) + add_constraint(model, x[2], LessThan(0.0)) + add_constraint(model, x[3], EqualTo(0.0)) + f = 1.0 * x[1] + x[2] + x[3] + add_constraint(model, f, GreaterThan(0.0)) + add_constraint(model, f, LessThan(0.0)) + add_constraint(model, f, EqualTo(0.0)) + y, _ = add_constrained_variables(model, Nonnegatives(2)) + set(model, ObjectiveSense(), MAX_SENSE) + set(model, ObjectiveFunction{typeof(f)}(), f) + optimize!(model) + end + end +end + end diff --git a/src/instantiate.jl b/src/instantiate.jl index 431d46f00a..899b187c5a 100644 --- a/src/instantiate.jl +++ b/src/instantiate.jl @@ -87,7 +87,7 @@ const _INSTANTIATE_NOT_CALLABLE_MESSAGE = Create an instance of optimizer by calling `optimizer_constructor`. Then check that the type returned is an empty [`ModelLike`](@ref). """ -function _instantiate_and_check(optimizer_constructor) +function _instantiate_and_check((@nospecialize optimizer_constructor)) if !applicable(optimizer_constructor) error(_INSTANTIATE_NOT_CALLABLE_MESSAGE) end @@ -143,7 +143,7 @@ problem incrementally (see [`supports_incremental_interface`](@ref)), then a model. """ function instantiate( - optimizer_constructor; + (@nospecialize optimizer_constructor); with_bridge_type::Union{Nothing,Type} = nothing, ) optimizer = _instantiate_and_check(optimizer_constructor)