Skip to content

Commit 5e359d1

Browse files
Merge branch 'SciML:master' into daenew
2 parents 526a8a9 + ca06e9a commit 5e359d1

File tree

18 files changed

+2466
-7
lines changed

18 files changed

+2466
-7
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/OptimizationODE/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
1616
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
1717

1818
[compat]
19-
ForwardDiff = "1"
19+
ForwardDiff = "0.10, 1"
2020
Optimization = "4"
21-
OrdinaryDiffEq = "7"
21+
OrdinaryDiffEq = "6.70"
2222
Reexport = "1"
2323
SciMLBase = "2"
2424
SteadyStateDiffEq = "2"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
matplotlib = ""
3+
cma = ""

lib/OptimizationPyCMA/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Julia Computing, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

lib/OptimizationPyCMA/Project.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name = "OptimizationPyCMA"
2+
uuid = "fb0822aa-1fe5-41d8-99a6-e7bf6c238d3b"
3+
authors = ["Maximilian Pochapski <[email protected]>"]
4+
version = "1.0.0"
5+
6+
[deps]
7+
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
8+
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
9+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
10+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
11+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
12+
13+
[compat]
14+
CondaPkg = "0.2.29"
15+
Optimization = "4.4.0"
16+
PythonCall = "0.9.25"
17+
Reexport = "1.2.2"
18+
Test = "1.10.0"
19+
julia = "1.10"

0 commit comments

Comments
 (0)