当我调用函数时 Numba 崩溃,但如果我将函数中的内容放在外面则不会

Numba crashes when I call a function but not if I put what's in the function outside

我正在尝试使用一些代码,其中包含 numba,它在 Windows 上运行良好,但在 MacOS 上崩溃。

基本上我有这条线

self.bruit = self.noise()

numba崩溃的地方,我稍后给出完整的日志。

功能简单

def noise(self,): 
    return self.coef * random.gauss(self.m,self.s )

我不明白的是,如果我像这样提取函数中的内容

self.bruit =self.coef * random.gauss(self.m, self.s)

我一点问题都没有,一切都很好。

我不明白为什么会出现这个问题。

最让我困惑的是,我有另一个脚本基本上做同样的事情(ODE 只是更小),它使用 noise() 函数并且工作正常。

    Traceback (most recent call last):
  File "/Users/yochum/Desktop/NIH/NMM_Applications/LargeScale/LargeScale_NMM_GUI.py", line 1184, in Runclicked
    self.LFPs,self.tp, self.Pulses, self.PPSs = self.C.Compute_Time(T,Fs,Stim=self.List_Stim,List_ParamEvol=self.List_ParamEvol ,Pre_Post=self.Simulation_Actions_StimPosPre.isChecked())
  File "/Users/yochum/Desktop/NIH/NMM_Applications/LargeScale/Cortex_Model_Wendling_TargetGains.py", line 330, in Compute_Time
    self.do_steptime()
  File "/Users/yochum/Desktop/NIH/NMM_Applications/LargeScale/Cortex_Model_Wendling_TargetGains.py", line 156, in do_steptime
    self.pop[idx].rk4()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/jitclass/boxing.py", line 62, in wrapper
    return method(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/dispatcher.py", line 344, in _compile_for_args
    reraise(type(e), e, None)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/six.py", line 658, in reraise
    raise value.with_traceback(tb)
numba.errors.TypingError: Failed at nopython (nopython frontend)
Failed at nopython (nopython frontend)
Internal error at <numba.typeinfer.CallConstraint object at 0x13cf6a278>:
--%<----------------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/errors.py", line 491, in new_error_context
    yield
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/typeinfer.py", line 421, in __call__
    self.resolve(typeinfer, typevars, fnty)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/typeinfer.py", line 447, in resolve
    sig = typeinfer.resolve_call(fnty, pos_args, kw_args, literals=literals)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/typeinfer.py", line 1161, in resolve_call
    literals=literals)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/typing/context.py", line 204, in resolve_function_type
    return func.get_call_type_with_literals(self, args, kws, literals)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/types/functions.py", line 202, in get_call_type_with_literals
    return self.get_call_type(context, args, kws)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/types/functions.py", line 196, in get_call_type
    return self.template(context).apply(args, kws)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/typing/templates.py", line 207, in apply
    sig = generic(args, kws)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/jitclass/base.py", line 322, in generic
    sig = disp_type.get_call_type(self.context, args, kws)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/types/functions.py", line 253, in get_call_type
    template, pysig, args, kws = self.dispatcher.get_call_template(args, kws)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/dispatcher.py", line 273, in get_call_template
    self.compile(tuple(args))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/dispatcher.py", line 618, in compile
    cres = self._compiler.compile(args, return_type)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/dispatcher.py", line 83, in compile
    pipeline_class=self.pipeline_class)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 871, in compile_extra
    return pipeline.compile_extra(func)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 365, in compile_extra
    return self._compile_bytecode()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 802, in _compile_bytecode
    return self._compile_core()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 789, in _compile_core
    res = pm.run(self.status)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 251, in run
    raise patched_exception
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 243, in run
    stage()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 676, in stage_nopython_backend
    self._backend(lowerfn, objectmode=False)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 626, in _backend
    lowered = lowerfn()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 613, in backend_nopython_mode
    self.flags)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/compiler.py", line 1003, in native_lowering_stage
    cfunc = targetctx.get_executable(library, fndesc, env)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/targets/cpu.py", line 166, in get_executable
    baseptr = library.get_pointer_to_function(fndesc.llvm_func_name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/targets/codegen.py", line 461, in get_pointer_to_function
    self._ensure_finalized()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/targets/codegen.py", line 103, in _ensure_finalized
    self.finalize()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/targets/codegen.py", line 228, in finalize
    self._optimize_final_module()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/targets/codegen.py", line 124, in _optimize_final_module
    self._final_module = remove_redundant_nrt_refct(self._final_module)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/runtime/nrtopt.py", line 169, in remove_redundant_nrt_refct
    new_mod = ll.parse_assembly(newll)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/llvmlite/binding/module.py", line 26, in parse_assembly
    raise RuntimeError("LLVM IR parsing error\n{0}".format(errmsg))
RuntimeError: Failed at nopython (nopython mode backend)
LLVM IR parsing error
<string>:155:12: error: use of undefined value '%_ZN26Model_Wendling_TargetGains12pop_Wendling10noise69EN8instance8jitclass1176pop_Wendling7fc4d10b3d38cAafloat64cBafloat64cGafloat64caafloat64cbafloat64cgafloat64cC1afloat64cC2afloat64cC3afloat64cC4afloat64cC5afloat64cC6afloat64cC7afloat64cv0afloat64ce0afloat64crafloat64cmafloat64csafloat64ccoefafloat64cdtafloat64cNbODEsaint32cdydxaarrayfloat64c1dcAcdydx1aarrayfloat64c1dcAcdydx2aarrayfloat64c1dcAcdydx3aarrayfloat64c1dcAcdydx4aarrayfloat64c1dcAcyaarrayfloat64c1dcAcytaarrayfloat64c1dcAcbruitafloat64cEEGoutputafloat64cpulseOutputPafloat64cpulseOutputINGabaAsafloat64cpulseOutputINGabaAfafloat64cPPSEpyrPafloat64cPPSIgabaAfafloat64cPPSIgabaAsafloat64cExtI_Pyr_to_Pyrafloat64cExtI_Gas_to_Pyrafloat64cExtI_Gaf_to_Pyrafloat64cExtI_Pyr_to_Gasafloat4'
  br label %"_ZN26Model_Wendling_TargetGains12pop_Wendling10noise69EN8instance8jitclass1176pop_Wendling7fc4d10b3d38cAafloat64cBafloat64cGafloat64caafloat64cbafloat64cgafloat64cC1afloat64cC2afloat64cC3afloat64cC4afloat64cC5afloat64cC6afloat64cC7afloat64cv0afloat64ce0afloat64crafloat64cmafloat64csafloat64ccoefafloat64cdtafloat64cNbODEsaint32cdydxaarrayfloat64c1dcAcdydx1aarrayfloat64c1dcAcdydx2aarrayfloat64c1dcAcdydx3aarrayfloat64c1dcAcdydx4aarrayfloat64c1dcAcyaarrayfloat64c1dcAcytaarrayfloat64c1dcAcbruitafloat64cEEGoutputafloat64cpulseOutputPafloat64cpulseOutputINGabaAsafloat64cpulseOutputINGabaAfafloat64cPPSEpyrPafloat64cPPSIgabaAfafloat64cPPSIgabaAsafloat64cExtI_Pyr_to_Pyrafloat64cExtI_Gas_to_Pyrafloat64cExtI_Gaf_to_Pyrafloat64cExtI_Pyr_to_Gasafloat4"
           ^


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/typeinfer.py", line 138, in propagate
    constraint(typeinfer)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/typeinfer.py", line 421, in __call__
    self.resolve(typeinfer, typevars, fnty)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/errors.py", line 499, in new_error_context
    six.reraise(type(newerr), newerr, tb)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numba/six.py", line 659, in reraise
    raise value
numba.errors.InternalError: Failed at nopython (nopython mode backend)
LLVM IR parsing error
<string>:155:12: error: use of undefined value '%_ZN26Model_Wendling_TargetGains12pop_Wendling10noise69EN8instance8jitclass1176pop_Wendling7fc4d10b3d38cAafloat64cBafloat64cGafloat64caafloat64cbafloat64cgafloat64cC1afloat64cC2afloat64cC3afloat64cC4afloat64cC5afloat64cC6afloat64cC7afloat64cv0afloat64ce0afloat64crafloat64cmafloat64csafloat64ccoefafloat64cdtafloat64cNbODEsaint32cdydxaarrayfloat64c1dcAcdydx1aarrayfloat64c1dcAcdydx2aarrayfloat64c1dcAcdydx3aarrayfloat64c1dcAcdydx4aarrayfloat64c1dcAcyaarrayfloat64c1dcAcytaarrayfloat64c1dcAcbruitafloat64cEEGoutputafloat64cpulseOutputPafloat64cpulseOutputINGabaAsafloat64cpulseOutputINGabaAfafloat64cPPSEpyrPafloat64cPPSIgabaAfafloat64cPPSIgabaAsafloat64cExtI_Pyr_to_Pyrafloat64cExtI_Gas_to_Pyrafloat64cExtI_Gaf_to_Pyrafloat64cExtI_Pyr_to_Gasafloat4'
  br label %"_ZN26Model_Wendling_TargetGains12pop_Wendling10noise69EN8instance8jitclass1176pop_Wendling7fc4d10b3d38cAafloat64cBafloat64cGafloat64caafloat64cbafloat64cgafloat64cC1afloat64cC2afloat64cC3afloat64cC4afloat64cC5afloat64cC6afloat64cC7afloat64cv0afloat64ce0afloat64crafloat64cmafloat64csafloat64ccoefafloat64cdtafloat64cNbODEsaint32cdydxaarrayfloat64c1dcAcdydx1aarrayfloat64c1dcAcdydx2aarrayfloat64c1dcAcdydx3aarrayfloat64c1dcAcdydx4aarrayfloat64c1dcAcyaarrayfloat64c1dcAcytaarrayfloat64c1dcAcbruitafloat64cEEGoutputafloat64cpulseOutputPafloat64cpulseOutputINGabaAsafloat64cpulseOutputINGabaAfafloat64cPPSEpyrPafloat64cPPSIgabaAfafloat64cPPSIgabaAsafloat64cExtI_Pyr_to_Pyrafloat64cExtI_Gas_to_Pyrafloat64cExtI_Gaf_to_Pyrafloat64cExtI_Pyr_to_Gasafloat4"
           ^

[1] During: resolving callee type: BoundFunction((<class 'numba.types.misc.ClassInstanceType'>, 'noise') for instance.jitclass.pop_Wendling#7fc4d10b3d38<A:float64,B:float64,G:float64,a:float64,b:float64,g:float64,C1:float64,C2:float64,C3:float64,C4:float64,C5:float64,C6:float64,C7:float64,v0:float64,e0:float64,r:float64,m:float64,s:float64,coef:float64,dt:float64,NbODEs:int32,dydx:array(float64, 1d, A),dydx1:array(float64, 1d, A),dydx2:array(float64, 1d, A),dydx3:array(float64, 1d, A),dydx4:array(float64, 1d, A),y:array(float64, 1d, A),yt:array(float64, 1d, A),bruit:float64,EEGoutput:float64,pulseOutputP:float64,pulseOutputINGabaAs:float64,pulseOutputINGabaAf:float64,PPSEpyrP:float64,PPSIgabaAf:float64,PPSIgabaAs:float64,ExtI_Pyr_to_Pyr:float64,ExtI_Gas_to_Pyr:float64,ExtI_Gaf_to_Pyr:float64,ExtI_Pyr_to_Gas:float64,ExtI_Gas_to_Gas:float64,ExtI_Gaf_to_Gas:float64,ExtI_Pyr_to_Gaf:float64,ExtI_Gas_to_Gaf:float64,ExtI_Gaf_to_Gaf:float64,k_P:float64,k_Gas:float64,k_Gaf:float64,Stim:float64,Pre_Post:int32>)
[2] During: typing of call at /Users/yochum/Desktop/NIH/NMM_Applications/LargeScale/Model_Wendling_TargetGains.py (161)

--%<----------------------------------------------------------------------------


File "Model_Wendling_TargetGains.py", line 161:
    def rk4(self):
        <source elided>
        #self.bruit =self.coef * random.gauss(self.m, self.s)
        self.bruit = self.noise() #p(t) est le bruit d'entree dans le modele
        ^

[1] During: resolving callee type: BoundFunction((<class 'numba.types.misc.ClassInstanceType'>, 'rk4') for instance.jitclass.pop_Wendling#7fc4d10b3d38<A:float64,B:float64,G:float64,a:float64,b:float64,g:float64,C1:float64,C2:float64,C3:float64,C4:float64,C5:float64,C6:float64,C7:float64,v0:float64,e0:float64,r:float64,m:float64,s:float64,coef:float64,dt:float64,NbODEs:int32,dydx:array(float64, 1d, A),dydx1:array(float64, 1d, A),dydx2:array(float64, 1d, A),dydx3:array(float64, 1d, A),dydx4:array(float64, 1d, A),y:array(float64, 1d, A),yt:array(float64, 1d, A),bruit:float64,EEGoutput:float64,pulseOutputP:float64,pulseOutputINGabaAs:float64,pulseOutputINGabaAf:float64,PPSEpyrP:float64,PPSIgabaAf:float64,PPSIgabaAs:float64,ExtI_Pyr_to_Pyr:float64,ExtI_Gas_to_Pyr:float64,ExtI_Gaf_to_Pyr:float64,ExtI_Pyr_to_Gas:float64,ExtI_Gas_to_Gas:float64,ExtI_Gaf_to_Gas:float64,ExtI_Pyr_to_Gaf:float64,ExtI_Gas_to_Gaf:float64,ExtI_Gaf_to_Gaf:float64,k_P:float64,k_Gas:float64,k_Gaf:float64,Stim:float64,Pre_Post:int32>)
[2] During: typing of call at <string> (3)


File "<string>", line 3:


This is not usually a problem with Numba itself but instead often caused by
the use of unsupported features or an issue in resolving types.

To see Python/NumPy features supported by the latest release of Numba visit:
http://numba.pydata.org/numba-doc/dev/reference/pysupported.html
and
http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html

For more information about typing errors and how to debug them visit:
http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile

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

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

我在另一个论坛找到了解决方案

所以添加这个

from llvmlite import binding
binding.set_option("tmp", "-non-global-value-max-name-size=2048")

导入后防止错误。