Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify usage of PrecompileTools.jl to improve code coverage #3954

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions src/JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1357,25 +1357,21 @@ export MOI

import PrecompileTools

PrecompileTools.@compile_workload begin
# Because lots of the work is done by macros, and macros are expanded
# at lowering time, not much of this would get precompiled without `@eval`
@eval begin
let
# We don't care about this particular optimizer, but it still
# exercises generic code paths that calls like
# Model(HiGHS.Optimizer) also need.
Model(
() -> MOI.Utilities.MockOptimizer(
MOI.Utilities.UniversalFallback(
MOI.Utilities.Model{Float64}(),
),
),
)
# Use an empty model to build, which is a common use-case, and
# doesn't bake in Utilities.MockOptimizer.
function _optimizer_for_precompile_tools()
return MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
end

PrecompileTools.@setup_workload begin
PrecompileTools.@compile_workload begin
# We don't care about this particular optimizer, but it still
# exercises generic code paths that calls like
# Model(HiGHS.Optimizer) also need.
model = Model(_optimizer_for_precompile_tools)
optimize!(model)
# Because lots of the work is done by macros, and macros are expanded
# at lowering time, not much of this would get precompiled without `@eval`
@eval begin
model = Model()
set_silent(model)
@variables(model, begin
x1 >= 0
0 <= x2 <= 1
Expand Down Expand Up @@ -1408,15 +1404,6 @@ PrecompileTools.@compile_workload begin
@objective(model, Min, x1)
@objective(model, Max, a)
@objective(model, Min, b)
set_optimizer(
model,
() -> MOI.Utilities.MockOptimizer(
MOI.Utilities.UniversalFallback(
MOI.Utilities.Model{Float64}(),
),
),
)
optimize!(model)
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/test_generate_and_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,9 @@ function test_compute_conflict()
return
end

function test__optimizer_for_precompile_tools()
@test _optimizer_for_precompile_tools() isa MOI.Utilities.MockOptimizer
return
end

end # module
Loading