Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support with NumPy 1.24+ #311

Open
mwtoews opened this issue Sep 21, 2023 · 1 comment
Open

Support with NumPy 1.24+ #311

mwtoews opened this issue Sep 21, 2023 · 1 comment

Comments

@mwtoews
Copy link

mwtoews commented Sep 21, 2023

Tests currently fail with recent NumPy releases. For instance:

pytest tests/test_algorithms.py::TestAlgorithms::test_padds

With current numpy (1.24.4):

self = <test_algorithms.TestAlgorithms testMethod=test_padds>

    def test_padds(self):
        sampler = spotpy.algorithms.padds(
            spot_setup_hymod(self.multi_obj_func),
            parallel=self.parallel,
            dbname="Rosen",
            dbformat=self.dbformat,
            sim_timeout=self.timeout,
        )
>       sampler.sample(int(self.rep * 0.5), metric="ones")

tests/test_algorithms.py:216: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/spotpy/algorithms/padds.py:259: in sample
    ) = self.calculate_initial_parameterset(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = padds(), repetitions = 493, initial_objs = array([], dtype=float64), initial_params = array([], dtype=float64)

    def calculate_initial_parameterset(self, repetitions, initial_objs, initial_params):
        self.obj_func_current = np.array([0.0])
        self.parameter_current = np.array([0.0] * self.number_of_parameters)
        self.parameter_range = (
            self.best_value.parameters.maxbound - self.best_value.parameters.minbound
        )
>       self.pareto_front = np.array(
            [[np.array([]), np.array([0] * self.number_of_parameters)]]
        )
E       ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 2) + inhomogeneous part.

src/spotpy/algorithms/padds.py:172: ValueError

With previous numpy (1.23.5) the test passes, but shows a VisibleDeprecationWarning:

/path/to/spotpy/src/spotpy/algorithms/padds.py:173: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
self.pareto_front = np.array(

where it created array([[array([], dtype=float64), array([0, 0, 0, 0, 0])]], dtype=object)

@lotruheawea
Copy link

Another issue is that np.int was deprecated
See

  File "/perm/cyrs/conda/envs/calibrate_ecland/lib/python3.11/site-packages/spotpy/algorithms/dds.py", line 281, in sample
    initial_iterations = np.int(np.max([5, round(0.005 * repetitions)]))
                         ^^^^^^
  File "/perm/cyrs/conda/envs/calibrate_ecland/lib/python3.11/site-packages/numpy/__init__.py", line 324, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'inf'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants