diff --git a/.circleci/config.yml b/.circleci/config.yml index 0b2e811e26..66e6b5a341 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,7 +40,8 @@ commands: pip install --progress-bar off -U pip setuptools pip install --progress-bar off -e .[all] #pip install --progress-bar off --use-deprecated=legacy-resolver -e .[all] - pip install --progress-bar off -U numpy>=1.20.0 + #pip install --progress-bar off -U numpy==1.24.0 + pip install --progress-bar off -U numpy==1.24.0 matplotlib==2.2.3 pyomo==5.7.1 pip install keras==2.6.0 # issue on Nov 4th 2021 jobs: diff --git a/nevergrad/__init__.py b/nevergrad/__init__.py index 5a22841ee5..6eec780d68 100644 --- a/nevergrad/__init__.py +++ b/nevergrad/__init__.py @@ -15,4 +15,4 @@ __all__ = ["optimizers", "families", "callbacks", "p", "typing", "errors", "ops"] -__version__ = "1.0.2" +__version__ = "1.0.3" diff --git a/nevergrad/benchmark/plotting.py b/nevergrad/benchmark/plotting.py index fddc5ed75f..300d9e8fbe 100644 --- a/nevergrad/benchmark/plotting.py +++ b/nevergrad/benchmark/plotting.py @@ -16,7 +16,8 @@ import pandas as pd from matplotlib import pyplot as plt from matplotlib.legend import Legend -from matplotlib import cm + +# from matplotlib import cm from mpl_toolkits.axes_grid1 import make_axes_locatable import nevergrad.common.typing as tp from . import utils @@ -611,7 +612,7 @@ def __init__( all_x = [v for vals in optim_vals.values() for v in vals[xaxis]] try: all_x = [float(a_) for a_ in all_x] - self._ax.set_xlim([min(all_x), max(all_x)]) + self._ax.set_xlim([min(all_x), max(all_x)]) # type: ignore except TypeError: print(f"TypeError for minimum or maximum or {all_x}") self.add_legends(legend_infos) @@ -798,7 +799,7 @@ def __init__(self, winrates_df: pd.DataFrame) -> None: max_cols = 25 self._cax = self._ax.imshow( 100 * np.array(self.winrates)[:, :max_cols], - cmap=cm.seismic, + cmap="seismic", interpolation="none", vmin=0, vmax=100, diff --git a/nevergrad/benchmark/xpbase.py b/nevergrad/benchmark/xpbase.py index 9db8f17d38..458cac6073 100644 --- a/nevergrad/benchmark/xpbase.py +++ b/nevergrad/benchmark/xpbase.py @@ -125,7 +125,7 @@ def create_seed_generator(seed: tp.Optional[int]) -> tp.Iterator[tp.Optional[int """ generator = None if seed is None else np.random.RandomState(seed=seed) while True: - yield None if generator is None else generator.randint(2**32, dtype=np.uint32) + yield None if generator is None else generator.randint(2**32, dtype=np.uint32) # type: ignore class Experiment: diff --git a/nevergrad/common/typing.py b/nevergrad/common/typing.py index 57f530a6e3..dd5c8c6360 100644 --- a/nevergrad/common/typing.py +++ b/nevergrad/common/typing.py @@ -54,7 +54,7 @@ PathLike = Union[str, Path] FloatLoss = float Loss = Union[float, ArrayLike] -BoundValue = Optional[Union[float, int, _np.int_, _np.float_, ArrayLike]] +BoundValue = Optional[Union[float, int, _np.int_, _np.float64, ArrayLike]] # %% Protocol definitions for executor typing diff --git a/nevergrad/functions/arcoating/core.py b/nevergrad/functions/arcoating/core.py index 4f3b81a26d..0ce783a9fb 100644 --- a/nevergrad/functions/arcoating/core.py +++ b/nevergrad/functions/arcoating/core.py @@ -73,7 +73,7 @@ def __init__(self, nbslab: int = 10, d_ar: int = 400, bounding_method: str = "bo super().__init__(self._get_minimum_average_reflexion, array) def _get_minimum_average_reflexion(self, x: np.ndarray) -> float: - x = np.array(x, copy=False).ravel() + x = np.asarray(x).ravel() assert len(x) == self.dimension, f"Expected dimension {self.dimension}, got {len(x)}" if np.min(x) < self.epmin or np.max(x) > self.epf: # acceptability return float("inf") diff --git a/nevergrad/functions/functionlib.py b/nevergrad/functions/functionlib.py index 07284bebaa..8e3ee3d113 100644 --- a/nevergrad/functions/functionlib.py +++ b/nevergrad/functions/functionlib.py @@ -77,7 +77,7 @@ def process( # pylint: disable=unused-argument self.random_state.seed(int(hashlib.md5(str(y).encode()).hexdigest(), 16) % 500000) data2[i] = self.random_state.normal(0.0, 1.0) data = data2 - data = np.array(data, copy=False) + data = np.asarray(data) output = [] for transform in self._transforms: output.append(data[transform.indices] if self.only_index_transform else transform(data)) diff --git a/nevergrad/functions/gym/multigym.py b/nevergrad/functions/gym/multigym.py index 9c9eff1127..050642a90d 100644 --- a/nevergrad/functions/gym/multigym.py +++ b/nevergrad/functions/gym/multigym.py @@ -89,7 +89,7 @@ def get_env_names() -> tp.List[str]: gym_env_names = [] max_displays = 10 - for e in gym.envs.registry.all(): + for e in gym.envs.registry.values(): # .all(): try: assert not any( x in str(e.id) diff --git a/nevergrad/functions/images/core.py b/nevergrad/functions/images/core.py index 1fea5fab50..41c75236d4 100644 --- a/nevergrad/functions/images/core.py +++ b/nevergrad/functions/images/core.py @@ -54,7 +54,9 @@ def __init__( assert index == 0 # For the moment only 1 target. # path = os.path.dirname(__file__) + "/headrgb_olivier.png" path = Path(__file__).with_name("headrgb_olivier.png") - image = PIL.Image.open(path).resize((self.domain_shape[0], self.domain_shape[1]), PIL.Image.BICUBIC) + image = PIL.Image.open(path).resize( + (self.domain_shape[0], self.domain_shape[1]) + ) # , PIL.Image.BICUBIC) self.data = np.asarray(image)[:, :, :3] # 4th Channel is pointless here, only 255. # parametrization if not with_pgan: diff --git a/nevergrad/functions/images/test_imagelosses.py b/nevergrad/functions/images/test_imagelosses.py index 0dd7b77839..5f81d25c56 100644 --- a/nevergrad/functions/images/test_imagelosses.py +++ b/nevergrad/functions/images/test_imagelosses.py @@ -27,7 +27,7 @@ def test_l1_loss() -> None: @pytest.mark.parametrize("loss_name", imagelosses.registry) # type: ignore def test_consistency_losses_with_oteytaud(loss_name: str) -> None: path = Path(__file__).with_name("headrgb_olivier.png") - image = PIL.Image.open(path).resize((256, 256), PIL.Image.BICUBIC) + image = PIL.Image.open(path).resize((256, 256)) # , PIL.Image.BICUBIC) data = np.asarray(image)[:, :, :3] # 4th Channel is pointless here, only 255. data_flip = np.flip(data, 0).copy() # Copy necessary as some nets do not support negative stride. diff --git a/nevergrad/functions/mlda/problems.py b/nevergrad/functions/mlda/problems.py index 7004f6c540..25c58d6829 100644 --- a/nevergrad/functions/mlda/problems.py +++ b/nevergrad/functions/mlda/problems.py @@ -127,7 +127,7 @@ def apply(self, parameters: tp.ArrayLike) -> np.ndarray: np.ndarray transformed data """ - parameters = np.array(parameters, copy=False) + parameters = np.asarray(parameters) assert parameters.shape == (10,) tmp = np.tanh(self._x[:, None] * parameters[None, :3] + parameters[None, 3:6]) tmp *= parameters[None, 6:9] diff --git a/nevergrad/functions/photonics/core.py b/nevergrad/functions/photonics/core.py index d742870163..4022453527 100644 --- a/nevergrad/functions/photonics/core.py +++ b/nevergrad/functions/photonics/core.py @@ -181,7 +181,7 @@ def to_array(self, *args: tp.Any, **kwargs: tp.Any) -> np.ndarray: assert not kwargs data = np.concatenate(args).T if self._as_tuple else args[0] assert data.size == self.dimension - return np.array(data, copy=False).ravel() + return np.asarray(data).ravel() def evaluation_function(self, *recommendations: ng.p.Parameter) -> float: assert len(recommendations) == 1, "Should not be a pareto set for a singleobjective function" diff --git a/nevergrad/functions/photonics/photonics.py b/nevergrad/functions/photonics/photonics.py index 35986ef3f6..065b284d02 100644 --- a/nevergrad/functions/photonics/photonics.py +++ b/nevergrad/functions/photonics/photonics.py @@ -23,6 +23,13 @@ # pylint: disable=blacklisted-name,too-many-locals,too-many-arguments +def trapezoid(a, b): # type: ignore + try: + return np.trapz(a, b) # numpy < 2.0 + except: # type: ignore + return np.trapezoid(a, b) # numpy 2.0 + + def bragg(X: np.ndarray) -> float: """ Cost function for the Bragg mirror problem: maximizing the reflection @@ -109,8 +116,8 @@ def c_bas(A: np.ndarray, V: np.ndarray, h: float) -> np.ndarray: def marche(a: float, b: float, p: float, n: int, x: float) -> np.ndarray: - l = np.zeros(n, dtype=np.complex_) # noqa - m = np.zeros(n, dtype=np.complex_) + l = np.zeros(n, dtype=np.complex128) # noqa + m = np.zeros(n, dtype=np.complex128) tmp = ( 1 / (2 * np.pi * np.arange(1, n)) @@ -187,7 +194,7 @@ def morpho(X: np.ndarray) -> float: l = lam / d # noqa k0 = 2 * np.pi / l P, V = homogene(k0, 0, pol, 1, n) - S = np.block([[np.zeros([n, n]), np.eye(n, dtype=np.complex_)], [np.eye(n), np.zeros([n, n])]]) + S = np.block([[np.zeros([n, n]), np.eye(n, dtype=np.complex128)], [np.eye(n), np.zeros([n, n])]]) for j in range(0, n_motifs): Pc, Vc = creneau(k0, 0, pol, e2, 1, a[j], n, x0[j]) S = cascade(S, interface(P, Pc)) @@ -196,7 +203,7 @@ def morpho(X: np.ndarray) -> float: S = c_bas(S, V, spacers[j]) Pc, Vc = homogene(k0, 0, pol, e2, n) S = cascade(S, interface(P, Pc)) - R = np.zeros(3, dtype=np.float_) + R = np.zeros(3, dtype=np.float64) for j in range(-1, 2): R[j] = abs(S[j + nmod, nmod]) ** 2 * np.real(V[j + nmod]) / k0 cost: float = 1 - (R[-1] + R[1]) / 2 + R[0] / 2 @@ -208,7 +215,7 @@ def morpho(X: np.ndarray) -> float: P, V = homogene(k0, 0, pol, 1, n) S = np.block( [ - [np.zeros([n, n], dtype=np.complex_), np.eye(n)], + [np.zeros([n, n], dtype=np.complex128), np.eye(n)], [np.eye(n), np.zeros([n, n])], ] ) @@ -366,8 +373,8 @@ def cf_photosic_reference(X: np.ndarray) -> float: absorb = absorption(lam, epsilon, mu, type_, hauteur, pol, theta) scc[k] = solar(lam) Ab[k] = absorb[len(absorb) - 1] - max_scc = np.trapz(scc, vlam) - j_sc = np.trapz(scc * Ab, vlam) + max_scc = trapezoid(scc, vlam) + j_sc = trapezoid(scc * Ab, vlam) CE = j_sc / max_scc cost = 1 - CE return cost # type: ignore @@ -404,8 +411,8 @@ def cf_photosic_realistic(eps_and_d: np.ndarray) -> float: absorb = absorption(lam, epsilon, mu, type_, hauteur, pol, theta) scc[k] = solar(lam) Ab[k] = absorb[len(absorb) - 1] - max_scc = np.trapz(scc, vlam) - j_sc = np.trapz(scc * Ab, vlam) + max_scc = trapezoid(scc, vlam) + j_sc = trapezoid(scc * Ab, vlam) CE = j_sc / max_scc cost = 1 - CE return cost # type: ignore diff --git a/nevergrad/functions/powersystems/core.py b/nevergrad/functions/powersystems/core.py index 3575c19c1a..c9b0e2e3d2 100644 --- a/nevergrad/functions/powersystems/core.py +++ b/nevergrad/functions/powersystems/core.py @@ -8,6 +8,9 @@ import typing as tp from math import pi, cos, sin +import matplotlib + +matplotlib.use("Agg") import matplotlib.pyplot as plt import numpy as np from nevergrad.parametrization import parameter as p diff --git a/nevergrad/functions/pyomo/test_core.py b/nevergrad/functions/pyomo/test_core.py index ad48749c51..7fe68ee437 100644 --- a/nevergrad/functions/pyomo/test_core.py +++ b/nevergrad/functions/pyomo/test_core.py @@ -5,6 +5,7 @@ import typing as tp import os import numpy as np + import pyomo.environ as pyomo import nevergrad as ng from . import core diff --git a/nevergrad/functions/stsp/core.py b/nevergrad/functions/stsp/core.py index ca0c2c6895..b58e6037f2 100644 --- a/nevergrad/functions/stsp/core.py +++ b/nevergrad/functions/stsp/core.py @@ -43,5 +43,5 @@ def make_plots(self, filename: str = "stsp.png") -> None: order = self.order x = self.x y = self.y - ax.plot((x[o] for o in order), (y[o] for o in order)) + ax.plot((x[o] for o in order), (y[o] for o in order)) # type: ignore plt.savefig(filename) diff --git a/nevergrad/optimization/base.py b/nevergrad/optimization/base.py index e55c0116cc..74527d646b 100644 --- a/nevergrad/optimization/base.py +++ b/nevergrad/optimization/base.py @@ -344,7 +344,7 @@ def tell( ) loss = 5.0e20 # sys.float_info.max leads to numerical problems so let us do this. elif isinstance(loss, (tuple, list, np.ndarray)): - loss = np.array(loss, copy=False, dtype=float).ravel() if len(loss) != 1 else loss[0] + loss = np.asarray(loss, dtype=float).ravel() if len(loss) != 1 else loss[0] elif not isinstance(loss, np.ndarray): raise TypeError( f'"tell" method only supports float values but the passed loss was: {loss} (type: {type(loss)}.' diff --git a/nevergrad/optimization/callbacks.py b/nevergrad/optimization/callbacks.py index f59e77f31f..e20a4d7ba7 100644 --- a/nevergrad/optimization/callbacks.py +++ b/nevergrad/optimization/callbacks.py @@ -161,7 +161,7 @@ def __call__(self, optimizer: base.Optimizer, candidate: p.Parameter, loss: tp.F data["#parents_uids"] = candidate.parents_uids for name, param in helpers.flatten(candidate, with_containers=False, order=1): val = param.value - if isinstance(val, (np.float_, np.int_, np.bool_)): + if isinstance(val, (np.float64, np.int_, np.bool_)): val = val.item() if inspect.ismethod(val): val = repr(val.__self__) # show mutation class diff --git a/nevergrad/optimization/helpers.py b/nevergrad/optimization/helpers.py index 606e2b0bb2..e70d2d90ff 100644 --- a/nevergrad/optimization/helpers.py +++ b/nevergrad/optimization/helpers.py @@ -65,7 +65,7 @@ def __init__( if not (inspect.isclass(cls) and issubclass(cls, base.Optimizer)): raise TypeError('"cls" must be a str, a ConfiguredOptimizer instance, or an Optimizer class') args = ( - ng.p.Array(init=np.array(p.data, dtype=np.float_)).set_bounds(-bound, bound, method="clipping") + ng.p.Array(init=np.array(p.data, dtype=np.float64)).set_bounds(-bound, bound, method="clipping") for p in self.parameters ) # bounded to avoid overflows self.optimizer = cls(ng.p.Tuple(*args), budget=None, num_workers=1) diff --git a/nevergrad/optimization/multiobjective/core.py b/nevergrad/optimization/multiobjective/core.py index 0dd47d3ffa..b9deb06417 100644 --- a/nevergrad/optimization/multiobjective/core.py +++ b/nevergrad/optimization/multiobjective/core.py @@ -58,9 +58,7 @@ def __init__( no_hypervolume: bool = False, ) -> None: self._auto_bound = 0 - self._upper_bounds = ( - np.array([-float("inf")]) if upper_bounds is None else np.array(upper_bounds, copy=False) - ) + self._upper_bounds = np.asarray([-float("inf")]) if upper_bounds is None else np.array(upper_bounds) if upper_bounds is None: self._auto_bound = auto_bound # If we are yet to set the upper bounds, or yet to have an add since doing so, _best_volume is -inf. diff --git a/nevergrad/optimization/multiobjective/hypervolume.py b/nevergrad/optimization/multiobjective/hypervolume.py index b26503a4e5..d3581c8b42 100644 --- a/nevergrad/optimization/multiobjective/hypervolume.py +++ b/nevergrad/optimization/multiobjective/hypervolume.py @@ -33,7 +33,7 @@ def __init__( self, dimension: int, coordinates: tp.Optional[tp.Union[np.ndarray, tp.List[float]]] = None ) -> None: self.dimension = dimension - self.coordinates = np.array(coordinates, copy=False) + self.coordinates = np.asarray(coordinates) self._next: tp.List["VectorNode"] = [self for _ in range(self.dimension)] self._prev: tp.List["VectorNode"] = [self for _ in range(self.dimension)] self.dominated_flag = 0 @@ -185,7 +185,7 @@ class HypervolumeIndicator: """ def __init__(self, reference_point: np.ndarray) -> None: - self.reference_point = np.array(reference_point, copy=False) + self.reference_point = np.asarray(reference_point) self.dimension = self.reference_point.size self.reference_bounds = np.full(self.dimension, -np.inf) self._multilist: tp.Optional[VectorLinkedList] = None diff --git a/nevergrad/optimization/optimizerlib.py b/nevergrad/optimization/optimizerlib.py index 7773db3b2d..fedb33b97a 100644 --- a/nevergrad/optimization/optimizerlib.py +++ b/nevergrad/optimization/optimizerlib.py @@ -752,7 +752,7 @@ def es(self) -> tp.Any: # typing not possible since cmaes not imported :( x0=( self.parametrization.sample().get_standardized_data(reference=self.parametrization) if self._config.random_init - else np.zeros(self.dimension, dtype=np.float_) + else np.zeros(self.dimension, dtype=np.float64) ), sigma0=self._config.scale * scale_multiplier, inopts=inopts, @@ -765,7 +765,7 @@ def es(self) -> tp.Any: # typing not possible since cmaes not imported :( "Please install fcmaes (pip install fcmaes) to use FCMA optimizers" ) from e self._es = cmaes.Cmaes( - x0=np.zeros(self.dimension, dtype=np.float_), + x0=np.zeros(self.dimension, dtype=np.float64), input_sigma=self._config.scale * scale_multiplier, popsize=self._popsize, randn=self._rng.randn, @@ -2928,7 +2928,7 @@ def _internal_ask_candidate(self) -> p.Parameter: else: x_probe = self.bo.suggest(util) # this is time consuming x_probe = [x_probe[self._fake_function.key(i)] for i in range(len(x_probe))] - data = self._normalizer.backward(np.array(x_probe, copy=False)) + data = self._normalizer.backward(np.asarray(x_probe)) candidate = self.parametrization.spawn_child().set_standardized_data(data) candidate._meta["x_probe"] = x_probe return candidate @@ -3067,7 +3067,7 @@ def _internal_ask_candidate(self) -> p.Parameter: candidate = candidate.tolist() self._buffer = candidate x_probe = self._buffer.pop() - data = self._normalizer.backward(np.array(x_probe, copy=False)) + data = self._normalizer.backward(np.array(x_probe)) candidate = self.parametrization.spawn_child().set_standardized_data(data) candidate._meta["x_probe"] = x_probe return candidate diff --git a/nevergrad/optimization/recastlib.py b/nevergrad/optimization/recastlib.py index afc9c33d79..3b5c5bb3b9 100644 --- a/nevergrad/optimization/recastlib.py +++ b/nevergrad/optimization/recastlib.py @@ -102,7 +102,7 @@ def _optimization_function( def ax_obj(p): data = [p["x" + str(i)] for i in range(weakself.dimension)] # type: ignore if weakself._normalizer: - data = weakself._normalizer.backward(np.asarray(data, dtype=np.float_)) + data = weakself._normalizer.backward(np.asarray(data, dtype=np.float64)) return objective_function(data) while remaining > 0: # try to restart if budget is not elapsed diff --git a/nevergrad/optimization/sequences.py b/nevergrad/optimization/sequences.py index ef7d6bbe88..1e856a6426 100644 --- a/nevergrad/optimization/sequences.py +++ b/nevergrad/optimization/sequences.py @@ -206,7 +206,7 @@ def _internal_sampler(self) -> tp.ArrayLike: class Rescaler: def __init__(self, points: tp.Iterable[tp.ArrayLike]) -> None: iterp = iter(points) - self.sample_mins = np.array(next(iterp), copy=False) + self.sample_mins = np.asarray(next(iterp)) self.sample_maxs = self.sample_mins for point in iterp: self.sample_mins = np.minimum(self.sample_mins, point) @@ -217,6 +217,6 @@ def __init__(self, points: tp.Iterable[tp.ArrayLike]) -> None: ), f"Non-positive epsilon={self.epsilon} from mins {self.sample_mins} and maxs {self.sample_maxs}" def apply(self, point: tp.ArrayLike) -> np.ndarray: - point = np.array(point, copy=False) + point = np.asarray(point) factor = (1 - 2 * self.epsilon) / (self.sample_maxs - self.sample_mins) return self.epsilon + factor * (point - self.sample_mins) # type: ignore diff --git a/nevergrad/optimization/test_callbacks.py b/nevergrad/optimization/test_callbacks.py index fc938e681f..7a37120927 100644 --- a/nevergrad/optimization/test_callbacks.py +++ b/nevergrad/optimization/test_callbacks.py @@ -21,7 +21,7 @@ def _func(x: tp.Any, y: tp.Any, blublu: str, array: tp.Any, multiobjective: bool def test_log_parameters(tmp_path: Path) -> None: filepath = tmp_path / "logs.txt" - cases = [0, np.int_(1), np.float_(2.0), np.nan, float("inf"), np.inf] + cases = [0, np.int_(1), np.float64(2.0), np.nan, float("inf"), np.inf] instrum = ng.p.Instrumentation( ng.ops.mutations.Translation()(ng.p.Array(shape=(1,))), ng.p.Scalar(), diff --git a/nevergrad/optimization/test_optimizerlib.py b/nevergrad/optimization/test_optimizerlib.py index 0db9e9049b..7fa6df208f 100644 --- a/nevergrad/optimization/test_optimizerlib.py +++ b/nevergrad/optimization/test_optimizerlib.py @@ -74,7 +74,7 @@ def __init__(self, x0: tp.ArrayLike) -> None: def __call__(self, x: tp.ArrayLike) -> float: assert len(self.x0) == len(x) self.call_times.append(time.time()) - return float(np.sum((np.array(x, copy=False) - self.x0) ** 2)) + return float(np.sum((np.asarray(x) - self.x0) ** 2)) def get_factors(self) -> tp.Tuple[float, float]: logdiffs = np.log(np.maximum(1e-15, np.cumsum(np.diff(self.call_times)))) diff --git a/nevergrad/optimization/test_special.py b/nevergrad/optimization/test_special.py index aef969f31c..addd6814ce 100644 --- a/nevergrad/optimization/test_special.py +++ b/nevergrad/optimization/test_special.py @@ -25,7 +25,7 @@ def __init__(self, x0: tp.ArrayLike, x1: tp.ArrayLike) -> None: def __call__(self, x: tp.ArrayLike) -> float: assert len(self.x0) == len(x) - return float(np.sum(self.x1 * np.cos(np.array(x, copy=False) - self.x0) ** 2)) + return float(np.sum(self.x1 * np.cos(np.asarray(x) - self.x0) ** 2)) @pytest.mark.parametrize("dim", [2, 10, 40, 200]) # type: ignore diff --git a/nevergrad/optimization/utils.py b/nevergrad/optimization/utils.py index 1e44a6de76..72aade6de0 100644 --- a/nevergrad/optimization/utils.py +++ b/nevergrad/optimization/utils.py @@ -157,9 +157,9 @@ def submit(self, fn: tp.Callable[..., tp.Any], *args: tp.Any, **kwargs: tp.Any) def _tobytes(x: tp.ArrayLike) -> bytes: - x = np.array(x, copy=False) # for compatibility + x = np.asarray(x) # for compatibility assert x.ndim == 1, f"Input shape: {x.shape}" - assert x.dtype == np.float_, f"Incorrect type {x.dtype} is not float" + assert x.dtype == np.float64, f"Incorrect type {x.dtype} is not float" return x.tobytes() diff --git a/nevergrad/parametrization/_datalayers.py b/nevergrad/parametrization/_datalayers.py index 4ca2be5d33..3f60a7a84e 100644 --- a/nevergrad/parametrization/_datalayers.py +++ b/nevergrad/parametrization/_datalayers.py @@ -147,7 +147,7 @@ class Modulo(BoundLayer): def __init__(self, module: tp.Any) -> None: super().__init__(lower=0, upper=module) - if not isinstance(module, (np.ndarray, np.float_, np.int_, float, int)): + if not isinstance(module, (np.ndarray, np.float64, np.int_, float, int)): raise TypeError(f"Unsupported type {type(module)} for module") self._module = module diff --git a/nevergrad/parametrization/_layering.py b/nevergrad/parametrization/_layering.py index 14fe17027c..2b3c69988f 100644 --- a/nevergrad/parametrization/_layering.py +++ b/nevergrad/parametrization/_layering.py @@ -211,7 +211,7 @@ def _layered_get_value(self) -> float: return out # type: ignore def _layered_set_value(self, value: tp.Any) -> None: - if not isinstance(value, (float, int, np.float_, np.int_)): + if not isinstance(value, (float, int, np.float64, np.int_)): raise TypeError(f"Received a {type(value)} in place of a scalar (float, int)") super()._layered_set_value(np.array([value], dtype=float)) diff --git a/nevergrad/parametrization/choice.py b/nevergrad/parametrization/choice.py index ea7c3116bd..d735e48b60 100644 --- a/nevergrad/parametrization/choice.py +++ b/nevergrad/parametrization/choice.py @@ -202,7 +202,7 @@ def __init__( choices=choices, repetitions=repetitions, indices=indices, - transitions=transitions if isinstance(transitions, Array) else np.array(transitions, copy=False), + transitions=transitions if isinstance(transitions, Array) else np.asarray(transitions), ) assert self.transitions.value.ndim == 1 self._ref: tp.Optional["TransitionChoice"] = None diff --git a/nevergrad/parametrization/core.py b/nevergrad/parametrization/core.py index 0ee3ece6e0..fa45e167d2 100644 --- a/nevergrad/parametrization/core.py +++ b/nevergrad/parametrization/core.py @@ -220,7 +220,7 @@ def set_standardized_data(self: P, data: tp.ArrayLike, *, reference: tp.Optional ), f"Expected {type(self)} but got {type(sent_reference)} as reference" self._check_frozen() del self.value # remove all cached information - self._internal_set_standardized_data(np.array(data, copy=False), reference=sent_reference) + self._internal_set_standardized_data(np.asarray(data), reference=sent_reference) return self def _internal_set_standardized_data( # pylint: disable=unused-argument diff --git a/nevergrad/parametrization/data.py b/nevergrad/parametrization/data.py index 10c1d68a77..901d9ffcdc 100644 --- a/nevergrad/parametrization/data.py +++ b/nevergrad/parametrization/data.py @@ -74,7 +74,7 @@ def __init__( if sum(x is None for x in [init, shape]) != 1: raise ValueError('Exactly one of "init" or "shape" must be provided') if init is not None: - init = np.array(init, dtype=float, copy=False) + init = np.asarray(init, dtype=float) # , copy=False) else: assert isinstance(shape, (list, tuple)) and all( isinstance(n, int) for n in shape diff --git a/nevergrad/parametrization/test_utils.py b/nevergrad/parametrization/test_utils.py index 6feb1eb96b..14daab9638 100644 --- a/nevergrad/parametrization/test_utils.py +++ b/nevergrad/parametrization/test_utils.py @@ -143,8 +143,8 @@ def test_flatten_order(order: int, keys: tp.Iterable[str]) -> None: np_false=(np.bool_(False), 1.0), pos=(0.7, 0.0), neg=(-0.7, 0.7), - np_pos=(np.float_(0.7), 0.0), - np_neg=(np.float_(-0.7), 0.7), + np_pos=(np.float64(0.7), 0.0), + np_neg=(np.float64(-0.7), 0.7), ) def test_float_penalty(value: tp.Any, expected: float) -> None: assert utils.float_penalty(value) == expected diff --git a/nevergrad/parametrization/transforms.py b/nevergrad/parametrization/transforms.py index e6506b87ca..388d8c049b 100644 --- a/nevergrad/parametrization/transforms.py +++ b/nevergrad/parametrization/transforms.py @@ -14,7 +14,7 @@ def bound_to_array(x: tp.BoundValue) -> np.ndarray: """Updates type of bounds to use arrays""" if isinstance(x, (tuple, list, np.ndarray)): - return np.array(x, copy=False) + return np.asarray(x) else: return np.array([x], dtype=float) @@ -118,7 +118,7 @@ def _f(x: BoundType) -> BoundType: array with one scalars are converted to floats """ if isinstance(x, (np.ndarray, list, tuple)): - x = np.array(x, copy=False) + x = np.asarray(x) if x.shape == (1,): x = float(x[0]) if isinstance(x, float) and x.is_integer(): @@ -134,7 +134,7 @@ def __init__(self, a_min: BoundType = None, a_max: BoundType = None) -> None: for name, value in [("a_min", a_min), ("a_max", a_max)]: if value is not None: isarray = isinstance(value, (tuple, list, np.ndarray)) - setattr(self, name, np.array(value, copy=False) if isarray else np.array([value])) + setattr(self, name, np.asarray(value) if isarray else np.array([value])) if not (self.a_min is None or self.a_max is None): if (self.a_min >= self.a_max).any(): raise ValueError(f"Lower bounds {a_min} should be strictly smaller than upper bounds {a_max}") diff --git a/nevergrad/parametrization/utils.py b/nevergrad/parametrization/utils.py index 61081e59f6..cc72499755 100644 --- a/nevergrad/parametrization/utils.py +++ b/nevergrad/parametrization/utils.py @@ -272,7 +272,7 @@ def float_penalty(x: tp.Union[bool, float]) -> float: """ if isinstance(x, (bool, np.bool_)): return float(not x) # False ==> 1. - elif isinstance(x, (float, np.float_)): + elif isinstance(x, (float, np.float64)): return -min(0, x) # Negative ==> >0 raise TypeError(f"Only bools and floats are supported for check constaint, but got: {x} ({type(x)})") diff --git a/requirements/bench.txt b/requirements/bench.txt index ff93bf4751..fa98c0890c 100644 --- a/requirements/bench.txt +++ b/requirements/bench.txt @@ -9,25 +9,25 @@ xlrd>=1.2.0 #lpips>=0.1.3 # removed because sometimes complicated. opencv-python>=4.1.2.30 matplotlib>=2.2.3 -#gym>=0.12.1 -#gym==0.24.1 gym==0.24.1 -gym-anm>=1.0.1 +#gym-anm>=1.0.1 pygame>=2.1.2 torch>=1.7.0 hiplot -fcmaes>=1.2.7 +fcmaes #>=1.2.7 pandas>=0.23.4 openpyxl>=3.0.0 # mlda data (for pandas) #pyproj>=2.6.1 pyproj -Pillow==10.3.0 +Pillow>=10.3.0 tqdm torchvision>=0.11.1 +#pyomo>=6.7.3 pyomo==5.7.1 mixsimulator>=0.3.3 hyperopt>=0.2.5 -IOHexperimenter>=0.2.8.7 +IOHexperimenter>=0.2.9.2 +# IOHexperimenter>=0.2.8.7 cdt>=0.5.23 tensorflow-estimator>=2.7.0 tensorflow>=2.7.0 @@ -35,16 +35,16 @@ keras>=2.4.3 #koncept>=0.2.2 # removed because sometimes complicated #tensorflow-estimator>=2.7.0 scikit-learn>=1.0.1 -scikit-image==0.18.3 +scikit-image>=0.18.3 image-quality>=1.2.7 #keras>=2.4.3 #tensorflow>=2.7.0 pymoo==0.5.0 -olymp==0.0.1b0 ; sys_platform == "linux" +olymp>=0.0.1b0 ; sys_platform == "linux" Keras-Preprocessing silence_tensorflow # for olymp tensorflow_probability # for olymp -bayes-optim==0.3.0 +bayes-optim #==0.3.0 nlopt pybullet>=3.2.2 #box2d-py>=2.3.5 @@ -57,7 +57,7 @@ Py-BOBYQA>=1.2 ax-platform loguru # for fcmaes #gomea -directsearch==1.0 +directsearch>=1.0 numpy>=1.16.2 scipy>=1.2.1 matplotlib>=3.0.3 diff --git a/requirements/dev.txt b/requirements/dev.txt index 8445ccffb4..83f68d832b 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -11,5 +11,5 @@ recommonmark>=0.5.0 twine>=3.1.1 # for upload to pypi autodocsumm>=0.1.11 pandas>=0.23.4 -pyparsing==2.2.1 # temporarily fixed to avoid incompatibilities (to be removed) +pyparsing>=2.2.1 # temporarily fixed to avoid incompatibilities (to be removed) docutils==0.17.1 # 0.18 is buggy