Skip to content

Commit 9ec9e13

Browse files
authored
MAINT: update @jit(nopython=True) to @jit with numba>=0.59 (#395)
* MAINT: update @jit(nopython=True) to @jit with numba>=0.59 * update @njit to @jit * update imports njit to jit and usage * minor fixes for import * remove njit from cass_koopmans_1 * remove njit from ak2
1 parent bc7a5cb commit 9ec9e13

31 files changed

+150
-150
lines changed

lectures/aiyagari.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class Household:
283283
284284
# Do the hard work using JIT-ed functions
285285
286-
@jit(nopython=True)
286+
@jit
287287
def populate_R(R, a_size, z_size, a_vals, z_vals, r, w):
288288
n = a_size * z_size
289289
for s_i in range(n):
@@ -297,7 +297,7 @@ def populate_R(R, a_size, z_size, a_vals, z_vals, r, w):
297297
if c > 0:
298298
R[s_i, new_a_i] = np.log(c) # Utility
299299
300-
@jit(nopython=True)
300+
@jit
301301
def populate_Q(Q, a_size, z_size, Π):
302302
n = a_size * z_size
303303
for s_i in range(n):
@@ -307,7 +307,7 @@ def populate_Q(Q, a_size, z_size, Π):
307307
Q[s_i, a_i, a_i*z_size + next_z_i] = Π[z_i, next_z_i]
308308
309309
310-
@jit(nopython=True)
310+
@jit
311311
def asset_marginal(s_probs, a_size, z_size):
312312
a_probs = np.zeros(a_size)
313313
for a_i in range(a_size):

lectures/ak2.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ $$
408408
```{code-cell} ipython3
409409
import numpy as np
410410
import matplotlib.pyplot as plt
411-
from numba import njit
411+
from numba import jit
412412
from quantecon.optimize import brent_max
413413
```
414414
@@ -433,22 +433,22 @@ Knowing $\hat K$, we can calculate other equilibrium objects.
433433
Let's first define some Python helper functions.
434434
435435
```{code-cell} ipython3
436-
@njit
436+
@jit
437437
def K_to_Y(K, α):
438438
439439
return K ** α
440440
441-
@njit
441+
@jit
442442
def K_to_r(K, α):
443443
444444
return α * K ** (α - 1)
445445
446-
@njit
446+
@jit
447447
def K_to_W(K, α):
448448
449449
return (1 - α) * K ** α
450450
451-
@njit
451+
@jit
452452
def K_to_C(K, D, τ, r, α, β):
453453
454454
# optimal consumption for the old when δ=0
@@ -913,7 +913,7 @@ Let's implement this "guess and verify" approach
913913
We start by defining the Cobb-Douglas utility function
914914
915915
```{code-cell} ipython3
916-
@njit
916+
@jit
917917
def U(Cy, Co, β):
918918
919919
return (Cy ** β) * (Co ** (1-β))
@@ -924,7 +924,7 @@ We use `Cy_val` to compute the lifetime value of an arbitrary consumption plan,
924924
Note that it requires knowing future prices $r_{t+1}$ and tax rate $\tau_{t+1}$.
925925
926926
```{code-cell} ipython3
927-
@njit
927+
@jit
928928
def Cy_val(Cy, W, r_next, τ, τ_next, δy, δo_next, β):
929929
930930
# Co given by the budget constraint

lectures/career.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import matplotlib.pyplot as plt
5151
plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
5252
import numpy as np
5353
import quantecon as qe
54-
from numba import njit, prange
54+
from numba import jit, prange
5555
from quantecon.distributions import BetaBinomial
5656
from scipy.special import binom, beta
5757
from mpl_toolkits.mplot3d.axes3d import Axes3D
@@ -234,7 +234,7 @@ def operator_factory(cw, parallel_flag=True):
234234
F_probs, G_probs = cw.F_probs, cw.G_probs
235235
F_mean, G_mean = cw.F_mean, cw.G_mean
236236
237-
@njit(parallel=parallel_flag)
237+
@jit(parallel=parallel_flag)
238238
def T(v):
239239
"The Bellman operator"
240240
@@ -249,7 +249,7 @@ def operator_factory(cw, parallel_flag=True):
249249
250250
return v_new
251251
252-
@njit
252+
@jit
253253
def get_greedy(v):
254254
"Computes the v-greedy policy"
255255
@@ -472,7 +472,7 @@ T, get_greedy = operator_factory(cw)
472472
v_star = solve_model(cw, verbose=False)
473473
greedy_star = get_greedy(v_star)
474474
475-
@njit
475+
@jit
476476
def passage_time(optimal_policy, F, G):
477477
t = 0
478478
i = j = 0
@@ -485,7 +485,7 @@ def passage_time(optimal_policy, F, G):
485485
i, j = qe.random.draw(F), qe.random.draw(G)
486486
t += 1
487487
488-
@njit(parallel=True)
488+
@jit(parallel=True)
489489
def median_time(optimal_policy, F, G, M=25000):
490490
samples = np.empty(M)
491491
for i in prange(M):

lectures/cass_koopmans_1.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.16.1
7+
jupytext_version: 1.16.4
88
kernelspec:
99
display_name: Python 3 (ipykernel)
1010
language: python
@@ -66,7 +66,7 @@ Let's start with some standard imports:
6666

6767
```{code-cell} ipython3
6868
import matplotlib.pyplot as plt
69-
from numba import njit, float64
69+
from numba import jit, float64
7070
from numba.experimental import jitclass
7171
import numpy as np
7272
from quantecon.optimize import brentq
@@ -525,7 +525,7 @@ planning problem.
525525
$c_0$ instead of $\mu_0$ in the following code.)
526526
527527
```{code-cell} ipython3
528-
@njit
528+
@jit
529529
def shooting(pp, c0, k0, T=10):
530530
'''
531531
Given the initial condition of capital k0 and an initial guess
@@ -610,7 +610,7 @@ When $K_{T+1}$ gets close enough to $0$ (i.e., within an error
610610
tolerance bounds), we stop.
611611
612612
```{code-cell} ipython3
613-
@njit
613+
@jit
614614
def bisection(pp, c0, k0, T=10, tol=1e-4, max_iter=500, k_ter=0, verbose=True):
615615
616616
# initial boundaries for guess c0
@@ -804,7 +804,7 @@ over time.
804804
Let's calculate and plot the saving rate.
805805
806806
```{code-cell} ipython3
807-
@njit
807+
@jit
808808
def saving_rate(pp, c_path, k_path):
809809
'Given paths of c and k, computes the path of saving rate.'
810810
production = pp.f(k_path[:-1])
@@ -912,7 +912,7 @@ $$ (eq:tildeC)
912912
A positive fixed point $C = \tilde C(K)$ exists only if $f\left(K\right)+\left(1-\delta\right)K-f^{\prime-1}\left(\frac{1}{\beta}-\left(1-\delta\right)\right)>0$
913913
914914
```{code-cell} ipython3
915-
@njit
915+
@jit
916916
def C_tilde(K, pp):
917917
918918
return pp.f(K) + (1 - pp.δ) * K - pp.f_prime_inv(1 / pp.β - 1 + pp.δ)
@@ -931,11 +931,11 @@ K = \tilde K(C)
931931
$$ (eq:tildeK)
932932
933933
```{code-cell} ipython3
934-
@njit
934+
@jit
935935
def K_diff(K, C, pp):
936936
return pp.f(K) - pp.δ * K - C
937937
938-
@njit
938+
@jit
939939
def K_tilde(C, pp):
940940
941941
res = brentq(K_diff, 1e-6, 100, args=(C, pp))
@@ -951,7 +951,7 @@ It is thus the intersection of the two curves $\tilde{C}$ and $\tilde{K}$ that w
951951
We can compute $K_s$ by solving the equation $K_s = \tilde{K}\left(\tilde{C}\left(K_s\right)\right)$
952952
953953
```{code-cell} ipython3
954-
@njit
954+
@jit
955955
def K_tilde_diff(K, pp):
956956
957957
K_out = K_tilde(C_tilde(K, pp), pp)
@@ -1003,7 +1003,7 @@ In addition to the three curves, Figure {numref}`stable_manifold` plots arrows
10031003
---
10041004
mystnb:
10051005
figure:
1006-
caption: "Stable Manifold and Phase Plane"
1006+
caption: Stable Manifold and Phase Plane
10071007
name: stable_manifold
10081008
tags: [hide-input]
10091009
---

lectures/cass_koopmans_2.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Let's start with some standard imports:
6868
```{code-cell} ipython
6969
import matplotlib.pyplot as plt
7070
plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
71-
from numba import njit, float64
71+
from numba import jit, float64
7272
from numba.experimental import jitclass
7373
import numpy as np
7474
```
@@ -751,7 +751,7 @@ class PlanningProblem():
751751
```
752752

753753
```{code-cell} python3
754-
@njit
754+
@jit
755755
def shooting(pp, c0, k0, T=10):
756756
'''
757757
Given the initial condition of capital k0 and an initial guess
@@ -779,7 +779,7 @@ def shooting(pp, c0, k0, T=10):
779779
```
780780

781781
```{code-cell} python3
782-
@njit
782+
@jit
783783
def bisection(pp, c0, k0, T=10, tol=1e-4, max_iter=500, k_ter=0, verbose=True):
784784
785785
# initial boundaries for guess c0
@@ -828,7 +828,7 @@ The above code from this lecture {doc}`Cass-Koopmans Planning Model <cass_koopma
828828
Now we're ready to bring in Python code that we require to compute additional objects that appear in a competitive equilibrium.
829829

830830
```{code-cell} python3
831-
@njit
831+
@jit
832832
def q(pp, c_path):
833833
# Here we choose numeraire to be u'(c_0) -- this is q^(t_0)_t
834834
T = len(c_path) - 1
@@ -838,12 +838,12 @@ def q(pp, c_path):
838838
q_path[t] = pp.β ** t * pp.u_prime(c_path[t])
839839
return q_path
840840
841-
@njit
841+
@jit
842842
def w(pp, k_path):
843843
w_path = pp.f(k_path) - k_path * pp.f_prime(k_path)
844844
return w_path
845845
846-
@njit
846+
@jit
847847
def η(pp, k_path):
848848
η_path = pp.f_prime(k_path)
849849
return η_path
@@ -953,7 +953,7 @@ years, and define a new function for $r$, then plot both.
953953
We begin by continuing to assume that $t_0=0$ and plot things for different maturities $t=T$, with $K_0$ below the steady state
954954

955955
```{code-cell} python3
956-
@njit
956+
@jit
957957
def q_generic(pp, t0, c_path):
958958
# simplify notations
959959
β = pp.β
@@ -966,7 +966,7 @@ def q_generic(pp, t0, c_path):
966966
q_path[t-t0] = β ** (t-t0) * u_prime(c_path[t]) / u_prime(c_path[t0])
967967
return q_path
968968
969-
@njit
969+
@jit
970970
def r(pp, t0, q_path):
971971
'''Yield to maturity'''
972972
r_path = - np.log(q_path[1:]) / np.arange(1, len(q_path))

lectures/coleman_policy_iter.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Let's start with some imports:
6363
import matplotlib.pyplot as plt
6464
import numpy as np
6565
from quantecon.optimize import brentq
66-
from numba import njit
66+
from numba import jit
6767
```
6868

6969
## The Euler Equation
@@ -286,7 +286,7 @@ u'(c) - \beta \int (u' \circ \sigma) (f(y - c) z ) f'(y - c) z \phi(dz)
286286
```
287287

288288
```{code-cell} ipython
289-
@njit
289+
@jit
290290
def euler_diff(c, σ, y, og):
291291
"""
292292
Set up a function such that the root with respect to c,
@@ -314,7 +314,7 @@ state $y$ and $σ$, the current guess of the policy.
314314
Here's the operator $K$, that implements the root-finding step.
315315

316316
```{code-cell} ipython3
317-
@njit
317+
@jit
318318
def K(σ, og):
319319
"""
320320
The Coleman-Reffett operator

lectures/egm_policy_iter.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Let's start with some standard imports:
4444
```{code-cell} ipython
4545
import matplotlib.pyplot as plt
4646
import numpy as np
47-
from numba import njit
47+
from numba import jit
4848
```
4949

5050
## Key Idea
@@ -161,7 +161,7 @@ We reuse the `OptimalGrowthModel` class
161161
Here's an implementation of $K$ using EGM as described above.
162162

163163
```{code-cell} python3
164-
@njit
164+
@jit
165165
def K(σ_array, og):
166166
"""
167167
The Coleman-Reffett operator using EGM

lectures/eig_circulant.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ We begin by importing some Python packages
3131

3232
```{code-cell} ipython3
3333
import numpy as np
34-
from numba import njit
34+
from numba import jit
3535
import matplotlib.pyplot as plt
3636
```
3737

@@ -66,7 +66,7 @@ first column needs to be specified.
6666
Let's write some Python code to generate a circulant matrix.
6767
6868
```{code-cell} ipython3
69-
@njit
69+
@jit
7070
def construct_cirlulant(row):
7171
7272
N = row.size
@@ -200,7 +200,7 @@ $$
200200
Let's write some Python code to illustrate these ideas.
201201
202202
```{code-cell} ipython3
203-
@njit
203+
@jit
204204
def construct_P(N):
205205
206206
P = np.zeros((N, N))

0 commit comments

Comments
 (0)