mdbartos / pysheds

:earth_americas: Simple and fast watershed delineation in python.
GNU General Public License v3.0
708 stars 191 forks source link

error when importing Grid class #192

Open walljcg opened 2 years ago

walljcg commented 2 years ago

Hi, I'm getting an error running the command below within Google Colab (I've pip installed using "%pip install "git+https://github.com/mdbartos/pysheds.git"). Any ideas on what might be happening? Thanks!


from pysheds.grid import Grid

/usr/local/lib/python3.7/dist-packages/numba/np/ufunc/parallel.py:363: NumbaWarning: The TBB threading layer requires TBB version 2019.5 or later i.e., TBB_INTERFACE_VERSION >= 11005. Found TBB_INTERFACE_VERSION = 9107. The TBB threading layer is disabled.
  warnings.warn(problem)
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
[<ipython-input-7-c8708fc12346>](https://localhost:8080/#) in <module>()
----> 1 from pysheds.grid import Grid

25 frames
[/usr/local/lib/python3.7/dist-packages/pysheds/grid.py](https://localhost:8080/#) in <module>()
      5     _HAS_NUMBA = False
      6 if _HAS_NUMBA:
----> 7     from pysheds.sgrid import sGrid as Grid
      8 else:
      9     from pysheds.pgrid import Grid as Grid

[/usr/local/lib/python3.7/dist-packages/pysheds/sgrid.py](https://localhost:8080/#) in <module>()
     34 
     35 # Import numba functions
---> 36 import pysheds._sgrid as _self
     37 
     38 class sGrid():

[/usr/local/lib/python3.7/dist-packages/pysheds/_sgrid.py](https://localhost:8080/#) in <module>()
   1654 @njit(int64[:,:](int64[:,:], UniTuple(int64, 8)),
   1655       parallel=True,
-> 1656       cache=True)
   1657 def _flatten_fdir_numba(fdir, dirmap):
   1658     r, c = fdir.shape

[/usr/local/lib/python3.7/dist-packages/numba/core/decorators.py](https://localhost:8080/#) in wrapper(func)
    216             with typeinfer.register_dispatcher(disp):
    217                 for sig in sigs:
--> 218                     disp.compile(sig)
    219                 disp.disable_compile()
    220         return disp

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler_lock.py](https://localhost:8080/#) in _acquire_compile_lock(*args, **kwargs)
     30         def _acquire_compile_lock(*args, **kwargs):
     31             with self:
---> 32                 return func(*args, **kwargs)
     33         return _acquire_compile_lock
     34 

[/usr/local/lib/python3.7/dist-packages/numba/core/dispatcher.py](https://localhost:8080/#) in compile(self, sig)
    817             self._cache_misses[sig] += 1
    818             try:
--> 819                 cres = self._compiler.compile(args, return_type)
    820             except errors.ForceLiteralArg as e:
    821                 def folded(args, kws):

[/usr/local/lib/python3.7/dist-packages/numba/core/dispatcher.py](https://localhost:8080/#) in compile(self, args, return_type)
     80             return retval
     81         else:
---> 82             raise retval
     83 
     84     def _compile_cached(self, args, return_type):

[/usr/local/lib/python3.7/dist-packages/numba/core/dispatcher.py](https://localhost:8080/#) in _compile_cached(self, args, return_type)
     90 
     91         try:
---> 92             retval = self._compile_core(args, return_type)
     93         except errors.TypingError as e:
     94             self._failed_cache[key] = e

[/usr/local/lib/python3.7/dist-packages/numba/core/dispatcher.py](https://localhost:8080/#) in _compile_core(self, args, return_type)
    108                                       args=args, return_type=return_type,
    109                                       flags=flags, locals=self.locals,
--> 110                                       pipeline_class=self.pipeline_class)
    111         # Check typing error if object mode is used
    112         if cres.typing_error is not None and not flags.enable_pyobject:

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler.py](https://localhost:8080/#) in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
    625     pipeline = pipeline_class(typingctx, targetctx, library,
    626                               args, return_type, flags, locals)
--> 627     return pipeline.compile_extra(func)
    628 
    629 

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler.py](https://localhost:8080/#) in compile_extra(self, func)
    361         self.state.lifted = ()
    362         self.state.lifted_from = None
--> 363         return self._compile_bytecode()
    364 
    365     def compile_ir(self, func_ir, lifted=(), lifted_from=None):

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler.py](https://localhost:8080/#) in _compile_bytecode(self)
    423         """
    424         assert self.state.func_ir is None
--> 425         return self._compile_core()
    426 
    427     def _compile_ir(self):

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler.py](https://localhost:8080/#) in _compile_core(self)
    403                 self.state.status.fail_reason = e
    404                 if is_final_pipeline:
--> 405                     raise e
    406         else:
    407             raise CompilerError("All available pipelines exhausted")

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler.py](https://localhost:8080/#) in _compile_core(self)
    394             res = None
    395             try:
--> 396                 pm.run(self.state)
    397                 if self.state.cr is not None:
    398                     break

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler_machinery.py](https://localhost:8080/#) in run(self, state)
    339                     (self.pipeline_name, pass_desc)
    340                 patched_exception = self._patch_error(msg, e)
--> 341                 raise patched_exception
    342 
    343     def dependency_analysis(self):

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler_machinery.py](https://localhost:8080/#) in run(self, state)
    330                 pass_inst = _pass_registry.get(pss).pass_inst
    331                 if isinstance(pass_inst, CompilerPass):
--> 332                     self._runPass(idx, pass_inst, state)
    333                 else:
    334                     raise BaseException("Legacy pass in use")

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler_lock.py](https://localhost:8080/#) in _acquire_compile_lock(*args, **kwargs)
     30         def _acquire_compile_lock(*args, **kwargs):
     31             with self:
---> 32                 return func(*args, **kwargs)
     33         return _acquire_compile_lock
     34 

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler_machinery.py](https://localhost:8080/#) in _runPass(self, index, pss, internal_state)
    289             mutated |= check(pss.run_initialization, internal_state)
    290         with SimpleTimer() as pass_time:
--> 291             mutated |= check(pss.run_pass, internal_state)
    292         with SimpleTimer() as finalize_time:
    293             mutated |= check(pss.run_finalizer, internal_state)

[/usr/local/lib/python3.7/dist-packages/numba/core/compiler_machinery.py](https://localhost:8080/#) in check(func, compiler_state)
    262 
    263         def check(func, compiler_state):
--> 264             mangled = func(compiler_state)
    265             if mangled not in (True, False):
    266                 msg = ("CompilerPass implementations should return True/False. "

[/usr/local/lib/python3.7/dist-packages/numba/core/typed_passes.py](https://localhost:8080/#) in run_pass(self, state)
     96                 state.return_type,
     97                 state.locals,
---> 98                 raise_errors=self._raise_errors)
     99             state.typemap = typemap
    100             if self._raise_errors:

[/usr/local/lib/python3.7/dist-packages/numba/core/typed_passes.py](https://localhost:8080/#) in type_inference_stage(typingctx, interp, args, return_type, locals, raise_errors)
     67             infer.seed_type(k, v)
     68 
---> 69         infer.build_constraint()
     70         infer.propagate(raise_errors=raise_errors)
     71         typemap, restype, calltypes = infer.unify(raise_errors=raise_errors)

[/usr/local/lib/python3.7/dist-packages/numba/core/typeinfer.py](https://localhost:8080/#) in build_constraint(self)
   1022         for blk in utils.itervalues(self.blocks):
   1023             for inst in blk.body:
-> 1024                 self.constrain_statement(inst)
   1025 
   1026     def return_types_from_partial(self):

[/usr/local/lib/python3.7/dist-packages/numba/core/typeinfer.py](https://localhost:8080/#) in constrain_statement(self, inst)
   1366     def constrain_statement(self, inst):
   1367         if isinstance(inst, ir.Assign):
-> 1368             self.typeof_assign(inst)
   1369         elif isinstance(inst, ir.SetItem):
   1370             self.typeof_setitem(inst)

[/usr/local/lib/python3.7/dist-packages/numba/core/typeinfer.py](https://localhost:8080/#) in typeof_assign(self, inst)
   1432         value = inst.value
   1433         if isinstance(value, ir.Const):
-> 1434             self.typeof_const(inst, inst.target, value.value)
   1435         elif isinstance(value, ir.Var):
   1436             self.constraints.append(Propagate(dst=inst.target.name,

[/usr/local/lib/python3.7/dist-packages/numba/core/typeinfer.py](https://localhost:8080/#) in typeof_const(self, inst, target, const)
   1467 
   1468     def typeof_const(self, inst, target, const):
-> 1469         ty = self.resolve_value_type(inst, const)
   1470         if inst.value.use_literal_type:
   1471             lit = types.maybe_literal(value=const)

[/usr/local/lib/python3.7/dist-packages/numba/core/typeinfer.py](https://localhost:8080/#) in resolve_value_type(self, inst, val)
   1458         except ValueError as e:
   1459             msg = str(e)
-> 1460         raise TypingError(msg, loc=inst.loc)
   1461 
   1462     def typeof_arg(self, inst, target, arg):

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
cannot determine Numba type of <class 'frozenset'>

File "../usr/local/lib/python3.7/dist-packages/pysheds/_sgrid.py", line 1679:
def _flatten_fdir_numba(fdir, dirmap):
    <source elided>
        # Left boundary
        if i in {5, 6, 7}:
        ^
`
cmacritchie commented 2 years ago

in google colab, try: !pip install pysheds I was having an issue with numba in google colab that wasn't occuring in Jupyter notebooks. this seemed to fix it:

!pip uninstall numba -y !pip install --pre numba !pip install pysheds

mdbartos commented 2 years ago

Might also be related to https://github.com/mdbartos/pysheds/issues/184.