Open chicoutimy opened 2 years ago
Hi! The code runs correctly in python 3.8 versions but i'm having the same problem as @chicoutimy with a 3.9 version. Still don't know why...
Hi,
Yes, it seems like numba.vectorize
that we use when solving for the constrained households' labor supply decision does not work properly for some (new) versions of numba. It seems that this problem only arises on Windows machines (correct me if you have Mac or Linux).
There are two workarounds.
njit
-ed loop over the gridpoints where the borrowing constraint binds. This will achieve similar speed at the cost of less elegant code.Hope this helps!
Hi,
I tried to look into this problem.
Background: I used Windows 11 and Python 3.8.15 as I downgraded following Bence's comment. It turned out that this did not resolve the problem. My old laptop with Python 3.7.3 did not have the problem. The update with which the problem came must be in between I suppose.
Findings:
The vectorize decorator works fine. Replacing it with native python code (an extra outer loop) leaves the problem unchanged.
It turns out that the problem is the following: the njit-ed netexp() function calls the also njit-ed cn() function. Somehow this leads to not well-defined behavior. I am not sure why but maybe a numba expert could tell. It is quite easy to see this problem in debug mode by manually going through the loop in solve_uc().
Solution: Just use the following netexp() function that does not call cn():
@njit
def netexp(log_uc, w, T, eis, frisch, vphi):
uc = np.exp(log_uc)
c = uc ** (-eis)
n = (w * uc / vphi) ** frisch
ne = c - w * n - T
# c and n have elasticities of -eis and frisch wrt log u'(c)
c_loguc = -eis * c
n_loguc = frisch * n
netexp_loguc = c_loguc - w * n_loguc
return ne, netexp_loguc
The only (trivial) change I made is to copy and paste the first 3 lines instead of calling the cn() function.
Hope this helps!
Hmm, interesting. I nest njit-ed functions all the time. But then again, I haven't experienced this issue in the first place.
Has @lukas-hack 's solution worked for everybody here since 2022?
High, I am following Tutorial 3 to solve the one-asset HANK model. The code runs smoothly until line 8, but when I go ahead and run line 9
I get the following error message:
Do you know what is going on? Am I am doing something wrong? Thanks for your help and congrats on the wonderful toolbox! chicoutimy