Skip to content

Commit d308614

Browse files
Merge branch 'SciML:master' into master
2 parents 0cb0e9c + 02c3d9f commit d308614

File tree

21 files changed

+2468
-13
lines changed

21 files changed

+2468
-13
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ jobs:
3333
- OptimizationOptimJL
3434
- OptimizationOptimisers
3535
- OptimizationPRIMA
36+
- OptimizationPyCMA
3637
- OptimizationQuadDIRECT
38+
- OptimizationSciPy
3739
- OptimizationSpeedMapping
3840
- OptimizationPolyalgorithms
3941
- OptimizationNLPModels

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Optimization"
22
uuid = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
3-
version = "4.3.0"
3+
version = "4.4.0"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

docs/pages.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pages = ["index.md",
2323
"API/modelingtoolkit.md",
2424
"API/FAQ.md"
2525
],
26-
"Optimizer Packages" => [
26+
"Optimizer Packages" => [
2727
"BlackBoxOptim.jl" => "optimization_packages/blackboxoptim.md",
2828
"CMAEvolutionStrategy.jl" => "optimization_packages/cmaevolutionstrategy.md",
2929
"Evolutionary.jl" => "optimization_packages/evolutionary.md",
@@ -40,7 +40,9 @@ pages = ["index.md",
4040
"Optimization.jl" => "optimization_packages/optimization.md",
4141
"Polyalgorithms.jl" => "optimization_packages/polyopt.md",
4242
"PRIMA.jl" => "optimization_packages/prima.md",
43+
"PyCMA.jl" => "optimization_packages/pycma.md",
4344
"QuadDIRECT.jl" => "optimization_packages/quaddirect.md",
44-
"SpeedMapping.jl" => "optimization_packages/speedmapping.md"
45+
"SpeedMapping.jl" => "optimization_packages/speedmapping.md",
46+
"SciPy.jl" => "optimization_packages/scipy.md"
4547
]
4648
]

docs/src/API/modelingtoolkit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Secondly, one can generate `OptimizationProblem`s for use in
1616
Optimization.jl from purely a symbolic front-end. This is the form
1717
users will encounter when using ModelingToolkit.jl directly, and it is
1818
also the form supplied by domain-specific languages. For more information,
19-
see the [OptimizationSystem documentation](https://docs.sciml.ai/ModelingToolkit/stable/systems/OptimizationSystem/).
19+
see the [OptimizationSystem documentation](https://docs.sciml.ai/ModelingToolkit/stable/API/problems/#SciMLBase.OptimizationProblem).
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# PyCMA.jl
2+
3+
[`PyCMA`](https://github.com/CMA-ES/pycma) is a Python implementation of CMA-ES and a few related numerical optimization tools. `OptimizationPyCMA.jl` gives access to the CMA-ES optimizer through the unified `Optimization.jl` interface just like any native Julia optimizer.
4+
5+
`OptimizationPyCMA.jl` relies on [`PythonCall`](https://github.com/cjdoris/PythonCall.jl). A minimal Python distribution containing PyCMA will be installed automatically on first use, so no manual Python set-up is required.
6+
7+
## Installation: OptimizationPyCMA.jl
8+
9+
```julia
10+
import Pkg
11+
Pkg.add("OptimizationPyCMA")
12+
```
13+
14+
## Methods
15+
16+
`PyCMAOpt` supports the usual keyword arguments `maxiters`, `maxtime`, `abstol`, `reltol`, `callback` in addition to any PyCMA-specific options (passed verbatim via keyword arguments to `solve`).
17+
18+
## Example
19+
20+
```@example PyCMA
21+
using OptimizationPyCMA
22+
23+
rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
24+
x0 = zeros(2)
25+
_p = [1.0, 100.0]
26+
l1 = rosenbrock(x0, _p)
27+
f = OptimizationFunction(rosenbrock)
28+
prob = OptimizationProblem(f, x0, _p, lb = [-1.0, -1.0], ub = [0.8, 0.8])
29+
sol = solve(prob, PyCMAOpt())
30+
```
31+
32+
## Passing solver-specific options
33+
34+
Any keyword that `Optimization.jl` does not interpret is forwarded directly to PyCMA.
35+
36+
In the event an `Optimization.jl` keyword overlaps with a `PyCMA` keyword, the `Optimization.jl` keyword takes precedence.
37+
38+
An exhaustive list of keyword arguments can be found by running the following python script:
39+
40+
```python
41+
import cma
42+
options = cma.CMAOptions()
43+
print(options)
44+
```
45+
46+
An example passing the `PyCMA` keywords "verbose" and "seed":
47+
```julia
48+
sol = solve(prob, PyCMA(), verbose = -9, seed = 42)
49+
```
50+
51+
## Troubleshooting
52+
53+
The original Python result object is attached to the solution in the `original` field:
54+
55+
```julia
56+
sol = solve(prob, PyCMAOpt())
57+
println(sol.original)
58+
```
59+
60+
## Contributing
61+
62+
Bug reports and feature requests are welcome in the [Optimization.jl](https://github.com/SciML/Optimization.jl) issue tracker. Pull requests that improve either the Julia wrapper or the documentation are highly appreciated.
63+
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# SciPy.jl
2+
3+
[`SciPy`](https://scipy.org/) is a mature Python library that offers a rich family of optimization, root–finding and linear‐programming algorithms. `OptimizationSciPy.jl` gives access to these routines through the unified `Optimization.jl` interface just like any native Julia optimizer.
4+
5+
!!! note
6+
`OptimizationSciPy.jl` relies on [`PythonCall`](https://github.com/cjdoris/PythonCall.jl). A minimal Python distribution containing SciPy will be installed automatically on first use, so no manual Python set-up is required.
7+
8+
## Installation: OptimizationSciPy.jl
9+
10+
```julia
11+
import Pkg
12+
Pkg.add("OptimizationSciPy")
13+
```
14+
15+
## Methods
16+
17+
Below is a catalogue of the solver families exposed by `OptimizationSciPy.jl` together with their convenience constructors. All of them accept the usual keyword arguments `maxiters`, `maxtime`, `abstol`, `reltol`, `callback`, `progress` in addition to any SciPy-specific options (passed verbatim via keyword arguments to `solve`).
18+
19+
### Local Optimizer
20+
21+
#### Derivative-Free
22+
23+
* `ScipyNelderMead()` – Simplex Nelder–Mead algorithm
24+
* `ScipyPowell()` – Powell search along conjugate directions
25+
* `ScipyCOBYLA()` – Linear approximation of constraints (supports nonlinear constraints)
26+
27+
#### Gradient-Based
28+
29+
* `ScipyCG()` – Non-linear conjugate gradient
30+
* `ScipyBFGS()` – Quasi-Newton BFGS
31+
* `ScipyLBFGSB()` – Limited-memory BFGS with simple bounds
32+
* `ScipyNewtonCG()` – Newton-conjugate gradient (requires Hessian-vector products)
33+
* `ScipyTNC()` – Truncated Newton with bounds
34+
* `ScipySLSQP()` – Sequential least-squares programming (supports constraints)
35+
* `ScipyTrustConstr()` – Trust-region method for non-linear constraints
36+
37+
#### Hessian–Based / Trust-Region
38+
39+
* `ScipyDogleg()`, `ScipyTrustNCG()`, `ScipyTrustKrylov()`, `ScipyTrustExact()` – Trust-region algorithms that optionally use or build Hessian information
40+
41+
### Global Optimizer
42+
43+
* `ScipyDifferentialEvolution()` – Differential evolution (requires bounds)
44+
* `ScipyBasinhopping()` – Basin-hopping with local search
45+
* `ScipyDualAnnealing()` – Dual annealing simulated annealing
46+
* `ScipyShgo()` – Simplicial homology global optimisation (supports constraints)
47+
* `ScipyDirect()` – Deterministic `DIRECT` algorithm (requires bounds)
48+
* `ScipyBrute()` – Brute-force grid search (requires bounds)
49+
50+
### Linear & Mixed-Integer Programming
51+
52+
* `ScipyLinprog("highs")` – LP solvers from the HiGHS project and legacy interior-point/simplex methods
53+
* `ScipyMilp()` – Mixed-integer linear programming via HiGHS branch-and-bound
54+
55+
### Root Finding & Non-Linear Least Squares *(experimental)*
56+
57+
Support for `ScipyRoot`, `ScipyRootScalar` and `ScipyLeastSquares` is available behind the scenes and will be documented once the APIs stabilise.
58+
59+
## Examples
60+
61+
### Unconstrained minimisation
62+
63+
```@example SciPy1
64+
using Optimization, OptimizationSciPy
65+
66+
rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
67+
x0 = zeros(2)
68+
p = [1.0, 100.0]
69+
70+
f = OptimizationFunction(rosenbrock, Optimization.AutoZygote())
71+
prob = OptimizationProblem(f, x0, p)
72+
73+
sol = solve(prob, ScipyBFGS())
74+
@show sol.objective # ≈ 0 at optimum
75+
```
76+
77+
### Constrained optimisation with COBYLA
78+
79+
```@example SciPy2
80+
using Optimization, OptimizationSciPy
81+
82+
# Objective
83+
obj(x, p) = (x[1] + x[2] - 1)^2
84+
85+
# Single non-linear constraint: x₁² + x₂² ≈ 1 (with small tolerance)
86+
cons(res, x, p) = (res .= [x[1]^2 + x[2]^2 - 1.0])
87+
88+
x0 = [0.5, 0.5]
89+
prob = OptimizationProblem(
90+
OptimizationFunction(obj; cons = cons),
91+
x0, nothing, lcons = [-1e-6], ucons = [1e-6]) # Small tolerance instead of exact equality
92+
93+
sol = solve(prob, ScipyCOBYLA())
94+
@show sol.u, sol.objective
95+
```
96+
97+
### Differential evolution (global) with custom options
98+
99+
```@example SciPy3
100+
using Optimization, OptimizationSciPy, Random, Statistics
101+
Random.seed!(123)
102+
103+
ackley(x, p) = -20exp(-0.2*sqrt(mean(x .^ 2))) - exp(mean(cos.(2π .* x))) + 20 + ℯ
104+
x0 = zeros(2) # initial guess is ignored by DE
105+
prob = OptimizationProblem(ackley, x0; lb = [-5.0, -5.0], ub = [5.0, 5.0])
106+
107+
sol = solve(prob, ScipyDifferentialEvolution(); popsize = 20, mutation = (0.5, 1))
108+
@show sol.objective
109+
```
110+
111+
## Passing solver-specific options
112+
113+
Any keyword that `Optimization.jl` does not interpret is forwarded directly to SciPy. Refer to the [SciPy optimisation API](https://docs.scipy.org/doc/scipy/reference/optimize.html) for the exhaustive list of options.
114+
115+
```julia
116+
sol = solve(prob, ScipyTrustConstr(); verbose = 3, maxiter = 10_000)
117+
```
118+
119+
## Troubleshooting
120+
121+
The original Python result object is attached to the solution in the `original` field:
122+
123+
```julia
124+
sol = solve(prob, ScipyBFGS())
125+
println(sol.original) # SciPy OptimizeResult
126+
```
127+
128+
If SciPy raises an error it is re-thrown as a Julia `ErrorException` carrying the Python message, so look there first.
129+
130+
## Contributing
131+
132+
Bug reports and feature requests are welcome in the [Optimization.jl](https://github.com/SciML/Optimization.jl) issue tracker. Pull requests that improve either the Julia wrapper or the documentation are highly appreciated.
133+

lib/OptimizationMOI/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "OptimizationMOI"
22
uuid = "fd9f6733-72f4-499f-8506-86b2bdd0dea1"
33
authors = ["Vaibhav Dixit <[email protected]> and contributors"]
4-
version = "0.5.4"
4+
version = "0.5.5"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

lib/OptimizationMOI/src/OptimizationMOI.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ using LinearAlgebra
1515

1616
const MOI = MathOptInterface
1717

18-
const DenseOrSparse{T} = Union{Matrix{T}, SparseMatrixCSC{T}}
19-
2018
function SciMLBase.requiresgradient(opt::Union{
2119
MOI.AbstractOptimizer, MOI.OptimizerWithAttributes})
2220
true

lib/OptimizationMOI/src/nlp.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
mutable struct MOIOptimizationNLPEvaluator{T, F <: OptimizationFunction, RC, LB, UB,
2-
I,
3-
JT <: DenseOrSparse{T}, HT <: DenseOrSparse{T},
4-
CHT <: DenseOrSparse{T}, S, CB} <:
2+
I, JT <: AbstractMatrix{T}, HT <: AbstractMatrix{T}, CHT <: AbstractMatrix{T}, S, CB} <:
53
MOI.AbstractNLPEvaluator
64
f::F
75
reinit_cache::RC

lib/OptimizationODE/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1212
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
1313

1414
[compat]
15-
ForwardDiff = "1"
15+
ForwardDiff = "0.10, 1"
1616
Optimization = "4"
17-
OrdinaryDiffEq = "7"
17+
OrdinaryDiffEq = "6.70"
1818
Reexport = "1"
1919
SciMLBase = "2"
2020
SteadyStateDiffEq = "2"

0 commit comments

Comments
 (0)