Skip to content

quantecon_wasm has no Timer and no timeit, so qe.Timer() cannot run in a wasm lecture #12

Description

@mmcky

quantecon_wasm exposes only the Matlab-like timers. Timer and timeit — the API the lectures have standardised on and the one the style guide mandates — are absent, so qe.Timer() raises AttributeError in a wasm build.

Current state

quantecon_wasm/util/__init__.py ends at:

from .timing import tic, tac, toc, loop_timer

and quantecon_wasm/util/timing.py defines exactly __Timer__, tic, tac, toc, loop_timer. There is no Timer class and no timeit. The package also has no quantecon_wasm/timings/ directory, which upstream Timer depends on for get_default_precision — so this is a two-part port, not a single-file copy.

Why the gap exists

version last commit
QuantEcon.py-wasm v0.7.2-1 2025-01-24
QuantEcon.py v0.11.4 current

Timer landed upstream in QuantEcon/QuantEcon.py#783 (2025-08-16) and timeit in QuantEcon/QuantEcon.py#794 (2025-08-27) — both after this package's last commit, so it never had the chance to pick them up. This is a concrete instance of the drift that #3 is about.

Why it matters now, not later

The collision is scheduled rather than hypothetical. lecture-wasm imports quantecon_wasm as qe in 4 lectures, and the series mirrors lecture-python-intro, where the style rule qe-code-004 ("use the quantecon.Timer context manager") targets timing magics that are still present in the mirrored copies:

lecture-wasm file timing magics awaiting conversion
lectures/monte_carlo.md 8 (%%time)
lectures/inequality.md 2 (%%time)
lectures/markov_chains_I.md 2 (%time)

The moment any of those is converted upstream and synced, the wasm build breaks on qe.Timer(). QuantEcon/compliance-lecture-style already carries the recommendation to convert them.

Separately, QuantEcon/QuantEcon.py#833 deprecates tic/tac/toc/loop_timer upstream (step 1 of QuantEcon/QuantEcon.py#786; removal targeted at v1.0). That PR does not affect this package — the fork has its own copy of timing.py with no warning — but when step 2 removes those functions upstream, this package becomes the only place in the org still carrying them, and the two APIs diverge in both directions at once: quantecon will have Timer/timeit and no tic/toc, quantecon_wasm the exact opposite.

Suggested scope

  1. Port quantecon/timings/ (__init__.py, timings.py) to quantecon_wasm/timings/.
  2. Port Timer and timeit from quantecon/util/timing.py into quantecon_wasm/util/timing.py, and export both from quantecon_wasm/util/__init__.py.
  3. Port the corresponding TestTimer / timeit cases into quantecon_wasm/util/tests/test_timing.py.
  4. Keep tic/tac/toc/loop_timer in place for now — nothing in wasm calls them, and removing them is a separate decision that should follow upstream's step 2 rather than lead it.

Worth checking during the port whether anything in Timer/timeit relies on behaviour Pyodide does not provide; time.perf_counter is available under Pyodide, but that is the thing to confirm rather than assume.

How this surfaced

An audit of whether QuantEcon/QuantEcon.py#833 would affect the lecture series. It does not — all nine repos in the lectures workspace manifest are clean of the deprecated timers — but the sweep turned up this package as the one place in the org whose timing API cannot follow the lectures. lecture-wasm uses neither API today, so nothing is broken right now.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions