Skip to content

Commit c23f204

Browse files
authored
compatibility with numpy2 (#1613)
* numpy2 * repl * cev (#1610) * fix * fix * multiceviche * fix * nocevicheincircleci * manyfixed * manyfixed * ola * po * po * fix * asarray * complex * trapz * noz * numpy2black * BICUBIC * additionalfixes * po * fix * fix * fix * fix * fix * po * po * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * Update config.yml (#1615) * fix * fix * fix * fix * fix * Update bench.txt * Update config.yml * fix * Update bench.txt * Update test_optimizerlib.py * Update __init__.py
1 parent 1338ea1 commit c23f204

38 files changed

+79
-66
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ commands:
4040
pip install --progress-bar off -U pip setuptools
4141
pip install --progress-bar off -e .[all]
4242
#pip install --progress-bar off --use-deprecated=legacy-resolver -e .[all]
43-
pip install --progress-bar off -U numpy>=1.20.0
43+
#pip install --progress-bar off -U numpy==1.24.0
44+
pip install --progress-bar off -U numpy==1.24.0 matplotlib==2.2.3 pyomo==5.7.1
4445
pip install keras==2.6.0 # issue on Nov 4th 2021
4546
4647
jobs:

nevergrad/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
__all__ = ["optimizers", "families", "callbacks", "p", "typing", "errors", "ops"]
1616

1717

18-
__version__ = "1.0.2"
18+
__version__ = "1.0.3"

nevergrad/benchmark/plotting.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
import pandas as pd
1717
from matplotlib import pyplot as plt
1818
from matplotlib.legend import Legend
19-
from matplotlib import cm
19+
20+
# from matplotlib import cm
2021
from mpl_toolkits.axes_grid1 import make_axes_locatable
2122
import nevergrad.common.typing as tp
2223
from . import utils
@@ -611,7 +612,7 @@ def __init__(
611612
all_x = [v for vals in optim_vals.values() for v in vals[xaxis]]
612613
try:
613614
all_x = [float(a_) for a_ in all_x]
614-
self._ax.set_xlim([min(all_x), max(all_x)])
615+
self._ax.set_xlim([min(all_x), max(all_x)]) # type: ignore
615616
except TypeError:
616617
print(f"TypeError for minimum or maximum or {all_x}")
617618
self.add_legends(legend_infos)
@@ -798,7 +799,7 @@ def __init__(self, winrates_df: pd.DataFrame) -> None:
798799
max_cols = 25
799800
self._cax = self._ax.imshow(
800801
100 * np.array(self.winrates)[:, :max_cols],
801-
cmap=cm.seismic,
802+
cmap="seismic",
802803
interpolation="none",
803804
vmin=0,
804805
vmax=100,

nevergrad/benchmark/xpbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def create_seed_generator(seed: tp.Optional[int]) -> tp.Iterator[tp.Optional[int
125125
"""
126126
generator = None if seed is None else np.random.RandomState(seed=seed)
127127
while True:
128-
yield None if generator is None else generator.randint(2**32, dtype=np.uint32)
128+
yield None if generator is None else generator.randint(2**32, dtype=np.uint32) # type: ignore
129129

130130

131131
class Experiment:

nevergrad/common/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
PathLike = Union[str, Path]
5555
FloatLoss = float
5656
Loss = Union[float, ArrayLike]
57-
BoundValue = Optional[Union[float, int, _np.int_, _np.float_, ArrayLike]]
57+
BoundValue = Optional[Union[float, int, _np.int_, _np.float64, ArrayLike]]
5858

5959

6060
# %% Protocol definitions for executor typing

nevergrad/functions/arcoating/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(self, nbslab: int = 10, d_ar: int = 400, bounding_method: str = "bo
7373
super().__init__(self._get_minimum_average_reflexion, array)
7474

7575
def _get_minimum_average_reflexion(self, x: np.ndarray) -> float:
76-
x = np.array(x, copy=False).ravel()
76+
x = np.asarray(x).ravel()
7777
assert len(x) == self.dimension, f"Expected dimension {self.dimension}, got {len(x)}"
7878
if np.min(x) < self.epmin or np.max(x) > self.epf: # acceptability
7979
return float("inf")

nevergrad/functions/functionlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def process( # pylint: disable=unused-argument
7777
self.random_state.seed(int(hashlib.md5(str(y).encode()).hexdigest(), 16) % 500000)
7878
data2[i] = self.random_state.normal(0.0, 1.0)
7979
data = data2
80-
data = np.array(data, copy=False)
80+
data = np.asarray(data)
8181
output = []
8282
for transform in self._transforms:
8383
output.append(data[transform.indices] if self.only_index_transform else transform(data))

nevergrad/functions/gym/multigym.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_env_names() -> tp.List[str]:
8989

9090
gym_env_names = []
9191
max_displays = 10
92-
for e in gym.envs.registry.all():
92+
for e in gym.envs.registry.values(): # .all():
9393
try:
9494
assert not any(
9595
x in str(e.id)

nevergrad/functions/images/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def __init__(
5454
assert index == 0 # For the moment only 1 target.
5555
# path = os.path.dirname(__file__) + "/headrgb_olivier.png"
5656
path = Path(__file__).with_name("headrgb_olivier.png")
57-
image = PIL.Image.open(path).resize((self.domain_shape[0], self.domain_shape[1]), PIL.Image.BICUBIC)
57+
image = PIL.Image.open(path).resize(
58+
(self.domain_shape[0], self.domain_shape[1])
59+
) # , PIL.Image.BICUBIC)
5860
self.data = np.asarray(image)[:, :, :3] # 4th Channel is pointless here, only 255.
5961
# parametrization
6062
if not with_pgan:

nevergrad/functions/images/test_imagelosses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_l1_loss() -> None:
2727
@pytest.mark.parametrize("loss_name", imagelosses.registry) # type: ignore
2828
def test_consistency_losses_with_oteytaud(loss_name: str) -> None:
2929
path = Path(__file__).with_name("headrgb_olivier.png")
30-
image = PIL.Image.open(path).resize((256, 256), PIL.Image.BICUBIC)
30+
image = PIL.Image.open(path).resize((256, 256)) # , PIL.Image.BICUBIC)
3131
data = np.asarray(image)[:, :, :3] # 4th Channel is pointless here, only 255.
3232

3333
data_flip = np.flip(data, 0).copy() # Copy necessary as some nets do not support negative stride.

0 commit comments

Comments
 (0)