Skip to content

Replace deprecated tic/toc timers with qe.Timer in kesten_processes - #330

Merged
jstac merged 2 commits into
QuantEcon:mainfrom
devthedevil:fix/kesten-processes-qe-timer
Jul 14, 2026
Merged

Replace deprecated tic/toc timers with qe.Timer in kesten_processes#330
jstac merged 2 commits into
QuantEcon:mainfrom
devthedevil:fix/kesten-processes-qe-timer

Conversation

@devthedevil

Copy link
Copy Markdown
Contributor

Summary

Closes #329.

quantecon is deprecating the Matlab-like tic/tac/toc timers in favour of the Timer context manager (QuantEcon/QuantEcon.py#833). lectures/kesten_processes.md was the only lecture in this repo still using the old API.

Change

  • Dropped the now-unused from quantecon import tic, toc import (the lecture already does import quantecon as qe).
  • Replaced all six tic() / toc() pairs wrapping a single timed call with the equivalent with qe.Timer(): context manager, e.g.:
# before
tic()
data = generate_cross_section(firm).block_until_ready()
toc()

# after
with qe.Timer():
    data = generate_cross_section(firm).block_until_ready()

This is a purely mechanical, behavior-preserving swap — qe.Timer() prints elapsed time on exit by default, matching toc()'s existing behavior.

Testing

This is a documentation/lecture source file (no associated unit tests). Verified by inspecting the quantecon.util.timing.Timer context-manager implementation upstream to confirm with qe.Timer(): is a drop-in replacement for the tic()/toc() pair used here.

@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploy Preview for incomparable-parfait-2417f8 ready!

Name Link
🔨 Latest commit c7310da
🔍 Latest deploy log https://app.netlify.com/projects/incomparable-parfait-2417f8/deploys/6a55a5c5f993c6000835fd1f
😎 Deploy Preview https://deploy-preview-330--incomparable-parfait-2417f8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread lectures/kesten_processes.md Outdated
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devthedevil I don't think this is correct unless we update variables elsewhere. Please review

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) <noreply@anthropic.com>
@jstac

jstac commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Thanks @devthedevil! I pushed a small maintainer fix (c7310da) alongside the timer swap.

The diff had also changed one line in the first generate_cross_section_lax:

-        s = jnp.where(s < s_bar, e_t, a_t * s + b_t)
+        s = jnp.where(s < s_bar, e, a * s + b)

In that first version, the inner update_cross_section binds a, b, e (via jax.tree.map(jnp.exp, (a, b, e))), so e_t/a_t/b_t are undefined there — it would have raised a NameError when the lecture executes during the build. (The e_t/a_t/b_t in the second generate_cross_section_lax are fine, since that one defines a_t, b_t, e_t = a[t], b[t], e[t] — I left it untouched.)

Otherwise the tic/toc → qe.Timer() change looks great. This just needs a maintainer to approve the CI workflow run.

@jstac

jstac commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

@mmcky should be good to merge when ready — the tic/toc → qe.Timer() swap plus the one-line fix (c7310da) for the undefined e_t/a_t/b_t in the first generate_cross_section_lax. Just needs a maintainer to approve the CI workflow run and confirm it's green.

@jstac
jstac merged commit a4722af into QuantEcon:main Jul 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace deprecated tic/toc timers with qe.Timer in kesten_processes

3 participants