USNavalResearchLaboratory / PyEBSDIndex

Python based tool for Hough/Radon based EBSD orientation indexing
https://pyebsdindex.readthedocs.io
Other
13 stars 8 forks source link

np.float() errors with Numba 0.57.0 #44

Closed hakonanes closed 1 year ago

hakonanes commented 1 year ago

Got this TypingError when doing with NumPy 1.24.3 and Numba 0.57.0

>>> from pyebsdindex import ebsd_index, pcopt
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
Cell In[4], line 1
----> 1 from pyebsdindex import pcopt, ebsd_index

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/pyebsdindex/ebsd_index.py:26
     23 """Setup and handling of Hough indexing runs of EBSD patterns."""
     25 from pyebsdindex import _ray_installed
---> 26 from pyebsdindex._ebsd_index_single import EBSDIndexer, index_pats
     28 if _ray_installed:
     29     from pyebsdindex._ebsd_index_parallel import index_pats_distributed, IndexerRay

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/pyebsdindex/_ebsd_index_single.py:32
     29 import numpy as np
     30 import h5py
---> 32 from pyebsdindex import (
     33     band_vote,
     34     ebsd_pattern,
     35     rotlib,
     36     tripletlib,
     37     _pyopencl_installed,
     38 )
     40 if _pyopencl_installed:
     41     from pyebsdindex.opencl import band_detect_cl as band_detect

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/pyebsdindex/band_vote.py:32
     29 import numba
     30 import numpy as np
---> 32 from pyebsdindex import rotlib
     35 RADEG = 180.0/np.pi
     37 tempdir = PurePath("/tmp" if platform.system() == "Darwin" else tempfile.gettempdir())

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/pyebsdindex/rotlib.py:1346
   1341     xyzba[2] = sXYZ[0]
   1342   return xyzba
   1345 @numba.jit(['f8[:](f8[:])','f8[:](f4[:])'], nopython=True,fastmath=nbFastmath, cache=nbcache)
-> 1346 def lambert3DBallToCube(xyz):
   1347   LPR1 = np.float(1.33067003949147) # (3pi/4)**(1/3)
   1348   LPpref = np.float(1.38197659788534) # sqrt(6/pi)

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/decorators.py:241, in _jit.<locals>.wrapper(func)
    239     with typeinfer.register_dispatcher(disp):
    240         for sig in sigs:
--> 241             disp.compile(sig)
    242         disp.disable_compile()
    243 return disp

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/dispatcher.py:965, in Dispatcher.compile(self, sig)
    963 with ev.trigger_event("numba:compile", data=ev_details):
    964     try:
--> 965         cres = self._compiler.compile(args, return_type)
    966     except errors.ForceLiteralArg as e:
    967         def folded(args, kws):

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/dispatcher.py:129, in _FunctionCompiler.compile(self, args, return_type)
    127     return retval
    128 else:
--> 129     raise retval

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/dispatcher.py:139, in _FunctionCompiler._compile_cached(self, args, return_type)
    136     pass
    138 try:
--> 139     retval = self._compile_core(args, return_type)
    140 except errors.TypingError as e:
    141     self._failed_cache[key] = e

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/dispatcher.py:152, in _FunctionCompiler._compile_core(self, args, return_type)
    149 flags = self._customize_flags(flags)
    151 impl = self._get_implementation(args, {})
--> 152 cres = compiler.compile_extra(self.targetdescr.typing_context,
    153                               self.targetdescr.target_context,
    154                               impl,
    155                               args=args, return_type=return_type,
    156                               flags=flags, locals=self.locals,
    157                               pipeline_class=self.pipeline_class)
    158 # Check typing error if object mode is used
    159 if cres.typing_error is not None and not flags.enable_pyobject:

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler.py:742, in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
    718 """Compiler entry point
    719 
    720 Parameter
   (...)
    738     compiler pipeline
    739 """
    740 pipeline = pipeline_class(typingctx, targetctx, library,
    741                           args, return_type, flags, locals)
--> 742 return pipeline.compile_extra(func)

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler.py:460, in CompilerBase.compile_extra(self, func)
    458 self.state.lifted = ()
    459 self.state.lifted_from = None
--> 460 return self._compile_bytecode()

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler.py:528, in CompilerBase._compile_bytecode(self)
    524 """
    525 Populate and run pipeline for bytecode input
    526 """
    527 assert self.state.func_ir is None
--> 528 return self._compile_core()

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler.py:507, in CompilerBase._compile_core(self)
    505         self.state.status.fail_reason = e
    506         if is_final_pipeline:
--> 507             raise e
    508 else:
    509     raise CompilerError("All available pipelines exhausted")

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler.py:494, in CompilerBase._compile_core(self)
    492 res = None
    493 try:
--> 494     pm.run(self.state)
    495     if self.state.cr is not None:
    496         break

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler_machinery.py:368, in PassManager.run(self, state)
    365 msg = "Failed in %s mode pipeline (step: %s)" % \
    366     (self.pipeline_name, pass_desc)
    367 patched_exception = self._patch_error(msg, e)
--> 368 raise patched_exception

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler_machinery.py:356, in PassManager.run(self, state)
    354 pass_inst = _pass_registry.get(pss).pass_inst
    355 if isinstance(pass_inst, CompilerPass):
--> 356     self._runPass(idx, pass_inst, state)
    357 else:
    358     raise BaseException("Legacy pass in use")

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.<locals>._acquire_compile_lock(*args, **kwargs)
     32 @functools.wraps(func)
     33 def _acquire_compile_lock(*args, **kwargs):
     34     with self:
---> 35         return func(*args, **kwargs)

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler_machinery.py:311, in PassManager._runPass(self, index, pss, internal_state)
    309     mutated |= check(pss.run_initialization, internal_state)
    310 with SimpleTimer() as pass_time:
--> 311     mutated |= check(pss.run_pass, internal_state)
    312 with SimpleTimer() as finalize_time:
    313     mutated |= check(pss.run_finalizer, internal_state)

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/compiler_machinery.py:273, in PassManager._runPass.<locals>.check(func, compiler_state)
    272 def check(func, compiler_state):
--> 273     mangled = func(compiler_state)
    274     if mangled not in (True, False):
    275         msg = ("CompilerPass implementations should return True/False. "
    276                "CompilerPass with name '%s' did not.")

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/typed_passes.py:110, in BaseTypeInference.run_pass(self, state)
    104 """
    105 Type inference and legalization
    106 """
    107 with fallback_context(state, 'Function "%s" failed type inference'
    108                       % (state.func_id.func_name,)):
    109     # Type inference
--> 110     typemap, return_type, calltypes, errs = type_inference_stage(
    111         state.typingctx,
    112         state.targetctx,
    113         state.func_ir,
    114         state.args,
    115         state.return_type,
    116         state.locals,
    117         raise_errors=self._raise_errors)
    118     state.typemap = typemap
    119     # save errors in case of partial typing

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/typed_passes.py:88, in type_inference_stage(typingctx, targetctx, interp, args, return_type, locals, raise_errors)
     86     infer.build_constraint()
     87     # return errors in case of partial typing
---> 88     errs = infer.propagate(raise_errors=raise_errors)
     89     typemap, restype, calltypes = infer.unify(raise_errors=raise_errors)
     91 # Output all Numba warnings

File ~/miniconda3/envs/kp-dev/lib/python3.10/site-packages/numba/core/typeinfer.py:1086, in TypeInferer.propagate(self, raise_errors)
   1083 force_lit_args = [e for e in errors
   1084                   if isinstance(e, ForceLiteralArg)]
   1085 if not force_lit_args:
-> 1086     raise errors[0]
   1087 else:
   1088     raise reduce(operator.or_, force_lit_args)

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at resolving type of attribute "float" of "$2load_global.0".
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
During: typing of get attribute at /home/hakon/miniconda3/envs/kp-dev/lib/python3.10/site-packages/pyebsdindex/rotlib.py (1347)
Enable logging at debug level for details.

File "../../../../miniconda3/envs/kp-dev/lib/python3.10/site-packages/pyebsdindex/rotlib.py", line 1347:
def lambert3DBallToCube(xyz):
  LPR1 = np.float(1.33067003949147) # (3pi/4)**(1/3)
  ^

Can fix this after next week, as I have a conference the coming week.

hakonanes commented 1 year ago

The error message states we can simply replace np.float() with float().

drowenhorst-nrl commented 1 year ago

I actually have that fix on my "develop" branch. Because these are part of the numba code, I decided it was better to explicitly type it by replacing with np.float64. There is A LOT of other fixes/rewrites, etc in that branch, but it is high time to pull it over to the main repo.

hakonanes commented 1 year ago

Great, looking forward to try out your updates!

It would be good to release a patch v0.1.2 with this fixed. There aren't any new changes in the main branch, so we could merge a fix there and release from that branch right away. What do you think?