Skip to content

Commit

Permalink
Remove out-dated precompile.jl and simplify compile_workload (#3871)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Nov 6, 2024
1 parent 5db6846 commit cb441df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 91 deletions.
50 changes: 19 additions & 31 deletions src/JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1367,13 +1367,20 @@ PrecompileTools.@compile_workload begin
# at lowering time, not much of this would get precompiled without `@eval`
@eval begin
let
model = Model(
# 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.
model = Model()
set_silent(model)
@variables(model, begin
x1 >= 0
0 <= x2 <= 1
Expand All @@ -1385,8 +1392,9 @@ PrecompileTools.@compile_workload begin
x8[i = 1:3; isodd(i)], (start = i)
end)
@expressions(model, begin
a, -1 + x1 + x2
a, 2 * x1 + 3 * x2
b, 1 + x1^2 + x2
nl_expr, sin(x1)
end)
@constraints(model, begin
c1, a >= 0
Expand All @@ -1400,42 +1408,22 @@ PrecompileTools.@compile_workload begin
[x1, x2, x1] in SecondOrderCone()
[1.0*x1 x2; x2 x1] >= 0, PSDCone()
1.0 * x1 x2
nl_expr <= 1
end)
@objective(model, Min, x1)
@objective(model, Max, a)
@objective(model, Min, b)
@NLconstraint(model, c9, 1 * sin(x1) + 2.0 * sin(a) + sin(b) <= 1)
@NLparameter(model, p == 2)
@NLexpression(model, expr, x1^p)
@NLobjective(model, Min, 1 + expr)
set_optimizer(
model,
() -> MOI.Utilities.MockOptimizer(
MOI.Utilities.UniversalFallback(
MOI.Utilities.Model{Float64}(),
),
),
)
optimize!(model)
# This block could sit in MOI, but it's a public API at the JuMP
# level, so it can go here.
#
# We evaluate with a `view` because it's a common type for solvers
# like Ipopt to use.
d = NLPEvaluator(model)
MOI.features_available(d)
MOI.initialize(d, [:Grad, :Jac, :Hess])
g = zeros(num_nonlinear_constraints(model))
v_g = view(g, 1:length(g))
x = zeros(num_variables(model))
MOI.eval_objective(d, x)
MOI.eval_constraint(d, g, x)
MOI.eval_constraint(d, v_g, x)
MOI.eval_objective_gradient(d, g, x)
J = zeros(length(MOI.jacobian_structure(d)))
MOI.eval_constraint_jacobian(d, J, x)
v_J = view(J, 1:length(J))
MOI.eval_constraint_jacobian(d, v_J, x)
H = zeros(length(MOI.hessian_lagrangian_structure(d)))
v_H = view(H, 1:length(H))
MOI.eval_hessian_lagrangian(d, v_H, x, 1.0, v_g)
end
end
end

include("precompile.jl")
_precompile_()

end
60 changes: 0 additions & 60 deletions src/precompile.jl

This file was deleted.

0 comments on commit cb441df

Please sign in to comment.