Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions lib/OptimizationBase/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand Down Expand Up @@ -47,6 +48,7 @@ FastClosures = "0.3"
FiniteDiff = "2.12"
ForwardDiff = "0.10.26, 1"
LinearAlgebra = "1.9, 1.10"
PrecompileTools = "1"
MLDataDevices = "1"
MLUtils = "0.4"
PDMats = "0.11"
Expand Down
2 changes: 2 additions & 0 deletions lib/OptimizationBase/src/OptimizationBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ include("state.jl")
export solve, OptimizationCache, DEFAULT_CALLBACK, DEFAULT_DATA
export IncompatibleOptimizerError, OptimizerMissingError

include("precompilation.jl")

end
22 changes: 22 additions & 0 deletions lib/OptimizationBase/src/precompilation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using PrecompileTools

@setup_workload begin
@compile_workload begin
# Precompile basic OptimizationFunction and OptimizationProblem creation
# These are the most common operations users perform

# Simple objective function
f_simple(x, p) = sum(abs2, x .- p)

# Create OptimizationFunction with NoAD (most basic case)
optf = OptimizationFunction(f_simple)

# Create OptimizationProblem with common type combinations
x0 = zeros(2)
p = [1.0, 2.0]
prob = OptimizationProblem(optf, x0, p)

# Also precompile with bounds
prob_bounded = OptimizationProblem(optf, x0, p; lb = zeros(2), ub = ones(2))
end
end
Loading