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

Unclear error message with ConstantInferenceError #3717

Closed
jurajmichalak1 opened this issue Jan 29, 2019 · 1 comment · Fixed by #3718
Closed

Unclear error message with ConstantInferenceError #3717

jurajmichalak1 opened this issue Jan 29, 2019 · 1 comment · Fixed by #3718
Labels

Comments

@jurajmichalak1
Copy link

jurajmichalak1 commented Jan 29, 2019

I have following code:

@njit
def problem(a,b):
    if a == b:
        raise Exception("Equal numbers: %i %i",a,b)
    return a*b

problem(1,2)

Now I know that there is problem with that exception. I can use only constants for Exception constructor. I had very long njit-ed method with multiple exceptions code paths and following error was not helping me to localize the source of problem:

---------------------------------------------------------------------------
ConstantInferenceError                    Traceback (most recent call last)
<ipython-input-29-41c708083646> in <module>
      5     return a*b
      6 
----> 7 problem(1,2)

~/.virtualenvs/dl4cv/lib/python3.7/site-packages/numba/dispatcher.py in _compile_for_args(self, *args, **kws)
    358             # this is from trying to infer something as constant when it isn't
    359             # or isn't supported as a constant
--> 360             error_rewrite(e, 'constant_inference')
    361         except Exception as e:
    362             if config.SHOW_HELP:

~/.virtualenvs/dl4cv/lib/python3.7/site-packages/numba/dispatcher.py in error_rewrite(e, issue_type)
    313                 raise e
    314             else:
--> 315                 reraise(type(e), e, None)
    316 
    317         argtypes = []

~/.virtualenvs/dl4cv/lib/python3.7/site-packages/numba/six.py in reraise(tp, value, tb)
    656             value = tp()
    657         if value.__traceback__ is not tb:
--> 658             raise value.with_traceback(tb)
    659         raise value
    660 

ConstantInferenceError: Failed in nopython mode pipeline (step: nopython rewrites)
Cannot make a constant from: Cannot make a constant from: Cannot make a constant from: constant inference not possible for arg(0, name=a)
Numba could not make a constant out of something that it decided should be
a constant. This could well be a current limitation in Numba's internals,
please either raise a bug report along with a minimal reproducer at:
https://github.com/numba/numba/issues/new

Unfortunately there is no information about the line of source code which caused this error. Would it be possible to encapsulate also line content or just line number into exception raised? Could you navigate me into Numba's source code, maybe I can fix this and create pull request.

Expected output:

ConstantInferenceError: Failed in nopython mode pipeline (step: nopython rewrites)
Cannot make a constant from: Cannot make a constant from: Cannot make a constant from: constant inference not possible for arg(0, name=a): Source line: 'raise Exception("Equal numbers: %i %i",a,b)'

I'm novice, I was playing with Numba just last 2 days and I thank you a lot for this tool. I don't have to write parts of code in plain C. But this lack of helpful error message issue destroyed happy end of my last evening.

stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Jan 29, 2019
As title. Also adds PEP8 compliance to numba/const.py.

Fixes numba#3453
Closes numba#3717
@stuartarchibald
Copy link
Contributor

stuartarchibald commented Jan 29, 2019

Thanks for the report. I'm glad you've found Numba useful. The problem you have encountered is known #3453 and you re-reporting it prompted me to fix it in #3718. With this patch your code now does this:

$ python issue3717.py
Traceback (most recent call last):
  File "issue3717.py", line 8, in <module>
    problem(1,2)
  File "<path>/numba/numba/dispatcher.py", line 362, in _compile_for_args
    error_rewrite(e, 'constant_inference')
  File "<path>/numba/numba/dispatcher.py", line 317, in error_rewrite
    reraise(type(e), e, None)
  File "<path>/numba/numba/six.py", line 658, in reraise
    raise value.with_traceback(tb)
numba.errors.ConstantInferenceError: Failed in nopython mode pipeline (step: nopython rewrites)
Constant inference not possible for: arg(0, name=a)

File "issue3717.py", line 5:
def problem(a,b):
    <source elided>
    if a == b:
        raise Exception("Equal numbers: %i %i",a,b)
        ^

Numba could not make a constant out of something that it decided should be
a constant. This could well be a current limitation in Numba's internals,
however please first check that your code is valid for compilation,
particularly with respect to string interpolation (not supported!) and
the requirement of compile time constants as arguments to exceptions:
http://numba.pydata.org/numba-doc/latest/reference/pysupported.html?highlight=exceptions#constructs

If the code is valid and the unsupported functionality is important to you
please file a feature request at: https://github.com/numba/numba/issues/new

If you think your code should work with Numba. 
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!

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

Successfully merging a pull request may close this issue.

2 participants