From 292a208a11993a68e7b2f0aec61c1b65f60cf9f4 Mon Sep 17 00:00:00 2001 From: Dev Kumar Date: Tue, 7 Jul 2026 00:40:13 -0500 Subject: [PATCH 1/2] chore: replace deprecated tic/toc timers with qe.Timer in kesten_processes --- lectures/kesten_processes.md | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/lectures/kesten_processes.md b/lectures/kesten_processes.md index 4dfb235a..90516051 100644 --- a/lectures/kesten_processes.md +++ b/lectures/kesten_processes.md @@ -56,7 +56,6 @@ import jax import jax.numpy as jnp from jax import random from jax import lax -from quantecon import tic, toc from typing import NamedTuple from functools import partial ``` @@ -235,17 +234,15 @@ Let's try running the code and generating a cross-section. ```{code-cell} ipython3 firm = Firm() -tic() -data = generate_cross_section(firm).block_until_ready() -toc() +with qe.Timer(): + data = generate_cross_section(firm).block_until_ready() ``` We run the function again so we can see the speed without compile time. ```{code-cell} ipython3 -tic() -data = generate_cross_section(firm).block_until_ready() -toc() +with qe.Timer(): + data = generate_cross_section(firm).block_until_ready() ``` Let's produce the rank-size plot and check the distribution: @@ -299,7 +296,7 @@ def generate_cross_section_lax( # Exponentiate them a, b, e = jax.tree.map(jnp.exp, (a, b, e)) # Update the cross-section of firms - s = jnp.where(s < s_bar, e, a * s + b) + s = jnp.where(s < s_bar, e_t, a_t * s + b_t) new_state = s, key return new_state @@ -314,15 +311,13 @@ def generate_cross_section_lax( Let's see if we get any speed gain ```{code-cell} ipython3 -tic() -data = generate_cross_section_lax(firm).block_until_ready() -toc() +with qe.Timer(): + data = generate_cross_section_lax(firm).block_until_ready() ``` ```{code-cell} ipython3 -tic() -data = generate_cross_section_lax(firm).block_until_ready() -toc() +with qe.Timer(): + data = generate_cross_section_lax(firm).block_until_ready() ``` Here we produce the same rank-size plot: @@ -393,15 +388,13 @@ def generate_cross_section_lax( Here are the run times. ```{code-cell} ipython3 -tic() -data = generate_cross_section_lax(firm).block_until_ready() -toc() +with qe.Timer(): + data = generate_cross_section_lax(firm).block_until_ready() ``` ```{code-cell} ipython3 -tic() -data = generate_cross_section_lax(firm).block_until_ready() -toc() +with qe.Timer(): + data = generate_cross_section_lax(firm).block_until_ready() ``` This method might or might not be faster. From c7310da02e7d371d6a17b238ef47958afa006fc9 Mon Sep 17 00:00:00 2001 From: John Stachurski Date: Tue, 14 Jul 2026 11:58:09 +0900 Subject: [PATCH 2/2] Fix accidental undefined e_t/a_t/b_t in first generate_cross_section_lax The timer swap accidentally changed the first generate_cross_section_lax's inner update to reference e_t/a_t/b_t, which are undefined in that function (it binds a, b, e via jax.tree.map). This caused a NameError at execution. Restore the correct e, a, b variables. The second function's e_t/a_t/b_t usage is legitimate and left unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- lectures/kesten_processes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lectures/kesten_processes.md b/lectures/kesten_processes.md index 90516051..37548d37 100644 --- a/lectures/kesten_processes.md +++ b/lectures/kesten_processes.md @@ -296,7 +296,7 @@ def generate_cross_section_lax( # Exponentiate them a, b, e = jax.tree.map(jnp.exp, (a, b, e)) # Update the cross-section of firms - s = jnp.where(s < s_bar, e_t, a_t * s + b_t) + s = jnp.where(s < s_bar, e, a * s + b) new_state = s, key return new_state