pygae / clifford

Geometric Algebra for Python
http://clifford.rtfd.io
BSD 3-Clause "New" or "Revised" License
771 stars 72 forks source link

Crash in python 3.8 #223

Closed eric-wieser closed 4 years ago

eric-wieser commented 4 years ago
In [3]: from clifford.g3c import layout
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Roaming\Python\Python38\site-packages\numba\errors.py in new_error_context(fmt_, *args, **kwargs)
    661     try:
--> 662         yield
    663     except NumbaError as e:

~\AppData\Roaming\Python\Python38\site-packages\numba\lowering.py in lower_block(self, block)
    257                                    loc=self.loc, errcls_=defaulterrcls):
--> 258                 self.lower_inst(inst)
    259

~\AppData\Roaming\Python\Python38\site-packages\numba\lowering.py in lower_inst(self, inst)
    300             ty = self.typeof(inst.target.name)
--> 301             val = self.lower_assign(ty, inst)
    302             self.storevar(val, inst.target.name)

~\AppData\Roaming\Python\Python38\site-packages\numba\lowering.py in lower_assign(self, ty, inst)
    458         elif isinstance(value, ir.Expr):
--> 459             return self.lower_expr(ty, value)
    460

~\AppData\Roaming\Python\Python38\site-packages\numba\lowering.py in lower_expr(self, resty, expr)
   1061                         for val, fromty in zip(itemvals, itemtys)]
-> 1062             return self.context.build_list(self.builder, resty, castvals)
   1063

~\AppData\Roaming\Python\Python38\site-packages\numba\targets\cpu.py in build_list(self, builder, list_type, items)
    123         """
--> 124         return listobj.build_list(self, builder, list_type, items)
    125

~\AppData\Roaming\Python\Python38\site-packages\numba\targets\listobj.py in build_list(context, builder, list_type, items)
    450     nitems = len(items)
--> 451     inst = ListInstance.allocate(context, builder, list_type, nitems)
    452     # Populate list

~\AppData\Roaming\Python\Python38\site-packages\numba\targets\listobj.py in allocate(cls, context, builder, list_type, nitems)
    318         """
--> 319         ok, self = cls.allocate_ex(context, builder, list_type, nitems)
    320         with builder.if_then(builder.not_(ok), likely=False):

~\AppData\Roaming\Python\Python38\site-packages\numba\targets\listobj.py in allocate_ex(cls, context, builder, list_type, nitems)
    267                     # Zero the allocated region
--> 268                     self.zfill(self.size.type(0), nitems)
    269

~\AppData\Roaming\Python\Python38\site-packages\numba\targets\listobj.py in zfill(self, start, stop)
    221                            builder.ptrtoint(base, intaddr_t))
--> 222         cgutils.memset(builder, base, size, ir.IntType(8)(0))
    223

~\AppData\Roaming\Python\Python38\site-packages\numba\cgutils.py in memset(builder, ptr, size, value)
    865         value = int8_t(value)
--> 866     builder.call(fn, [ptr, value, size, int32_t(0), bool_t(0)])
    867

~\AppData\Roaming\Python\Python38\site-packages\llvmlite\ir\builder.py in call(self, fn, args, name, cconv, tail, fastmath)
    839         """
--> 840         inst = instructions.CallInstr(self.block, fn, args, name=name,
    841                                       cconv=cconv, tail=tail, fastmath=fastmath)

~\AppData\Roaming\Python\Python38\site-packages\llvmlite\ir\instructions.py in __init__(self, parent, func, args, name, cconv, tail, fastmath)
     83                        .format(1 + i, expected_type, arg.type))
---> 84                 raise TypeError(msg)
     85             args[i] = arg

TypeError: Type of #4 arg mismatch: i1 != i32

During handling of the above exception, another exception occurred:

LoweringError                             Traceback (most recent call last)
<ipython-input-3-ef44c63a3449> in <module>
----> 1 from clifford.g3c import layout

c:\users\wiese\repos\ga\clifford\clifford\g3c.py in <module>
      1 from . import Cl, conformalize
----> 2 layout_orig, blades_orig = Cl(3)
      3 layout, blades, stuff = conformalize(layout_orig)
      4
      5

c:\users\wiese\repos\ga\clifford\clifford\__init__.py in Cl(p, q, r, sig, names, firstIdx, mvClass)
    731     """
    732     if sig is None:
--> 733         layout = Layout._from_Cl(p, q, r, firstIdx=firstIdx, names=names)
    734     else:
    735         layout = Layout._from_sig(sig, firstIdx=firstIdx, names=names)

c:\users\wiese\repos\ga\clifford\clifford\_layout.py in _from_Cl(cls, p, q, r, **kwargs)
    161     def _from_Cl(cls, p=0, q=0, r=0, **kwargs):
    162         """ Factory method from a ${Cl}_{p,q,r}$ notation """
--> 163         return cls._from_sig([0]*r + [+1]*p + [-1]*q, **kwargs)
    164
    165     def __hash__(self):

c:\users\wiese\repos\ga\clifford\clifford\_layout.py in _from_sig(cls, sig, firstIdx, **kwargs)
    156         bladeTupList = cf.elements(len(sig), firstIdx)
    157
--> 158         return cls(sig, bladeTupList, firstIdx=firstIdx, **kwargs)
    159
    160     @classmethod

c:\users\wiese\repos\ga\clifford\clifford\_layout.py in __init__(self, sig, bladeTupList, firstIdx, names)
    144                 (len(names), self.gaDims))
    145
--> 146         self._genTables()
    147         self.adjoint_func = get_adjoint_function(self.gradeList)
    148         self.left_complement_func = self._gen_complement_func(wedge=lambda a, b: a^b)

c:\users\wiese\repos\ga\clifford\clifford\_layout.py in _genTables(self)
    311             self.sig
    312         )
--> 313         self.omt = sparse.where(omt_prod_mask, self.gmt, self.gmt.dtype.type(0))
    314         self.imt = sparse.where(imt_prod_mask, self.gmt, self.gmt.dtype.type(0))
    315         self.lcmt = sparse.where(lcmt_prod_mask, self.gmt, self.gmt.dtype.type(0))

~\AppData\Roaming\Python\Python38\site-packages\sparse\_coo\common.py in where(condition, x, y)
    782         raise ValueError('either both or neither of x and y should be given')
    783
--> 784     return elemwise(np.where, condition, x, y)
    785
    786

~\AppData\Roaming\Python\Python38\site-packages\sparse\_coo\umath.py in elemwise(func, *args, **kwargs)
     46     """
     47
---> 48     return _Elemwise(func, *args, **kwargs).get_result()
     49
     50

~\AppData\Roaming\Python\Python38\site-packages\sparse\_coo\umath.py in get_result(self)
    451                 continue
    452
--> 453             r = self._get_func_coords_data(mask)
    454
    455             if r is not None:

~\AppData\Roaming\Python\Python38\site-packages\sparse\_coo\umath.py in _get_func_coords_data(self, mask)
    552         )
    553
--> 554         matched_arrays = self._match_coo(*matched_args,
    555                                          cache=self.cache,
    556                                          broadcast_shape=matched_broadcast_shape)

~\AppData\Roaming\Python\Python38\site-packages\sparse\_coo\umath.py in _match_coo(*args, **kwargs)
    670             sorted_idx = [np.argsort(idx) for idx in linear]
    671             linear = [idx[s] for idx, s in zip(linear, sorted_idx)]
--> 672             matched_idx = _match_arrays(*linear)
    673
    674             if return_midx:

~\AppData\Roaming\Python\Python38\site-packages\numba\dispatcher.py in _compile_for_args(self, *args, **kws)
    393                     e.patch_message(''.join(e.args) + help_msg)
    394             # ignore the FULL_TRACEBACKS config, this needs reporting!
--> 395             raise e
    396
    397     def inspect_llvm(self, signature=None):

~\AppData\Roaming\Python\Python38\site-packages\numba\dispatcher.py in _compile_for_args(self, *args, **kws)
    350                 argtypes.append(self.typeof_pyval(a))
    351         try:
--> 352             return self.compile(tuple(argtypes))
    353         except errors.TypingError as e:
    354             # Intercept typing error that may be due to an argument

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler_lock.py 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

~\AppData\Roaming\Python\Python38\site-packages\numba\dispatcher.py in compile(self, sig)
    691
    692             self._cache_misses[sig] += 1
--> 693             cres = self._compiler.compile(args, return_type)
    694             self.add_overload(cres)
    695             self._cache.save_overload(sig, cres)

~\AppData\Roaming\Python\Python38\site-packages\numba\dispatcher.py in compile(self, args, return_type)
     74
     75     def compile(self, args, return_type):
---> 76         status, retval = self._compile_cached(args, return_type)
     77         if status:
     78             return retval

~\AppData\Roaming\Python\Python38\site-packages\numba\dispatcher.py in _compile_cached(self, args, return_type)
     88
     89         try:
---> 90             retval = self._compile_core(args, return_type)
     91         except errors.TypingError as e:
     92             self._failed_cache[key] = e

~\AppData\Roaming\Python\Python38\site-packages\numba\dispatcher.py in _compile_core(self, args, return_type)
    101
    102         impl = self._get_implementation(args, {})
--> 103         cres = compiler.compile_extra(self.targetdescr.typing_context,
    104                                       self.targetdescr.target_context,
    105                                       impl,

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
    970     pipeline = pipeline_class(typingctx, targetctx, library,
    971                               args, return_type, flags, locals)
--> 972     return pipeline.compile_extra(func)
    973
    974

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in compile_extra(self, func)
    388         self.lifted = ()
    389         self.lifted_from = None
--> 390         return self._compile_bytecode()
    391
    392     def compile_ir(self, func_ir, lifted=(), lifted_from=None):

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in _compile_bytecode(self)
    901         """
    902         assert self.func_ir is None
--> 903         return self._compile_core()
    904
    905     def _compile_ir(self):

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in _compile_core(self)
    888         self.define_pipelines(pm)
    889         pm.finalize()
--> 890         res = pm.run(self.status)
    891         if res is not None:
    892             # Early pipeline completion

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler_lock.py 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

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in run(self, status)
    264                     # No more fallback pipelines?
    265                     if is_final_pipeline:
--> 266                         raise patched_exception
    267                     # Go to next fallback pipeline
    268                     else:

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in run(self, status)
    255                 try:
    256                     event("-- %s" % stage_name)
--> 257                     stage()
    258                 except _EarlyPipelineCompletion as e:
    259                     return e.result

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in stage_nopython_backend(self)
    762         """
    763         lowerfn = self.backend_nopython_mode
--> 764         self._backend(lowerfn, objectmode=False)
    765
    766     def stage_compile_interp_mode(self):

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in _backend(self, lowerfn, objectmode)
    701             self.library.enable_object_caching()
    702
--> 703         lowered = lowerfn()
    704         signature = typing.signature(self.return_type, *self.args)
    705         self.cr = compile_result(

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in backend_nopython_mode(self)
    680                "mode lowering" % (self.func_id.func_name,))
    681         with self.fallback_context(msg):
--> 682             return native_lowering_stage(
    683                 self.targetctx,
    684                 self.library,

~\AppData\Roaming\Python\Python38\site-packages\numba\compiler.py in native_lowering_stage(targetctx, library, interp, typemap, restype, calltypes, flags, metadata)
   1141         lower = lowering.Lower(targetctx, library, fndesc, interp,
   1142                                metadata=metadata)
-> 1143         lower.lower()
   1144         if not flags.no_cpython_wrapper:
   1145             lower.create_cpython_wrapper(flags.release_gil)

~\AppData\Roaming\Python\Python38\site-packages\numba\lowering.py in lower(self)
    175         if self.generator_info is None:
    176             self.genlower = None
--> 177             self.lower_normal_function(self.fndesc)
    178         else:
    179             self.genlower = self.GeneratorLower(self)

~\AppData\Roaming\Python\Python38\site-packages\numba\lowering.py in lower_normal_function(self, fndesc)
    216         # Init argument values
    217         self.extract_function_arguments()
--> 218         entry_block_tail = self.lower_function_body()
    219
    220         # Close tail of entry block

~\AppData\Roaming\Python\Python38\site-packages\numba\lowering.py in lower_function_body(self)
    241             bb = self.blkmap[offset]
    242             self.builder.position_at_end(bb)
--> 243             self.lower_block(block)
    244
    245         self.post_lower()

~\AppData\Roaming\Python\Python38\site-packages\numba\lowering.py in lower_block(self, block)
    256             with new_error_context('lowering "{inst}" at {loc}', inst=inst,
    257                                    loc=self.loc, errcls_=defaulterrcls):
--> 258                 self.lower_inst(inst)
    259
    260     def create_cpython_wrapper(self, release_gil=False):

~\AppData\Local\Programs\Python\Python38\lib\contextlib.py in __exit__(self, type, value, traceback)
    129                 value = type()
    130             try:
--> 131                 self.gen.throw(type, value, traceback)
    132             except StopIteration as exc:
    133                 # Suppress StopIteration *unless* it's the same exception that

~\AppData\Roaming\Python\Python38\site-packages\numba\errors.py in new_error_context(fmt_, *args, **kwargs)
    668         from numba import config
    669         tb = sys.exc_info()[2] if config.FULL_TRACEBACKS else None
--> 670         six.reraise(type(newerr), newerr, tb)
    671
    672

~\AppData\Roaming\Python\Python38\site-packages\numba\six.py in reraise(tp, value, tb)
    657         if value.__traceback__ is not tb:
    658             raise value.with_traceback(tb)
--> 659         raise value
    660
    661 else:

LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
Type of #4 arg mismatch: i1 != i32

File "..\..\AppData\Roaming\Python\Python38\site-packages\sparse\_coo\umath.py", line 71:
def _match_arrays(a, b):  # pragma: no cover
    <source elided>

    a_ind, b_ind = [], []
    ^

[1] During: lowering "$56.1 = build_list(items=[])" at C:\Users\wiese\AppData\Roaming\Python\Python38\site-packages\sparse\_coo\umath.py (71)
-------------------------------------------------------------------------------
This should not have happened, a problem has occurred in Numba's internals.
You are currently using Numba version 0.45.1.

Please report the error message and traceback, along with a minimal reproducer
at: https://github.com/numba/numba/issues/new

If more help is needed please feel free to speak to the Numba core developers
directly at: https://gitter.im/numba/numba

Thanks in advance for your help in improving Numba!
eric-wieser commented 4 years ago

Looks like we need to stop pinning to numba==0.45.1, works fine with numba==0.47.0

stuartarchibald commented 4 years ago

The i1 != i32 issue root cause is likely https://github.com/numba/numba/issues/5035

Dano-drevo commented 4 years ago

This crash has occurred to me with both Python 3.7.6 and Python 3.7.4 (on Ubuntu 18.04). I couldn't used a single functionality of clifford... (however, as I recall I had no issues on Ubuntu 16.04 about one month ago)

What's more...this error also appeared in my fork of this repo used via binder project. And I didn't even make any change to the repo itself, despite original repo binder-build runs smoothly. Besides, tests are passing... I really can't tell whats the deal.

Looks like we need to stop pinning to numba==0.45.1, works fine with numba==0.47.0

I can confirm that this works with Python 3.7.4 which resolved issue for me. Is there any reason to use numba version 0.45.1 instead of 0.47.0 ? If not, I suggest to immediately make this change to upstream....