Skip to content

Commit c0f08bf

Browse files
authored
Merge branch 'main' into copilot/fix-246
2 parents 65edbd0 + 3f3c493 commit c0f08bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+677
-533
lines changed

.github/workflows/cache.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ on:
33
schedule:
44
# Execute cache weekly at 3am on Monday
55
- cron: '0 3 * * 1'
6+
workflow_dispatch:
67
jobs:
78
tests:
89
runs-on: ubuntu-latest
910
steps:
1011
- name: Checkout
11-
uses: actions/checkout@v4
12+
uses: actions/checkout@v5
1213
- name: Setup Anaconda
1314
uses: conda-incubator/setup-miniconda@v3
1415
with:
1516
auto-update-conda: true
1617
auto-activate-base: true
1718
miniconda-version: 'latest'
18-
python-version: "3.12"
19+
python-version: "3.13"
1920
environment-file: environment.yml
2021
activate-environment: quantecon
2122
- name: Install latex dependencies

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout
10-
uses: actions/checkout@v4
10+
uses: actions/checkout@v5
1111
- name: Setup Anaconda
1212
uses: conda-incubator/setup-miniconda@v3
1313
with:
1414
auto-update-conda: true
1515
auto-activate-base: true
1616
miniconda-version: 'latest'
17-
python-version: "3.12"
17+
python-version: "3.13"
1818
environment-file: environment.yml
1919
activate-environment: quantecon
2020
- name: Install latex dependencies

.github/workflows/execution.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
os: ["ubuntu-latest"]
14-
python-version: ["3.12"]
14+
python-version: ["3.13"]
1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@v5
1818
- uses: conda-incubator/setup-miniconda@v3
1919
with:
2020
auto-update-conda: true
@@ -53,10 +53,10 @@ jobs:
5353
fail-fast: false
5454
matrix:
5555
os: ["macos-latest"]
56-
python-version: ["3.12"]
56+
python-version: ["3.13"]
5757
steps:
5858
- name: Checkout
59-
uses: actions/checkout@v4
59+
uses: actions/checkout@v5
6060
- uses: conda-incubator/setup-miniconda@v3
6161
with:
6262
auto-update-conda: true
@@ -85,7 +85,7 @@ jobs:
8585
# fail-fast: false
8686
# matrix:
8787
# os: ["windows-latest"]
88-
# python-version: ["3.11"]
88+
# python-version: ["3.13"]
8989
# steps:
9090
# - name: Checkout
9191
# uses: actions/checkout@v2

.github/workflows/linkcheck.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ jobs:
1313
steps:
1414
# Checkout the live site (html)
1515
- name: Checkout
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v5
1717
with:
1818
ref: gh-pages
1919
- name: Link Checker
2020
id: lychee
2121
uses: lycheeverse/lychee-action@v2
2222
with:
2323
fail: false
24-
args: --accept 403,503 **/*.html
24+
# Configuration is now specified in lychee.toml file
25+
args: **/*.html
2526
- name: Create Issue From File
2627
if: steps.lychee.outputs.exit_code != 0
2728
uses: peter-evans/create-issue-from-file@v5

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@v4
12+
uses: actions/checkout@v5
1313
- name: Setup Anaconda
1414
uses: conda-incubator/setup-miniconda@v3
1515
with:
1616
auto-update-conda: true
1717
auto-activate-base: true
1818
miniconda-version: 'latest'
19-
python-version: "3.12"
19+
python-version: "3.13"
2020
environment-file: environment.yml
2121
activate-environment: quantecon
2222
- name: Install latex dependencies

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
_build/
2-
.DS_Store
2+
.DS_Store
3+
.ipynb_checkpoints/
4+
.virtual_documents/

environment.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ name: quantecon
22
channels:
33
- default
44
dependencies:
5-
- python=3.12
6-
- anaconda=2024.10
5+
- python=3.13
6+
- anaconda=2025.06
77
- pip
88
- pip:
9-
- jupyter-book==1.0.3
9+
- jupyter-book==1.0.4post1
1010
- git+https://github.com/QuantEcon/quantecon-book-theme@copilot/fix-299
11-
- sphinx-tojupyter==0.3.0
11+
- sphinx-tojupyter==0.3.1
1212
- sphinxext-rediraffe==0.2.7
13-
- sphinx-reredirects==0.1.4
1413
- sphinx-exercise==1.0.1
15-
- sphinx-proof==0.2.0
16-
- ghp-import==1.1.0
17-
- sphinxcontrib-youtube==1.3.0 #Version 1.3.0 is required as quantecon-book-theme is only compatible with sphinx<=5
14+
- sphinx-proof==0.2.1
15+
- sphinxcontrib-youtube==1.4.1
1816
- sphinx-togglebutton==0.3.2
19-
# Docker Requirements
20-
- pytz
17+
- sphinx-reredirects==0.1.4
18+
2119

lectures/BCG_incomplete_mkts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ show up in differences in the two types of consumers’ demands for a
242242
typical firm’s bonds and equity, the only two assets that agents can now
243243
trade.
244244

245-
## Asset Markets
245+
## Asset markets
246246

247247
Markets are incomplete: *ex cathedra* we the model builders declare that only equities and bonds issued by representative
248248
firms can be traded.
@@ -548,7 +548,7 @@ $C$’s that appear in the pricing functions, then
548548
- $\check q = q(K,B)$ and
549549
$\check p = p(K,B)$.
550550

551-
## Pseudo Code
551+
## Pseudo code
552552

553553
Before displaying our Python code for computing a BCG incomplete markets equilibrium,
554554
we’ll sketch some pseudo code that describes its logical flow.

lectures/_static/lecture_specific/amss/recursive_allocation.py

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
1+
import numpy as np
2+
from numba import njit, prange
3+
from quantecon import optimize
4+
5+
@njit
6+
def get_grid_nodes(grid):
7+
"""
8+
Get the actual grid points from a grid tuple.
9+
"""
10+
x_min, x_max, x_num = grid
11+
return np.linspace(x_min, x_max, x_num)
12+
13+
@njit
14+
def linear_interp_1d_scalar(x_min, x_max, x_num, y_values, x_val):
15+
"""Helper function for scalar interpolation"""
16+
x_nodes = np.linspace(x_min, x_max, x_num)
17+
18+
# Extrapolation with linear extension
19+
if x_val <= x_nodes[0]:
20+
# Linear extrapolation using first two points
21+
if x_num >= 2:
22+
slope = (y_values[1] - y_values[0]) / (x_nodes[1] - x_nodes[0])
23+
return y_values[0] + slope * (x_val - x_nodes[0])
24+
else:
25+
return y_values[0]
26+
27+
if x_val >= x_nodes[-1]:
28+
# Linear extrapolation using last two points
29+
if x_num >= 2:
30+
slope = (y_values[-1] - y_values[-2]) / (x_nodes[-1] - x_nodes[-2])
31+
return y_values[-1] + slope * (x_val - x_nodes[-1])
32+
else:
33+
return y_values[-1]
34+
35+
# Binary search for the right interval
36+
left = 0
37+
right = x_num - 1
38+
while right - left > 1:
39+
mid = (left + right) // 2
40+
if x_nodes[mid] <= x_val:
41+
left = mid
42+
else:
43+
right = mid
44+
45+
# Linear interpolation
46+
x_left = x_nodes[left]
47+
x_right = x_nodes[right]
48+
y_left = y_values[left]
49+
y_right = y_values[right]
50+
51+
weight = (x_val - x_left) / (x_right - x_left)
52+
return y_left * (1 - weight) + y_right * weight
53+
54+
@njit
55+
def linear_interp_1d(x_grid, y_values, x_query):
56+
"""
57+
Perform 1D linear interpolation.
58+
"""
59+
x_min, x_max, x_num = x_grid
60+
return linear_interp_1d_scalar(x_min, x_max, x_num, y_values, x_query[0])
61+
162
class AMSS:
263
# WARNING: THE CODE IS EXTREMELY SENSITIVE TO CHOCIES OF PARAMETERS.
364
# DO NOT CHANGE THE PARAMETERS AND EXPECT IT TO WORK
@@ -78,6 +139,10 @@ def simulate(self, s_hist, b_0):
78139
pref = self.pref
79140
x_grid, g, β, S = self.x_grid, self.g, self.β, self.S
80141
σ_v_star, σ_w_star = self.σ_v_star, self.σ_w_star
142+
Π = self.Π
143+
144+
# Extract the grid tuple from the list
145+
grid_tuple = x_grid[0] if isinstance(x_grid, list) else x_grid
81146

82147
T = len(s_hist)
83148
s_0 = s_hist[0]
@@ -111,8 +176,8 @@ def simulate(self, s_hist, b_0):
111176
T = np.zeros(S)
112177
for s in range(S):
113178
x_arr = np.array([x_])
114-
l[s] = eval_linear(x_grid, σ_v_star[s_, :, s], x_arr)
115-
T[s] = eval_linear(x_grid, σ_v_star[s_, :, S+s], x_arr)
179+
l[s] = linear_interp_1d(grid_tuple, σ_v_star[s_, :, s], x_arr)
180+
T[s] = linear_interp_1d(grid_tuple, σ_v_star[s_, :, S+s], x_arr)
116181

117182
c = (1 - l) - g
118183
u_c = pref.Uc(c, l)
@@ -135,6 +200,8 @@ def simulate(self, s_hist, b_0):
135200

136201
def obj_factory(Π, β, x_grid, g):
137202
S = len(Π)
203+
# Extract the grid tuple from the list
204+
grid_tuple = x_grid[0] if isinstance(x_grid, list) else x_grid
138205

139206
@njit
140207
def obj_V(σ, state, V, pref):
@@ -152,7 +219,7 @@ def obj_V(σ, state, V, pref):
152219
V_next = np.zeros(S)
153220

154221
for s in range(S):
155-
V_next[s] = eval_linear(x_grid, V[s], np.array([x[s]]))
222+
V_next[s] = linear_interp_1d(grid_tuple, V[s], np.array([x[s]]))
156223

157224
out = Π[s_] @ (pref.U(c, l) + β * V_next)
158225

@@ -167,7 +234,7 @@ def obj_W(σ, state, V, pref):
167234
c = (1 - l) - g[s_]
168235
x = -pref.Uc(c, l) * (c - T - b_0) + pref.Ul(c, l) * (1 - l)
169236

170-
V_next = eval_linear(x_grid, V[s_], np.array([x]))
237+
V_next = linear_interp_1d(grid_tuple, V[s_], np.array([x]))
171238

172239
out = pref.U(c, l) + β * V_next
173240

@@ -178,9 +245,11 @@ def obj_W(σ, state, V, pref):
178245

179246
def bellman_operator_factory(Π, β, x_grid, g, bounds_v):
180247
obj_V, obj_W = obj_factory(Π, β, x_grid, g)
181-
n = x_grid[0][2]
248+
# Extract the grid tuple from the list
249+
grid_tuple = x_grid[0] if isinstance(x_grid, list) else x_grid
250+
n = grid_tuple[2]
182251
S = len(Π)
183-
x_nodes = nodes(x_grid)
252+
x_nodes = get_grid_nodes(grid_tuple)
184253

185254
@njit(parallel=True)
186255
def T_v(V, V_new, σ_star, pref):
@@ -209,4 +278,4 @@ def T_w(W, σ_star, V, b_0, pref):
209278
W[s_] = res.fun
210279
σ_star[s_] = res.x
211280

212-
return T_v, T_w
281+
return T_v, T_w

lectures/_static/lecture_specific/amss2/recursive_allocation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def objf(z):
230230
def objf_prime(x):
231231

232232
epsilon = 1e-7
233-
x0 = np.asfarray(x)
233+
x0 = np.asarray(x, dtype=float)
234234
f0 = np.atleast_1d(objf(x0))
235235
jac = np.zeros([len(x0), len(f0)])
236236
dx = np.zeros(len(x0))

0 commit comments

Comments
 (0)