Skip to content

Commit 315812e

Browse files
Update solve.md
1 parent a297008 commit 315812e

File tree

1 file changed

+0
-80
lines changed

1 file changed

+0
-80
lines changed

docs/src/API/solve.md

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,83 +3,3 @@
33
```@docs
44
solve(::OptimizationProblem,::Any)
55
```
6-
7-
## Reusing Optimization Caches with `reinit!`
8-
9-
The `reinit!` function allows you to efficiently reuse an existing optimization cache with new parameters or initial values. This is particularly useful when solving similar optimization problems repeatedly with different parameter values, as it avoids the overhead of creating a new cache from scratch.
10-
11-
### Basic Usage
12-
13-
```julia
14-
# Create initial problem and cache
15-
using Optimization, OptimizationOptimJL
16-
rosenbrock(u, p) = (p[1] - u[1])^2 + p[2] * (u[2] - u[1]^2)^2
17-
u0 = zeros(2)
18-
p = [1.0, 100.0]
19-
20-
optf = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())
21-
prob = OptimizationProblem(optf, u0, p)
22-
23-
# Initialize cache and solve
24-
cache = Optimization.init(prob, Optim.BFGS())
25-
sol = Optimization.solve!(cache)
26-
27-
# Reinitialize cache with new parameters
28-
cache = Optimization.reinit!(cache; p = [2.0, 50.0])
29-
sol2 = Optimization.solve!(cache)
30-
```
31-
32-
### Supported Arguments
33-
34-
The `reinit!` function supports updating various fields of the optimization cache:
35-
36-
- `u0`: New initial values for the optimization variables
37-
- `p`: New parameter values
38-
- `lb`: New lower bounds (if applicable)
39-
- `ub`: New upper bounds (if applicable)
40-
- `lcons`: New lower bounds for constraints (if applicable)
41-
- `ucons`: New upper bounds for constraints (if applicable)
42-
43-
### Example: Parameter Sweep
44-
45-
```julia
46-
# Solve for multiple parameter values efficiently
47-
results = []
48-
p_values = [[1.0, 100.0], [2.0, 100.0], [3.0, 100.0]]
49-
50-
# Create initial cache
51-
cache = Optimization.init(prob, Optim.BFGS())
52-
53-
for p in p_values
54-
cache = Optimization.reinit!(cache; p = p)
55-
sol = Optimization.solve!(cache)
56-
push!(results, (p = p, u = sol.u, objective = sol.objective))
57-
end
58-
```
59-
60-
### Example: Updating Initial Values
61-
62-
```julia
63-
# Warm-start optimization from different initial points
64-
u0_values = [[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]]
65-
66-
for u0 in u0_values
67-
cache = Optimization.reinit!(cache; u0 = u0)
68-
sol = Optimization.solve!(cache)
69-
println("Starting from ", u0, " converged to ", sol.u)
70-
end
71-
```
72-
73-
### Performance Benefits
74-
75-
Using `reinit!` is more efficient than creating a new problem and cache for each parameter value, especially when:
76-
- The optimization algorithm maintains internal state that can be reused
77-
- The problem structure remains the same (only parameter values change)
78-
- You're performing parameter sweeps or sensitivity analysis
79-
80-
### Notes
81-
82-
- The `reinit!` function modifies the cache in-place and returns it for convenience
83-
- Not all fields need to be specified; only provide the ones you want to update
84-
- The function is particularly useful in iterative algorithms, parameter estimation, and when solving families of related optimization problems
85-
- For creating a new problem with different parameters (rather than modifying a cache), use `remake` on the `OptimizationProblem` instead

0 commit comments

Comments
 (0)