Skip to content

Commit e5463a8

Browse files
authored
Merge branch 'main' into gradient_free_optimizers
2 parents 271b049 + 10a0711 commit e5463a8

25 files changed

+2053
-329
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
- id: check-useless-excludes
77
# - id: identity # Prints all files passed to pre-commits. Debugging.
88
- repo: https://github.com/lyz-code/yamlfix
9-
rev: 1.17.0
9+
rev: 1.18.0
1010
hooks:
1111
- id: yamlfix
1212
exclude: tests/optimagic/optimizers/_pounders/fixtures
@@ -89,7 +89,7 @@ repos:
8989
- --blank
9090
exclude: src/optimagic/optimization/algo_options.py
9191
- repo: https://github.com/astral-sh/ruff-pre-commit
92-
rev: v0.12.11
92+
rev: v0.13.3
9393
hooks:
9494
# Run the linter.
9595
- id: ruff

.tools/envs/testenv-linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies:
3939
- kaleido>=1.0 # dev, tests
4040
- bayes_optim # dev, tests
4141
- gradient_free_optimizers # dev, tests
42+
- pyswarms # dev, tests
4243
- pandas-stubs # dev, tests
4344
- types-cffi # dev, tests
4445
- types-openpyxl # dev, tests

.tools/envs/testenv-nevergrad.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ dependencies:
3636
- kaleido>=1.0 # dev, tests
3737
- bayes_optim # dev, tests
3838
- gradient_free_optimizers # dev, tests
39+
- pyswarms # dev, tests
3940
- pandas-stubs # dev, tests
4041
- types-cffi # dev, tests
4142
- types-openpyxl # dev, tests
4243
- types-jinja2 # dev, tests
4344
- sqlalchemy-stubs # dev, tests
44-
- sphinxcontrib-mermaid # dev, tests, docs
4545
- bayesian_optimization==1.4.0
4646
- nevergrad
47+
- sphinxcontrib-mermaid # dev, tests, docs
4748
- -e ../../

.tools/envs/testenv-numpy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies:
3737
- kaleido>=1.0 # dev, tests
3838
- bayes_optim # dev, tests
3939
- gradient_free_optimizers # dev, tests
40+
- pyswarms # dev, tests
4041
- types-cffi # dev, tests
4142
- types-openpyxl # dev, tests
4243
- types-jinja2 # dev, tests

.tools/envs/testenv-others.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies:
3737
- kaleido>=1.0 # dev, tests
3838
- bayes_optim # dev, tests
3939
- gradient_free_optimizers # dev, tests
40+
- pyswarms # dev, tests
4041
- pandas-stubs # dev, tests
4142
- types-cffi # dev, tests
4243
- types-openpyxl # dev, tests

.tools/envs/testenv-pandas.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies:
3737
- kaleido>=1.0 # dev, tests
3838
- bayes_optim # dev, tests
3939
- gradient_free_optimizers # dev, tests
40+
- pyswarms # dev, tests
4041
- types-cffi # dev, tests
4142
- types-openpyxl # dev, tests
4243
- types-jinja2 # dev, tests

.tools/envs/testenv-plotly.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ dependencies:
3636
- fides==0.7.4 # dev, tests
3737
- bayes_optim # dev, tests
3838
- gradient_free_optimizers # dev, tests
39+
- pyswarms # dev, tests
3940
- pandas-stubs # dev, tests
4041
- types-cffi # dev, tests
4142
- types-openpyxl # dev, tests
4243
- types-jinja2 # dev, tests
4344
- sqlalchemy-stubs # dev, tests
44-
- sphinxcontrib-mermaid # dev, tests, docs
4545
- kaleido<0.3
46+
- sphinxcontrib-mermaid # dev, tests, docs
4647
- -e ../../

docs/source/algorithms.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5125,6 +5125,107 @@ We wrap the pygad optimizer. To use it you need to have
51255125
.. autoclass:: optimagic.optimizers.pygad_optimizer.Pygad
51265126
```
51275127

5128+
## PySwarms Optimizers
5129+
5130+
optimagic supports the following continuous algorithms from the
5131+
[PySwarms](https://pyswarms.readthedocs.io/en/latest/) library: (GlobalBestPSO,
5132+
LocalBestPSO, GeneralOptimizerPSO). To use these optimizers, you need to have
5133+
[the pyswarms package](https://github.com/ljvmiranda921/pyswarms) installed.
5134+
(`pip install pyswarms`).
5135+
5136+
```{eval-rst}
5137+
.. dropdown:: pyswarms_global_best
5138+
5139+
**How to use this algorithm:**
5140+
5141+
.. code-block::
5142+
5143+
import optimagic as om
5144+
om.minimize(
5145+
...,
5146+
algorithm=om.algos.pyswarms_global_best(n_particles=50, ...)
5147+
)
5148+
5149+
or
5150+
5151+
.. code-block::
5152+
5153+
om.minimize(
5154+
...,
5155+
algorithm="pyswarms_global_best",
5156+
algo_options={"n_particles": 50, ...}
5157+
)
5158+
5159+
**Description and available options:**
5160+
5161+
.. autoclass:: optimagic.optimizers.pyswarms_optimizers.PySwarmsGlobalBestPSO
5162+
:members:
5163+
:inherited-members: Algorithm, object
5164+
5165+
```
5166+
5167+
```{eval-rst}
5168+
.. dropdown:: pyswarms_local_best
5169+
5170+
**How to use this algorithm:**
5171+
5172+
.. code-block::
5173+
5174+
import optimagic as om
5175+
om.minimize(
5176+
...,
5177+
algorithm=om.algos.pyswarms_local_best(n_particles=50, k_neighbors=3, ...)
5178+
)
5179+
5180+
or
5181+
5182+
.. code-block::
5183+
5184+
om.minimize(
5185+
...,
5186+
algorithm="pyswarms_local_best",
5187+
algo_options={"n_particles": 50, "k_neighbors": 3, ...}
5188+
)
5189+
5190+
**Description and available options:**
5191+
5192+
.. autoclass:: optimagic.optimizers.pyswarms_optimizers.PySwarmsLocalBestPSO
5193+
:members:
5194+
:inherited-members: Algorithm, object
5195+
5196+
```
5197+
5198+
```{eval-rst}
5199+
.. dropdown:: pyswarms_general
5200+
5201+
**How to use this algorithm:**
5202+
5203+
.. code-block::
5204+
5205+
import optimagic as om
5206+
om.minimize(
5207+
...,
5208+
algorithm=om.algos.pyswarms_general(n_particles=50, topology_type="star", ...)
5209+
)
5210+
5211+
or
5212+
5213+
.. code-block::
5214+
5215+
om.minimize(
5216+
...,
5217+
algorithm="pyswarms_general",
5218+
algo_options={"n_particles": 50, "topology_type": "star", ...}
5219+
)
5220+
5221+
**Description and available options:**
5222+
5223+
.. autoclass:: optimagic.optimizers.pyswarms_optimizers.PySwarmsGeneralPSO
5224+
:members:
5225+
:inherited-members: Algorithm, object
5226+
5227+
```
5228+
51285229
## References
51295230

51305231
```{eval-rst}

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
nb_execution_mode = "force" # "off", "force", "cache", "auto"
174174
nb_execution_allow_errors = False
175175
nb_merge_streams = True
176+
nb_scroll_outputs = True
176177

177178
# Notebook cell execution timeout; defaults to 30.
178179
nb_execution_timeout = 1000

docs/source/how_to/how_to_benchmarking.ipynb

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@
135135
"cell_type": "markdown",
136136
"id": "10",
137137
"metadata": {},
138+
"source": [
139+
":::{note}\n",
140+
"\n",
141+
"For details on using other plotting backends, see [How to change the plotting backend](how_to_change_plotting_backend.ipynb).\n",
142+
"\n",
143+
":::"
144+
]
145+
},
146+
{
147+
"cell_type": "markdown",
148+
"id": "11",
149+
"metadata": {},
138150
"source": [
139151
"The x axis shows runtime per problem. The y axis shows the share of problems each algorithm solved within that runtime. Thus, higher and further to the left values are desirable. Higher means more problems were solved and further to the left means, the algorithm found the solutions earlier. \n",
140152
"\n",
@@ -150,7 +162,7 @@
150162
{
151163
"cell_type": "code",
152164
"execution_count": null,
153-
"id": "11",
165+
"id": "12",
154166
"metadata": {},
155167
"outputs": [],
156168
"source": [
@@ -167,7 +179,7 @@
167179
},
168180
{
169181
"cell_type": "markdown",
170-
"id": "12",
182+
"id": "13",
171183
"metadata": {},
172184
"source": [
173185
"## 4b. Convergence plots\n",
@@ -178,7 +190,7 @@
178190
{
179191
"cell_type": "code",
180192
"execution_count": null,
181-
"id": "13",
193+
"id": "14",
182194
"metadata": {},
183195
"outputs": [],
184196
"source": [
@@ -194,7 +206,7 @@
194206
},
195207
{
196208
"cell_type": "markdown",
197-
"id": "14",
209+
"id": "15",
198210
"metadata": {},
199211
"source": [
200212
"The further to the left and the lower the curve of an algorithm, the better that algorithm performed.\n",
@@ -205,7 +217,7 @@
205217
{
206218
"cell_type": "code",
207219
"execution_count": null,
208-
"id": "15",
220+
"id": "16",
209221
"metadata": {},
210222
"outputs": [],
211223
"source": [
@@ -223,7 +235,7 @@
223235
},
224236
{
225237
"cell_type": "markdown",
226-
"id": "16",
238+
"id": "17",
227239
"metadata": {},
228240
"source": [
229241
"## 5a. Convergence report\n",
@@ -235,7 +247,7 @@
235247
{
236248
"cell_type": "code",
237249
"execution_count": null,
238-
"id": "17",
250+
"id": "18",
239251
"metadata": {},
240252
"outputs": [],
241253
"source": [
@@ -251,7 +263,7 @@
251263
{
252264
"cell_type": "code",
253265
"execution_count": null,
254-
"id": "18",
266+
"id": "19",
255267
"metadata": {},
256268
"outputs": [],
257269
"source": [
@@ -260,18 +272,18 @@
260272
},
261273
{
262274
"cell_type": "markdown",
263-
"id": "19",
275+
"id": "20",
264276
"metadata": {},
265277
"source": [
266-
"## 5b. Rank report\n",
278+
"## 5b. Rank report\n",
267279
"\n",
268280
"The **Rank Report** shows the ranks of the algorithms for each problem; where 0 means the algorithm was the fastest on a given benchmark problem, 1 means it was the second fastest and so on. If an algorithm did not converge on a problem, the value is \"failed\". If an algorithm did encounter an error during optimization, the value is \"error\"."
269281
]
270282
},
271283
{
272284
"cell_type": "code",
273285
"execution_count": null,
274-
"id": "20",
286+
"id": "21",
275287
"metadata": {},
276288
"outputs": [],
277289
"source": [
@@ -288,7 +300,7 @@
288300
{
289301
"cell_type": "code",
290302
"execution_count": null,
291-
"id": "21",
303+
"id": "22",
292304
"metadata": {},
293305
"outputs": [],
294306
"source": [
@@ -297,18 +309,18 @@
297309
},
298310
{
299311
"cell_type": "markdown",
300-
"id": "22",
312+
"id": "23",
301313
"metadata": {},
302314
"source": [
303-
"## 5b. Traceback report\n",
315+
"## 5b. Traceback report\n",
304316
"\n",
305317
"The **Traceback Report** shows the tracebacks returned by the optimizers if they encountered an error during optimization. The resulting ```pd.DataFrame``` is empty if none of the optimizers terminated with an error, as in the example below."
306318
]
307319
},
308320
{
309321
"cell_type": "code",
310322
"execution_count": null,
311-
"id": "23",
323+
"id": "24",
312324
"metadata": {},
313325
"outputs": [],
314326
"source": [
@@ -318,7 +330,7 @@
318330
{
319331
"cell_type": "code",
320332
"execution_count": null,
321-
"id": "24",
333+
"id": "25",
322334
"metadata": {},
323335
"outputs": [],
324336
"source": [

0 commit comments

Comments
 (0)