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

Use of deprecated np.float #1

Closed
athulpg007 opened this issue Jul 4, 2023 · 1 comment
Closed

Use of deprecated np.float #1

athulpg007 opened this issue Jul 4, 2023 · 1 comment

Comments

@athulpg007
Copy link

from sb_arch_opt.problems.hierarchical import HierZDT1Small
problem = HierZDT1Small()
problem.print_stats()

In the print_stats line, an error occurs due to use deprecated numpy.float. Since numpy version is not pinned, I had the latest version 1.25.0. I suggest to replace the numpy.float with built-in float (preferable); or pin the numpy version to one < 1.20.0 (not recommended) as a short term fix. Full traceback:

AttributeError                            Traceback (most recent call last)
Cell In[1], line 5
      3 # Instantiate the problem class and print some statistics
      4 problem = HierZDT1Small()
----> 5 problem.print_stats()

File ~/Documents/sbarchopt-test-py39/venv/lib/python3.9/site-packages/sb_arch_opt/problem.py:221, in ArchOptProblemBase.print_stats(self)
    218 print(f'MD     : {n_discr > 0 and n_cont > 0}')  # Is it a mixed-discrete problem?
    219 print(f'MO     : {self.n_obj > 1}')  # Is it a multi-objective problem?
--> 221 imp_ratio = self.get_imputation_ratio()
    222 discrete_imp_ratio = self.get_discrete_imputation_ratio()
    223 cont_imp_ratio = self.get_continuous_imputation_ratio()

File ~/Documents/sbarchopt-test-py39/venv/lib/python3.9/site-packages/sb_arch_opt/problem.py:244, in ArchOptProblemBase.get_imputation_ratio(self)
    239 def get_imputation_ratio(self) -> float:
    240     """
    241     Returns the problem-level imputation ratio, a measure of how hierarchical the problem is. It is calculated
    242     from the product of the discrete and continuous imputation ratios.
    243     """
--> 244     return self.design_space.imputation_ratio

File ~/Documents/sbarchopt-test-py39/venv/lib/python3.9/site-packages/cached_property.py:36, in cached_property.__get__(self, obj, cls)
     33 if asyncio and asyncio.iscoroutinefunction(self.func):
     34     return self._wrap_in_coroutine(obj)
---> 36 value = obj.__dict__[self.func.__name__] = self.func(obj)
     37 return value

File ~/Documents/sbarchopt-test-py39/venv/lib/python3.9/site-packages/sb_arch_opt/design_space.py:260, in ArchDesignSpace.imputation_ratio(self)
    254 @cached_property
    255 def imputation_ratio(self) -> float:
    256     """
    257     Returns the problem-level imputation ratio, a measure of how hierarchical the problem is. It is calculated
    258     from the product of the discrete and continuous imputation ratios.
    259     """
--> 260     return self.discrete_imputation_ratio * self.continuous_imputation_ratio

File ~/Documents/sbarchopt-test-py39/venv/lib/python3.9/site-packages/cached_property.py:36, in cached_property.__get__(self, obj, cls)
     33 if asyncio and asyncio.iscoroutinefunction(self.func):
     34     return self._wrap_in_coroutine(obj)
---> 36 value = obj.__dict__[self.func.__name__] = self.func(obj)
     37 return value

File ~/Documents/sbarchopt-test-py39/venv/lib/python3.9/site-packages/sb_arch_opt/design_space.py:278, in ArchDesignSpace.discrete_imputation_ratio(self)
    275 if n_valid == 0:
    276     return 1.
--> 278 n_declared = self.get_n_declared_discrete()
    279 discrete_imp_ratio = n_declared/n_valid
    280 return discrete_imp_ratio

File ~/Documents/sbarchopt-test-py39/venv/lib/python3.9/site-packages/sb_arch_opt/design_space.py:252, in ArchDesignSpace.get_n_declared_discrete(self)
    249 if len(n_opts_discrete) == 0:
    250     return 1
--> 252 return int(np.prod(n_opts_discrete, dtype=np.float))

File ~/Documents/sbarchopt-test-py39/venv/lib/python3.9/site-packages/numpy/__init__.py:313, in __getattr__(attr)
    308     warnings.warn(
    309         f"In the future `np.{attr}` will be defined as the "
    310         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    312 if attr in __former_attrs__:
--> 313     raise AttributeError(__former_attrs__[attr])
    315 if attr == 'testing':
    316     import numpy.testing as testing

AttributeError: module 'numpy' has no attribute 'float'.
`np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
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
@athulpg007
Copy link
Author

athulpg007 commented Jul 4, 2023

Fixed in version 1.1.4 b5b5adc

Comment copied over from openjournals/joss-reviews#5564 to keep review clean, can be closed.

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