Skip to content

Commit c6565c6

Browse files
committed
Adjust for new tranquilo version and clean up
1 parent e1558ae commit c6565c6

9 files changed

Lines changed: 30 additions & 21 deletions

File tree

.tools/envs/testenv-linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dependencies:
3030
- pyyaml # dev, tests
3131
- jinja2 # dev, tests
3232
- annotated-types # dev, tests
33+
- tranquilo>=0.1.0 # tests
3334
- iminuit # dev, tests
3435
- cma # dev, tests
3536
- pygad # dev, tests

.tools/envs/testenv-nevergrad.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies:
2828
- pyyaml # dev, tests
2929
- jinja2 # dev, tests
3030
- annotated-types # dev, tests
31+
- tranquilo>=0.1.0 # tests
3132
- iminuit # dev, tests
3233
- cma # dev, tests
3334
- pygad # dev, tests

.tools/envs/testenv-numpy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies:
2828
- pyyaml # dev, tests
2929
- jinja2 # dev, tests
3030
- annotated-types # dev, tests
31+
- tranquilo>=0.1.0 # tests
3132
- iminuit # dev, tests
3233
- cma # dev, tests
3334
- pygad # dev, tests

.tools/envs/testenv-others.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies:
2828
- pyyaml # dev, tests
2929
- jinja2 # dev, tests
3030
- annotated-types # dev, tests
31+
- tranquilo>=0.1.0 # tests
3132
- iminuit # dev, tests
3233
- cma # dev, tests
3334
- pygad # dev, tests

.tools/envs/testenv-pandas.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies:
2828
- pyyaml # dev, tests
2929
- jinja2 # dev, tests
3030
- annotated-types # dev, tests
31+
- tranquilo>=0.1.0 # tests
3132
- iminuit # dev, tests
3233
- cma # dev, tests
3334
- pygad # dev, tests

.tools/envs/testenv-plotly.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies:
2828
- pyyaml # dev, tests
2929
- jinja2 # dev, tests
3030
- annotated-types # dev, tests
31+
- tranquilo>=0.1.0 # tests
3132
- iminuit # dev, tests
3233
- cma # dev, tests
3334
- pygad # dev, tests

codecov.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ coverage:
1414
default:
1515
target: 90%
1616
ignore:
17-
- setup.py
1817
# Uses numba
1918
- src/optimagic/benchmarking/cartis_roberts.py
20-
# not installed on CI
21-
- src/optimagic/optimizers/tranquilo.py
2219
- tests/**/*

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dependencies:
4040
- jinja2 # dev, tests
4141
- furo # dev, docs
4242
- annotated-types # dev, tests
43+
- tranquilo>=0.1.0 # tests
4344
- iminuit # dev, tests
4445
- cma # dev, tests
4546
- pygad # dev, tests

src/optimagic/optimizers/tranquilo.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import numpy as np
77
from numpy.typing import NDArray
8+
from packaging import version
89

910
from optimagic import mark
1011
from optimagic.config import IS_TRANQUILO_INSTALLED
@@ -34,6 +35,20 @@
3435
VarianceEstimatorOptions,
3536
)
3637

38+
if IS_TRANQUILO_INSTALLED:
39+
import tranquilo
40+
41+
IS_TRANQUILO_VERSION_NEWER_OR_EQUAL_TO_0_1_0 = version.parse(
42+
tranquilo.__version__
43+
) >= version.parse("0.1.0")
44+
else:
45+
IS_TRANQUILO_VERSION_NEWER_OR_EQUAL_TO_0_1_0 = False
46+
47+
TRANQUILO_INSTALLATION_INSTRUCTIONS = (
48+
"The 'tranquilo' algorithm requires the tranquilo package version 0.1.0 or newer "
49+
"to be installed. Install it with 'conda -c conda-forge install tranquilo>=0.1.0'."
50+
)
51+
3752

3853
@mark.minimizer(
3954
name="tranquilo",
@@ -48,7 +63,7 @@
4863
supports_infinite_bounds=True,
4964
supports_linear_constraints=False,
5065
supports_nonlinear_constraints=False,
51-
disable_history=True,
66+
disable_history=False,
5267
)
5368
@dataclass(frozen=True)
5469
class Tranquilo(Algorithm):
@@ -164,17 +179,13 @@ class Tranquilo(Algorithm):
164179
def _solve_internal_problem(
165180
self, problem: InternalOptimizationProblem, x0: NDArray[np.float64]
166181
) -> InternalOptimizeResult:
167-
if not IS_TRANQUILO_INSTALLED:
168-
raise NotInstalledError(
169-
"The 'tranquilo-ls' algorithm requires the tranquilo package "
170-
"to be installed. You can install it with "
171-
"'conda install -c conda-forge tranquilo'."
172-
)
182+
if not IS_TRANQUILO_VERSION_NEWER_OR_EQUAL_TO_0_1_0:
183+
raise NotInstalledError(TRANQUILO_INSTALLATION_INSTRUCTIONS)
173184
from tranquilo.tranquilo import _tranquilo
174185

175186
raw_res = _tranquilo(
176187
functype="scalar",
177-
criterion=problem.fun,
188+
batch_fun=problem.batch_fun,
178189
x=x0,
179190
lower_bounds=problem.bounds.lower,
180191
upper_bounds=problem.bounds.upper,
@@ -190,7 +201,6 @@ def _solve_internal_problem(
190201
stopping_max_criterion_evaluations=self.stopping_maxfun,
191202
stopping_max_iterations=self.stopping_maxiter,
192203
stopping_max_time=self.stopping_maxtime,
193-
batch_evaluator=self.batch_evaluator,
194204
n_cores=self.n_cores,
195205
batch_size=self.batch_size,
196206
sample_size=self.sample_size,
@@ -242,7 +252,7 @@ def _solve_internal_problem(
242252
supports_infinite_bounds=True,
243253
supports_linear_constraints=False,
244254
supports_nonlinear_constraints=False,
245-
disable_history=True,
255+
disable_history=False,
246256
)
247257
@dataclass(frozen=True)
248258
class TranquiloLS(Algorithm):
@@ -356,17 +366,13 @@ class TranquiloLS(Algorithm):
356366
def _solve_internal_problem(
357367
self, problem: InternalOptimizationProblem, x0: NDArray[np.float64]
358368
) -> InternalOptimizeResult:
359-
if not IS_TRANQUILO_INSTALLED:
360-
raise NotInstalledError(
361-
"The 'tranquilo-ls' algorithm requires the tranquilo package "
362-
"to be installed. You can install it with "
363-
"'conda install -c conda-forge tranquilo'."
364-
)
369+
if not IS_TRANQUILO_VERSION_NEWER_OR_EQUAL_TO_0_1_0:
370+
raise NotInstalledError(TRANQUILO_INSTALLATION_INSTRUCTIONS)
365371
from tranquilo.tranquilo import _tranquilo
366372

367373
raw_res = _tranquilo(
368374
functype="least_squares",
369-
criterion=problem.fun,
375+
batch_fun=problem.batch_fun,
370376
x=x0,
371377
lower_bounds=problem.bounds.lower,
372378
upper_bounds=problem.bounds.upper,
@@ -382,7 +388,6 @@ def _solve_internal_problem(
382388
stopping_max_criterion_evaluations=self.stopping_maxfun,
383389
stopping_max_iterations=self.stopping_maxiter,
384390
stopping_max_time=self.stopping_maxtime,
385-
batch_evaluator=self.batch_evaluator,
386391
n_cores=self.n_cores,
387392
batch_size=self.batch_size,
388393
sample_size=self.sample_size,

0 commit comments

Comments
 (0)