From 9bc9c66578b6f9732505b8f4688aeafb8a7c58a8 Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 6 Nov 2024 12:23:24 +1300 Subject: [PATCH] Remove out-dated precompile.jl and simplify compile_workload --- src/JuMP.jl | 40 +++---------------------------- src/precompile.jl | 60 ----------------------------------------------- 2 files changed, 3 insertions(+), 97 deletions(-) delete mode 100644 src/precompile.jl diff --git a/src/JuMP.jl b/src/JuMP.jl index 94f7a17f0cf..732f9d8485b 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -1367,13 +1367,7 @@ PrecompileTools.@compile_workload begin # at lowering time, not much of this would get precompiled without `@eval` @eval begin let - model = Model( - () -> MOI.Utilities.MockOptimizer( - MOI.Utilities.UniversalFallback( - MOI.Utilities.Model{Float64}(), - ), - ), - ) + model = Model() @variables(model, begin x1 >= 0 0 <= x2 <= 1 @@ -1387,6 +1381,7 @@ PrecompileTools.@compile_workload begin @expressions(model, begin a, -1 + x1 + x2 b, 1 + x1^2 + x2 + nl_expr, sin(x) end) @constraints(model, begin c1, a >= 0 @@ -1400,42 +1395,13 @@ 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) - 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 diff --git a/src/precompile.jl b/src/precompile.jl deleted file mode 100644 index fc795b53927..00000000000 --- a/src/precompile.jl +++ /dev/null @@ -1,60 +0,0 @@ -# This precompile statements are a mix of hand-generated ones (for example, to -# ensure coverage across the breadth of common constraint types, as well as some -# SnoopCompile ones that are expensive.) - -function _precompile_() - ccall(:jl_generating_output, Cint, ()) == 1 || return nothing - T = Float64 - scalar_sets = ( - MOI.LessThan{T}, - MOI.GreaterThan{T}, - MOI.EqualTo{T}, - MOI.Interval{T}, - MOI.Integer, - MOI.ZeroOne, - MOI.Semiinteger{T}, - MOI.Semicontinuous{T}, - ) - scalar_functions = ( - MOI.VariableIndex, - MOI.ScalarAffineFunction{T}, - MOI.ScalarQuadraticFunction{T}, - ) - vector_sets = ( - MOI.Nonnegatives, - MOI.Nonpositives, - MOI.Zeros, - MOI.Reals, - MOI.SecondOrderCone, - MOI.RotatedSecondOrderCone, - MOI.ExponentialCone, - MOI.DualExponentialCone, - MOI.PositiveSemidefiniteConeSquare, - MOI.PositiveSemidefiniteConeTriangle, - ) - vector_functions = ( - MOI.VectorOfVariables, - MOI.VectorAffineFunction{T}, - MOI.VectorQuadraticFunction{T}, - ) - constraints = vcat( - [(F, S) for F in scalar_functions for S in scalar_sets], - [(F, S) for F in vector_functions for S in vector_sets], - ) - for (F, S) in constraints - Base.precompile( - _moi_add_constraint, - ( - MOIU.CachingOptimizer{ - MOI.AbstractOptimizer, - MOIU.UniversalFallback{MOIU.Model{Float64}}, - }, - F, - S, - ), - ) - end - - Base.precompile(Tuple{typeof(model_string),Type,Model}) # time: 0.25714603 - return -end