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

Bug with Python 3.8 and np.argmin #4712

Closed
larsoner opened this issue Oct 15, 2019 · 4 comments
Closed

Bug with Python 3.8 and np.argmin #4712

larsoner opened this issue Oct 15, 2019 · 4 comments
Labels

Comments

@larsoner
Copy link
Contributor

Trying to compile some code on Python 3.8.0rc1 (what Ubuntu 19.10 ships with currently) and latest numpy (1.18.0.dev0+5ed0ebe) and numba (bdd8e31) master this code:

from numba import jit
import numpy as np


@jit(nopython=True)
def _bad():
    return np.argmin(np.zeros(1))

_bad()

Produces:

$ python -u numba38.py
/home/larsoner/python/numba/numba/dataflow.py:58: RuntimeWarning: inconsistent stack offset for block(offset:42, outgoing: [52], incoming: [24, 26])
  warnings.warn("inconsistent stack offset for %s" % blk,
...
File "numba38.py", line 7:
def _bad():
    return np.argmin(np.zeros(1))
    ^

[1] During: lowering "$0.7 = call $0.2($0.6, func=$0.2, args=[Var($0.6, numba38.py (7))], kws=(), vararg=None)" at numba38.py (7)

-------------------------------------------------------------------------------
This should not have happened, a problem has occurred in Numba's internals.
You are currently using Numba version 0.47.0dev0.

Full trace:

larsoner@bunk:~/Desktop$ python -u numba38.py 
/home/larsoner/python/numba/numba/dataflow.py:58: RuntimeWarning: inconsistent stack offset for block(offset:42, outgoing: [52], incoming: [24, 26])
  warnings.warn("inconsistent stack offset for %s" % blk,
Traceback (most recent call last):
  File "/home/larsoner/python/numba/numba/errors.py", line 717, in new_error_context
    yield
  File "/home/larsoner/python/numba/numba/lowering.py", line 260, in lower_block
    self.lower_inst(inst)
  File "/home/larsoner/python/numba/numba/lowering.py", line 303, in lower_inst
    val = self.lower_assign(ty, inst)
  File "/home/larsoner/python/numba/numba/lowering.py", line 465, in lower_assign
    return self.lower_expr(ty, value)
  File "/home/larsoner/python/numba/numba/lowering.py", line 927, in lower_expr
    res = self.lower_call(resty, expr)
  File "/home/larsoner/python/numba/numba/lowering.py", line 719, in lower_call
    res = self._lower_call_normal(fnty, expr, signature)
  File "/home/larsoner/python/numba/numba/lowering.py", line 898, in _lower_call_normal
    res = impl(self.builder, argvals, self.loc)
  File "/home/larsoner/python/numba/numba/targets/base.py", line 1132, in __call__
    res = self._imp(self._context, builder, self._sig, args, loc=loc)
  File "/home/larsoner/python/numba/numba/targets/base.py", line 1157, in wrapper
    return fn(*args, **kwargs)
  File "/home/larsoner/python/numba/numba/targets/arraymath.py", line 608, in array_argmin
    res = context.compile_internal(builder, array_argmin_impl, sig, args)
  File "/home/larsoner/python/numba/numba/targets/base.py", line 859, in compile_internal
    cres = self.compile_subroutine(builder, impl, sig, locals)
  File "/home/larsoner/python/numba/numba/targets/base.py", line 844, in compile_subroutine
    cres = self._compile_subroutine_no_cache(builder, impl, sig,
  File "/home/larsoner/python/numba/numba/targets/base.py", line 815, in _compile_subroutine_no_cache
    cres = compiler.compile_internal(self.typing_context, self,
  File "/home/larsoner/python/numba/numba/compiler.py", line 602, in compile_internal
    return pipeline.compile_extra(func)
  File "/home/larsoner/python/numba/numba/compiler.py", line 326, in compile_extra
    return self._compile_bytecode()
  File "/home/larsoner/python/numba/numba/compiler.py", line 385, in _compile_bytecode
    return self._compile_core()
  File "/home/larsoner/python/numba/numba/compiler.py", line 365, in _compile_core
    raise e
  File "/home/larsoner/python/numba/numba/compiler.py", line 356, in _compile_core
    pm.run(self.state)
  File "/home/larsoner/python/numba/numba/compiler_machinery.py", line 328, in run
    raise patched_exception
  File "/home/larsoner/python/numba/numba/compiler_machinery.py", line 319, in run
    self._runPass(idx, pass_inst, state)
  File "/home/larsoner/python/numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
    return func(*args, **kwargs)
  File "/home/larsoner/python/numba/numba/compiler_machinery.py", line 281, in _runPass
    mutated |= check(pss.run_pass, internal_state)
  File "/home/larsoner/python/numba/numba/compiler_machinery.py", line 268, in check
    mangled = func(compiler_state)
  File "/home/larsoner/python/numba/numba/untyped_passes.py", line 78, in run_pass
    func_ir = interp.interpret(bc)
  File "/home/larsoner/python/numba/numba/interpreter.py", line 103, in interpret
    self.dfa.run()
  File "/home/larsoner/python/numba/numba/dataflow.py", line 30, in run
    self.infos[blk.offset] = self.run_on_block(blk)
  File "/home/larsoner/python/numba/numba/dataflow.py", line 76, in run_on_block
    callback(info)
  File "/home/larsoner/python/numba/numba/dataflow.py", line 304, in pop_info
    info.pop()
  File "/home/larsoner/python/numba/numba/dataflow.py", line 853, in pop
    return self.make_incoming()
  File "/home/larsoner/python/numba/numba/dataflow.py", line 880, in make_incoming
    ib.request_outgoing(self, ret, stack_index)
  File "/home/larsoner/python/numba/numba/dataflow.py", line 897, in request_outgoing
    varname = self.stack[stack_index - self.stack_offset]
IndexError: Failed in nopython mode pipeline (step: analyzing bytecode)
list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "numba38.py", line 9, in <module>
    _bad()
  File "/home/larsoner/python/numba/numba/dispatcher.py", line 420, in _compile_for_args
    raise e
  File "/home/larsoner/python/numba/numba/dispatcher.py", line 353, in _compile_for_args
    return self.compile(tuple(argtypes))
  File "/home/larsoner/python/numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
    return func(*args, **kwargs)
  File "/home/larsoner/python/numba/numba/dispatcher.py", line 768, in compile
    cres = self._compiler.compile(args, return_type)
  File "/home/larsoner/python/numba/numba/dispatcher.py", line 77, in compile
    status, retval = self._compile_cached(args, return_type)
  File "/home/larsoner/python/numba/numba/dispatcher.py", line 91, in _compile_cached
    retval = self._compile_core(args, return_type)
  File "/home/larsoner/python/numba/numba/dispatcher.py", line 104, in _compile_core
    cres = compiler.compile_extra(self.targetdescr.typing_context,
  File "/home/larsoner/python/numba/numba/compiler.py", line 528, in compile_extra
    return pipeline.compile_extra(func)
  File "/home/larsoner/python/numba/numba/compiler.py", line 326, in compile_extra
    return self._compile_bytecode()
  File "/home/larsoner/python/numba/numba/compiler.py", line 385, in _compile_bytecode
    return self._compile_core()
  File "/home/larsoner/python/numba/numba/compiler.py", line 365, in _compile_core
    raise e
  File "/home/larsoner/python/numba/numba/compiler.py", line 356, in _compile_core
    pm.run(self.state)
  File "/home/larsoner/python/numba/numba/compiler_machinery.py", line 328, in run
    raise patched_exception
  File "/home/larsoner/python/numba/numba/compiler_machinery.py", line 319, in run
    self._runPass(idx, pass_inst, state)
  File "/home/larsoner/python/numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
    return func(*args, **kwargs)
  File "/home/larsoner/python/numba/numba/compiler_machinery.py", line 281, in _runPass
    mutated |= check(pss.run_pass, internal_state)
  File "/home/larsoner/python/numba/numba/compiler_machinery.py", line 268, in check
    mangled = func(compiler_state)
  File "/home/larsoner/python/numba/numba/typed_passes.py", line 380, in run_pass
    NativeLowering().run_pass(state) # TODO: Pull this out into the pipeline
  File "/home/larsoner/python/numba/numba/typed_passes.py", line 325, in run_pass
    lower.lower()
  File "/home/larsoner/python/numba/numba/lowering.py", line 179, in lower
    self.lower_normal_function(self.fndesc)
  File "/home/larsoner/python/numba/numba/lowering.py", line 220, in lower_normal_function
    entry_block_tail = self.lower_function_body()
  File "/home/larsoner/python/numba/numba/lowering.py", line 245, in lower_function_body
    self.lower_block(block)
  File "/home/larsoner/python/numba/numba/lowering.py", line 260, in lower_block
    self.lower_inst(inst)
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/larsoner/python/numba/numba/errors.py", line 725, in new_error_context
    six.reraise(type(newerr), newerr, tb)
  File "/home/larsoner/python/numba/numba/six.py", line 669, in reraise
    raise value
numba.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
Failed in nopython mode pipeline (step: analyzing bytecode)
list index out of range

File "numba38.py", line 7:
def _bad():
    return np.argmin(np.zeros(1))
    ^

[1] During: lowering "$0.7 = call $0.2($0.6, func=$0.2, args=[Var($0.6, numba38.py (7))], kws=(), vararg=None)" at numba38.py (7)

-------------------------------------------------------------------------------
This should not have happened, a problem has occurred in Numba's internals.
You are currently using Numba version 0.47.0dev0.

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!

A more complicated version of this code works fine on Ubuntu 3.7.

Tagging #4071 since it's 3.8-related (I think).

@stuartarchibald
Copy link
Contributor

Thanks for the report. Guessing solely from what is on stdout, the bytecode updates/changes in Python 3.8 are sufficiently altered that the current bytecode analysis is not working. We (core developers) anticipated this and are planning a 0.46.1 patch release to accommodate Python 3.8.

@ulijh
Copy link

ulijh commented Nov 28, 2019

This works with the current master. Could be closed I guess.

@esc
Copy link
Member

esc commented Nov 28, 2019

@ulijh thanks for circling back on this and confirming that it does work on master. I am assuming this is the result of #4755 being merged. Closing now.

@esc esc closed this as completed Nov 28, 2019
@larsoner
Copy link
Contributor Author

larsoner commented Dec 2, 2019

Indeed things appear fixed on 3.8 for me on master, thanks!

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

No branches or pull requests

4 participants