Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tools/envs/testenv-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
- pytorch-cpu # dev, tests
- pip: # dev, tests, docs
- bayesian-optimization>=2.0.4 # dev, tests
- DFO-LS>=1.5.3 # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-nevergrad.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
- pytorch-cpu # dev, tests
- pip: # dev, tests, docs
- DFO-LS>=1.5.3 # dev, tests
- Py-BOBYQA # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-numpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
- pytorch-cpu # dev, tests
- pip: # dev, tests, docs
- bayesian-optimization>=2.0.4 # dev, tests
- DFO-LS>=1.5.3 # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-others.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
- pytorch-cpu # dev, tests
- pip: # dev, tests, docs
- bayesian-optimization>=2.0.4 # dev, tests
- DFO-LS>=1.5.3 # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-pandas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
- pytorch-cpu # dev, tests
- pip: # dev, tests, docs
- bayesian-optimization>=2.0.4 # dev, tests
- DFO-LS>=1.5.3 # dev, tests
Expand Down
1 change: 1 addition & 0 deletions .tools/envs/testenv-plotly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
- pytorch-cpu # dev, tests
- pip: # dev, tests, docs
- bayesian-optimization>=2.0.4 # dev, tests
- DFO-LS>=1.5.3 # dev, tests
Expand Down
2 changes: 1 addition & 1 deletion docs/source/how_to/how_to_constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ full parameter vector and returns the subset of parameters that should be constr
This yields the same solution as an unconstrained estimation because the constraint
is not binding:

>>> res.params.round(3)
>>> res.params.round(3) # doctest: +SKIP
array([ 1. , 0.8, 0.6, 0.4, 0.2, -0. ])

We can now use one of optimagic's utility functions to actually build the standard
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies:
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
- pytorch-cpu # dev, tests
- pip: # dev, tests, docs
- bayesian-optimization>=2.0.4 # dev, tests
# - nevergrad # incompatible with bayesian-optimization>=2.0.4
Expand Down
2 changes: 1 addition & 1 deletion src/optimagic/optimization/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def params_data(
"""
wide = pd.DataFrame(self.flat_params, columns=self.flat_param_names)
wide["task"] = _task_to_categorical(self.task)
wide["fun"] = self.fun
wide["fun"] = self.fun # type: ignore[assignment]

# If requested, we collapse the batches and only keep the parameters that led to
# the minimal (or maximal) function value in each batch.
Expand Down
2 changes: 1 addition & 1 deletion src/optimagic/visualization/slice_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _get_plot_data(
metadata.append(meta)

plot_data = pd.DataFrame(metadata)
plot_data["Function Value"] = func_values
plot_data["Function Value"] = func_values # type: ignore[assignment]

return plot_data, internal_params

Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pytest
import statsmodels.api as sm

from optimagic.config import IS_MATPLOTLIB_INSTALLED


@pytest.fixture(autouse=True)
def fresh_directory(tmp_path): # noqa: PT004
Expand All @@ -30,3 +32,13 @@ def logit_object():
spector_data.exog = sm.add_constant(spector_data.exog)
logit_mod = sm.Logit(spector_data.endog, spector_data.exog)
return logit_mod


@pytest.fixture()
def close_mpl_figures():
"""Close all matplotlib figures after test execution."""
yield
if IS_MATPLOTLIB_INSTALLED:
import matplotlib.pyplot as plt

plt.close("all")
4 changes: 4 additions & 0 deletions tests/optimagic/optimizers/test_pounders_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def trustregion_subproblem_options():


@pytest.mark.skipif(sys.platform == "win32", reason="Not accurate on Windows.")
@pytest.mark.skipif(
sys.platform == "linux" and sys.version_info[:2] == (3, 10),
reason="Not accurate on Linux with Python 3.10.",
)
@pytest.mark.parametrize("start_vec, conjugate_gradient_method_sub", TEST_CASES)
def test_bntr(
start_vec,
Expand Down
2 changes: 1 addition & 1 deletion tests/optimagic/visualization/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def sample_lines():


@pytest.mark.parametrize("backend", BACKEND_AVAILABILITY_AND_LINE_PLOT_FUNCTION.keys())
def test_line_plot_all_backends(sample_lines, backend):
def test_line_plot_all_backends(sample_lines, backend, close_mpl_figures):
line_plot(sample_lines, backend=backend)


Expand Down
2 changes: 1 addition & 1 deletion tests/optimagic/visualization/test_convergence_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_convergence_plot_default_options(benchmark_results):

@pytest.mark.parametrize("options", profile_options)
@pytest.mark.parametrize("grid", [True, False])
def test_convergence_plot_options(options, grid, benchmark_results):
def test_convergence_plot_options(options, grid, benchmark_results, close_mpl_figures):
problems, results = benchmark_results

convergence_plot(
Expand Down
4 changes: 2 additions & 2 deletions tests/optimagic/visualization/test_history_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ def test_criterion_plot_wrong_inputs():


@pytest.mark.parametrize("backend", BACKEND_AVAILABILITY_AND_LINE_PLOT_FUNCTION.keys())
def test_criterion_plot_different_backends(minimize_result, backend):
def test_criterion_plot_different_backends(minimize_result, backend, close_mpl_figures):
res = minimize_result[False][0]
criterion_plot(res, backend=backend)


@pytest.mark.parametrize("backend", BACKEND_AVAILABILITY_AND_LINE_PLOT_FUNCTION.keys())
def test_params_plot_different_backends(minimize_result, backend):
def test_params_plot_different_backends(minimize_result, backend, close_mpl_figures):
res = minimize_result[False][0]
params_plot(res, backend=backend)

Expand Down
2 changes: 1 addition & 1 deletion tests/optimagic/visualization/test_profile_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_extract_profile_plot_lines():


@pytest.mark.parametrize("options", profile_options)
def test_profile_plot_options(options):
def test_profile_plot_options(options, close_mpl_figures):
problems = get_benchmark_problems("example")
stop_after_10 = {
"stopping_max_criterion_evaluations": 10,
Expand Down
2 changes: 1 addition & 1 deletion tests/optimagic/visualization/test_slice_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def sphere(params):

@pytest.mark.parametrize("backend", BACKEND_AVAILABILITY_AND_LINE_PLOT_FUNCTION.keys())
@pytest.mark.parametrize("func, kwargs", parametrization)
def test_slice_plot(fixed_inputs, func, backend, kwargs):
def test_slice_plot(fixed_inputs, func, backend, kwargs, close_mpl_figures):
slice_plot(
func=func,
backend=backend,
Expand Down
Loading