Skip to content

Commit b0f7a8e

Browse files
authored
Implementation of matplotlib backend for criterion_plot() (#599)
1 parent 383fc19 commit b0f7a8e

File tree

15 files changed

+323
-104
lines changed

15 files changed

+323
-104
lines changed

.tools/envs/testenv-linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies:
1919
- numpy >= 2 # run, tests
2020
- pandas # run, tests
2121
- plotly>=6.2 # run, tests
22+
- matplotlib # tests
2223
- pybaum>=0.1.2 # run, tests
2324
- scipy>=1.2.1 # run, tests
2425
- sqlalchemy # run, tests

.tools/envs/testenv-nevergrad.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
- numpy >= 2 # run, tests
1818
- pandas # run, tests
1919
- plotly>=6.2 # run, tests
20+
- matplotlib # tests
2021
- pybaum>=0.1.2 # run, tests
2122
- scipy>=1.2.1 # run, tests
2223
- sqlalchemy # run, tests

.tools/envs/testenv-numpy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
- cloudpickle # run, tests
1818
- joblib # run, tests
1919
- plotly>=6.2 # run, tests
20+
- matplotlib # tests
2021
- pybaum>=0.1.2 # run, tests
2122
- scipy>=1.2.1 # run, tests
2223
- sqlalchemy # run, tests

.tools/envs/testenv-others.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
- numpy >= 2 # run, tests
1818
- pandas # run, tests
1919
- plotly>=6.2 # run, tests
20+
- matplotlib # tests
2021
- pybaum>=0.1.2 # run, tests
2122
- scipy>=1.2.1 # run, tests
2223
- sqlalchemy # run, tests

.tools/envs/testenv-pandas.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
- cloudpickle # run, tests
1818
- joblib # run, tests
1919
- plotly>=6.2 # run, tests
20+
- matplotlib # tests
2021
- pybaum>=0.1.2 # run, tests
2122
- scipy>=1.2.1 # run, tests
2223
- sqlalchemy # run, tests

.tools/envs/testenv-plotly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies:
1717
- joblib # run, tests
1818
- numpy >= 2 # run, tests
1919
- pandas # run, tests
20+
- matplotlib # tests
2021
- pybaum>=0.1.2 # run, tests
2122
- scipy>=1.2.1 # run, tests
2223
- sqlalchemy # run, tests

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies:
2121
- numpy >= 2 # run, tests
2222
- pandas # run, tests
2323
- plotly>=6.2 # run, tests
24+
- matplotlib # tests
2425
- pybaum>=0.1.2 # run, tests
2526
- scipy>=1.2.1 # run, tests
2627
- sqlalchemy # run, tests

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ module = [
290290

291291
"optimagic.visualization",
292292
"optimagic.visualization.convergence_plot",
293+
"optimagic.visualization.backends",
293294
"optimagic.visualization.deviation_plot",
294295
"optimagic.visualization.history_plots",
295296
"optimagic.visualization.plotting_utilities",
@@ -346,6 +347,8 @@ module = [
346347
"plotly.graph_objects",
347348
"plotly.express",
348349
"plotly.subplots",
350+
"matplotlib",
351+
"matplotlib.pyplot",
349352
"cyipopt",
350353
"nlopt",
351354
"bokeh",

src/optimagic/config.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
PLOTLY_TEMPLATE = "simple_white"
1212
PLOTLY_PALETTE = px.colors.qualitative.Set2
1313

14+
# The hex strings are obtained from the Plotly D3 qualitative palette.
15+
DEFAULT_PALETTE = [
16+
"#1F77B4",
17+
"#FF7F0E",
18+
"#2CA02C",
19+
"#D62728",
20+
"#9467BD",
21+
"#8C564B",
22+
"#E377C2",
23+
"#7F7F7F",
24+
"#BCBD22",
25+
"#17BECF",
26+
]
27+
1428
DEFAULT_N_CORES = 1
1529

1630
CRITERION_PENALTY_SLOPE = 0.1
@@ -23,7 +37,7 @@ def _is_installed(module_name: str) -> bool:
2337

2438

2539
# ======================================================================================
26-
# Check Available Packages
40+
# Check Available Optimization Packages
2741
# ======================================================================================
2842

2943
IS_PETSC4PY_INSTALLED = _is_installed("petsc4py")
@@ -42,6 +56,12 @@ def _is_installed(module_name: str) -> bool:
4256
IS_GRADIENT_FREE_OPTIMIZERS_INSTALLED = _is_installed("gradient_free_optimizers")
4357
IS_PYGAD_INSTALLED = _is_installed("pygad")
4458

59+
# ======================================================================================
60+
# Check Available Visualization Packages
61+
# ======================================================================================
62+
63+
IS_MATPLOTLIB_INSTALLED = _is_installed("matplotlib")
64+
4565

4666
# ======================================================================================
4767
# Check if pandas version is newer or equal to version 2.1.0

src/optimagic/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class InvalidAlgoInfoError(OptimagicError):
7979
"""Exception for invalid user provided algorithm information."""
8080

8181

82+
class InvalidPlottingBackendError(OptimagicError):
83+
"""Exception for invalid user provided plotting backend."""
84+
85+
8286
class StopOptimizationError(OptimagicError):
8387
def __init__(self, message, current_status):
8488
super().__init__(message)

0 commit comments

Comments
 (0)