55
66import numpy as np
77from numpy .typing import NDArray
8+ from packaging import version
89
910from optimagic import mark
1011from optimagic .config import IS_TRANQUILO_INSTALLED
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" ,
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 )
5469class 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 )
248258class 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