Error problems in Optimal Growth I (Dynamic Programming)

Hi, some guys including me found it impossible to implement the codes provided in
“Optimal Growth I: The Stochastic Optimal Growth Mode” due to some error.

We use jupyter notebook and the 11th cell does not work.
(The subsequent contents in Optimal Growth I and Optimal Growth II seem to have the same problem.)
Here is the (very long) error message:


TypingError Traceback (most recent call last)
in
3
4 v_init = v_star(grid, α, β, μ) # Start at the solution
----> 5 v = T(v_init) # Apply the Bellman operator once
6
7 fig, ax = plt.subplots(figsize=(9, 5))

~\Anaconda3\lib\site-packages\numba\dispatcher.py in _compile_for_args(self, *args, **kws)
346 e.patch_message(msg)
347
–> 348 error_rewrite(e, ‘typing’)
349 except errors.UnsupportedError as e:
350 # Something unsupported is present in the user code, add help info

~\Anaconda3\lib\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 = []

~\Anaconda3\lib\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

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.typeinfer.CallConstraint object at 0x000001EE0C601EB8>:
–%<----------------------------------------------------------------------------
Traceback (most recent call last):
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\errors.py”, line 609, in new_error_context
yield
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\lowering.py”, line 259, in lower_block
self.lower_inst(inst)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\lowering.py”, line 403, in lower_inst
self.lower_static_raise(inst)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\lowering.py”, line 442, in lower_static_raise
self.return_exception(inst.exc_class, inst.exc_args, loc=self.loc)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\lowering.py”, line 164, in return_exception
func_name=self.func_ir.func_id.func_name)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\targets\callconv.py”, line 367, in return_user_exc
fname = loc._raw_function_name()
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\ir.py”, line 63, in _raw_function_name
return self._defmatcher.match(defn.strip()).groups()[0]
AttributeError: ‘NoneType’ object has no attribute ‘groups’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\typeinfer.py”, line 141, in propagate
constraint(typeinfer)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\typeinfer.py”, line 422, in call
self.resolve(typeinfer, typevars, fnty)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\typeinfer.py”, line 446, in resolve
sig = typeinfer.resolve_call(fnty, pos_args, kw_args)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\typeinfer.py”, line 1231, in resolve_call
return self.context.resolve_function_type(fnty, pos_args, kw_args)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\typing\context.py”, line 190, in resolve_function_type
res = self._resolve_user_function_type(func, args, kws)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\typing\context.py”, line 242, in _resolve_user_function_type
return func.get_call_type(self, args, kws)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\types\functions.py”, line 280, in get_call_type
template, pysig, args, kws = self.dispatcher.get_call_template(args, kws)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\dispatcher.py”, line 272, in get_call_template
self.compile(tuple(args))
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler_lock.py”, line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\dispatcher.py”, line 655, in compile
cres = self._compiler.compile(args, return_type)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\dispatcher.py”, line 82, in compile
pipeline_class=self.pipeline_class)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 926, in compile_extra
return pipeline.compile_extra(func)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 374, in compile_extra
return self._compile_bytecode()
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 857, in _compile_bytecode
return self._compile_core()
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 844, in _compile_core
res = pm.run(self.status)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler_lock.py”, line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 255, in run
raise patched_exception
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 246, in run
stage()
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 717, in stage_nopython_backend
self._backend(lowerfn, objectmode=False)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 666, in _backend
lowered = lowerfn()
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 653, in backend_nopython_mode
self.metadata)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\compiler.py”, line 1048, in native_lowering_stage
lower.lower()
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\lowering.py”, line 178, in lower
self.lower_normal_function(self.fndesc)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\lowering.py”, line 219, in lower_normal_function
entry_block_tail = self.lower_function_body()
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\lowering.py”, line 244, in lower_function_body
self.lower_block(block)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\lowering.py”, line 259, in lower_block
self.lower_inst(inst)
File “C:\Users\shcor\Anaconda3\lib\contextlib.py”, line 130, in exit
self.gen.throw(type, value, traceback)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\errors.py”, line 617, in new_error_context
six.reraise(type(newerr), newerr, tb)
File “C:\Users\shcor\Anaconda3\lib\site-packages\numba\six.py”, line 659, in reraise
raise value
numba.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
‘NoneType’ object has no attribute ‘groups’

File “…\Anaconda3\lib\site-packages\quantecon\optimize\scalar_maximization.py”, line 50:
… def f(x):

if not np.isfinite(a):
raise ValueError(“a must be finite.”)
^

[1] During: lowering “raise <class ‘ValueError’>(‘a must be finite.’)” at C:\Users\shcor\Anaconda3\lib\site-packages\quantecon\optimize\scalar_maximization.py (50)
[2] During: resolving callee type: type(CPUDispatcher(<function brent_max at 0x000001EE0B8D5048>))
[3] During: typing of call at (30)

–%<----------------------------------------------------------------------------

File “”, line 30:
def T(v):

# Solve for optimal v at y
v_max = brent_max(objective, 1e-10, y, args=(v, y))[1]
^

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:

Thanks a lot in advance!

Hi @cryptopia, thanks for reporting.

There were some issues with a previous version of Anaconda (and Numba in particular).

Would you mind to install the latest version of Anaconda (personally, I just delete my existing one and install the latest version) and update the quantecon library (pip install --upgrade quantecon)?

After that I hope this problem will disappear. If not please let us know.

Regards, John.

Thank you so much for your very quick and useful comment!

I re-installed the newest version of Anaconda and the problem has completely disappeared.
(I tested on Jupyter Notebook and Visual Studio Code, both of which successfully worked as desired.)

I should have tried re-installing before asking (I’m sorry), but thanks anyway!

Thanks good news @cryptopia. All feedback is welcome so please let us know if you have more issues or suggestions.

Good luck with your studies. John.