Skip to content
Open
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 @@ -30,6 +30,7 @@ dependencies:
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
- tranquilo>=0.1.0 # tests
- iminuit # dev, tests
- cma # dev, tests
- pygad # 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 @@ -28,6 +28,7 @@ dependencies:
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
- tranquilo>=0.1.0 # tests
- iminuit # dev, tests
- cma # dev, tests
- pygad # 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 @@ -28,6 +28,7 @@ dependencies:
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
- tranquilo>=0.1.0 # tests
- iminuit # dev, tests
- cma # dev, tests
- pygad # 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 @@ -28,6 +28,7 @@ dependencies:
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
- tranquilo>=0.1.0 # tests
- iminuit # dev, tests
- cma # dev, tests
- pygad # 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 @@ -28,6 +28,7 @@ dependencies:
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
- tranquilo>=0.1.0 # tests
- iminuit # dev, tests
- cma # dev, tests
- pygad # 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 @@ -28,6 +28,7 @@ dependencies:
- pyyaml # dev, tests
- jinja2 # dev, tests
- annotated-types # dev, tests
- tranquilo>=0.1.0 # tests
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
Expand Down
3 changes: 0 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ coverage:
default:
target: 90%
ignore:
- setup.py
# Uses numba
- src/optimagic/benchmarking/cartis_roberts.py
# not installed on CI
- src/optimagic/optimizers/tranquilo.py
- tests/**/*
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies:
- jinja2 # dev, tests
- furo # dev, docs
- annotated-types # dev, tests
- tranquilo>=0.1.0 # tests
- iminuit # dev, tests
- cma # dev, tests
- pygad # dev, tests
Expand Down
41 changes: 23 additions & 18 deletions src/optimagic/optimizers/tranquilo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
from numpy.typing import NDArray
from packaging import version

from optimagic import mark
from optimagic.config import IS_TRANQUILO_INSTALLED
Expand Down Expand Up @@ -34,6 +35,20 @@
VarianceEstimatorOptions,
)

if IS_TRANQUILO_INSTALLED:
import tranquilo

IS_TRANQUILO_VERSION_NEWER_OR_EQUAL_TO_0_1_0 = version.parse(
tranquilo.__version__
) >= version.parse("0.1.0")
else:
IS_TRANQUILO_VERSION_NEWER_OR_EQUAL_TO_0_1_0 = False

TRANQUILO_INSTALLATION_INSTRUCTIONS = (
"The 'tranquilo' algorithm requires the tranquilo package version 0.1.0 or newer "
"to be installed. Install it with 'conda -c conda-forge install tranquilo>=0.1.0'."
)


@mark.minimizer(
name="tranquilo",
Expand All @@ -48,7 +63,7 @@
supports_infinite_bounds=True,
supports_linear_constraints=False,
supports_nonlinear_constraints=False,
disable_history=True,
disable_history=False,
)
@dataclass(frozen=True)
class Tranquilo(Algorithm):
Expand Down Expand Up @@ -164,17 +179,13 @@ class Tranquilo(Algorithm):
def _solve_internal_problem(
self, problem: InternalOptimizationProblem, x0: NDArray[np.float64]
) -> InternalOptimizeResult:
if not IS_TRANQUILO_INSTALLED:
raise NotInstalledError(
"The 'tranquilo-ls' algorithm requires the tranquilo package "
"to be installed. You can install it with "
"'conda install -c conda-forge tranquilo'."
)
if not IS_TRANQUILO_VERSION_NEWER_OR_EQUAL_TO_0_1_0:
raise NotInstalledError(TRANQUILO_INSTALLATION_INSTRUCTIONS)
from tranquilo.tranquilo import _tranquilo

raw_res = _tranquilo(
functype="scalar",
criterion=problem.fun,
batch_fun=problem.batch_fun,
x=x0,
lower_bounds=problem.bounds.lower,
upper_bounds=problem.bounds.upper,
Expand All @@ -190,7 +201,6 @@ def _solve_internal_problem(
stopping_max_criterion_evaluations=self.stopping_maxfun,
stopping_max_iterations=self.stopping_maxiter,
stopping_max_time=self.stopping_maxtime,
batch_evaluator=self.batch_evaluator,
n_cores=self.n_cores,
batch_size=self.batch_size,
sample_size=self.sample_size,
Expand Down Expand Up @@ -242,7 +252,7 @@ def _solve_internal_problem(
supports_infinite_bounds=True,
supports_linear_constraints=False,
supports_nonlinear_constraints=False,
disable_history=True,
disable_history=False,
)
@dataclass(frozen=True)
class TranquiloLS(Algorithm):
Expand Down Expand Up @@ -356,17 +366,13 @@ class TranquiloLS(Algorithm):
def _solve_internal_problem(
self, problem: InternalOptimizationProblem, x0: NDArray[np.float64]
) -> InternalOptimizeResult:
if not IS_TRANQUILO_INSTALLED:
raise NotInstalledError(
"The 'tranquilo-ls' algorithm requires the tranquilo package "
"to be installed. You can install it with "
"'conda install -c conda-forge tranquilo'."
)
if not IS_TRANQUILO_VERSION_NEWER_OR_EQUAL_TO_0_1_0:
raise NotInstalledError(TRANQUILO_INSTALLATION_INSTRUCTIONS)
from tranquilo.tranquilo import _tranquilo

raw_res = _tranquilo(
functype="least_squares",
criterion=problem.fun,
batch_fun=problem.batch_fun,
x=x0,
lower_bounds=problem.bounds.lower,
upper_bounds=problem.bounds.upper,
Expand All @@ -382,7 +388,6 @@ def _solve_internal_problem(
stopping_max_criterion_evaluations=self.stopping_maxfun,
stopping_max_iterations=self.stopping_maxiter,
stopping_max_time=self.stopping_maxtime,
batch_evaluator=self.batch_evaluator,
n_cores=self.n_cores,
batch_size=self.batch_size,
sample_size=self.sample_size,
Expand Down
Loading