Skip to content

Commit cb441df

Browse files
authored
Remove out-dated precompile.jl and simplify compile_workload (#3871)
1 parent 5db6846 commit cb441df

File tree

2 files changed

+19
-91
lines changed

2 files changed

+19
-91
lines changed

src/JuMP.jl

+19-31
Original file line numberDiff line numberDiff line change
@@ -1367,13 +1367,20 @@ PrecompileTools.@compile_workload begin
13671367
# at lowering time, not much of this would get precompiled without `@eval`
13681368
@eval begin
13691369
let
1370-
model = Model(
1370+
# We don't care about this particular optimizer, but it still
1371+
# exercises generic code paths that calls like
1372+
# Model(HiGHS.Optimizer) also need.
1373+
Model(
13711374
() -> MOI.Utilities.MockOptimizer(
13721375
MOI.Utilities.UniversalFallback(
13731376
MOI.Utilities.Model{Float64}(),
13741377
),
13751378
),
13761379
)
1380+
# Use an empty model to build, which is a common use-case, and
1381+
# doesn't bake in Utilities.MockOptimizer.
1382+
model = Model()
1383+
set_silent(model)
13771384
@variables(model, begin
13781385
x1 >= 0
13791386
0 <= x2 <= 1
@@ -1385,8 +1392,9 @@ PrecompileTools.@compile_workload begin
13851392
x8[i = 1:3; isodd(i)], (start = i)
13861393
end)
13871394
@expressions(model, begin
1388-
a, -1 + x1 + x2
1395+
a, 2 * x1 + 3 * x2
13891396
b, 1 + x1^2 + x2
1397+
nl_expr, sin(x1)
13901398
end)
13911399
@constraints(model, begin
13921400
c1, a >= 0
@@ -1400,42 +1408,22 @@ PrecompileTools.@compile_workload begin
14001408
[x1, x2, x1] in SecondOrderCone()
14011409
[1.0*x1 x2; x2 x1] >= 0, PSDCone()
14021410
1.0 * x1 x2
1411+
nl_expr <= 1
14031412
end)
14041413
@objective(model, Min, x1)
14051414
@objective(model, Max, a)
14061415
@objective(model, Min, b)
1407-
@NLconstraint(model, c9, 1 * sin(x1) + 2.0 * sin(a) + sin(b) <= 1)
1408-
@NLparameter(model, p == 2)
1409-
@NLexpression(model, expr, x1^p)
1410-
@NLobjective(model, Min, 1 + expr)
1416+
set_optimizer(
1417+
model,
1418+
() -> MOI.Utilities.MockOptimizer(
1419+
MOI.Utilities.UniversalFallback(
1420+
MOI.Utilities.Model{Float64}(),
1421+
),
1422+
),
1423+
)
14111424
optimize!(model)
1412-
# This block could sit in MOI, but it's a public API at the JuMP
1413-
# level, so it can go here.
1414-
#
1415-
# We evaluate with a `view` because it's a common type for solvers
1416-
# like Ipopt to use.
1417-
d = NLPEvaluator(model)
1418-
MOI.features_available(d)
1419-
MOI.initialize(d, [:Grad, :Jac, :Hess])
1420-
g = zeros(num_nonlinear_constraints(model))
1421-
v_g = view(g, 1:length(g))
1422-
x = zeros(num_variables(model))
1423-
MOI.eval_objective(d, x)
1424-
MOI.eval_constraint(d, g, x)
1425-
MOI.eval_constraint(d, v_g, x)
1426-
MOI.eval_objective_gradient(d, g, x)
1427-
J = zeros(length(MOI.jacobian_structure(d)))
1428-
MOI.eval_constraint_jacobian(d, J, x)
1429-
v_J = view(J, 1:length(J))
1430-
MOI.eval_constraint_jacobian(d, v_J, x)
1431-
H = zeros(length(MOI.hessian_lagrangian_structure(d)))
1432-
v_H = view(H, 1:length(H))
1433-
MOI.eval_hessian_lagrangian(d, v_H, x, 1.0, v_g)
14341425
end
14351426
end
14361427
end
14371428

1438-
include("precompile.jl")
1439-
_precompile_()
1440-
14411429
end

src/precompile.jl

-60
This file was deleted.

0 commit comments

Comments
 (0)