[markov_asset] Update to JAX and runtime comparison#654
Conversation
|
📖 Netlify Preview Ready! Preview URL: https://pr-654--sunny-cactus-210e3e.netlify.app (0317e4a) 📚 Changed Lecture Pages: harrison_kreps, markov_asset, two_auctions |
|
📖 Netlify Preview Ready! Preview URL: https://pr-654--sunny-cactus-210e3e.netlify.app (76c64b2) 📚 Changed Lecture Pages: harrison_kreps, markov_asset, two_auctions |
|
📖 Netlify Preview Ready! Preview URL: https://pr-654--sunny-cactus-210e3e.netlify.app (02dfe6e) 📚 Changed Lecture Pages: harrison_kreps, markov_asset, two_auctions |
|
📖 Netlify Preview Ready! Preview URL: https://pr-654--sunny-cactus-210e3e.netlify.app (211ec24) 📚 Changed Lecture Pages: harrison_kreps, markov_asset, two_auctions |
|
📖 Netlify Preview Ready! Preview URL: https://pr-654--sunny-cactus-210e3e.netlify.app (cb2995a) 📚 Changed Lecture Pages: markov_asset |
|
📖 Netlify Preview Ready! Preview URL: https://pr-654--sunny-cactus-210e3e.netlify.app (4adc2f5) 📚 Changed Lecture Pages: markov_asset |
|
📖 Netlify Preview Ready! Preview URL: https://pr-654--sunny-cactus-210e3e.netlify.app (e47f942) 📚 Changed Lecture Pages: markov_asset, markov_asset_numpy |
|
🤖 Status note for a future session — from a maintainer investigation on 2026-07-08 into why open-PR previews 404. Context only, not instructions. Netlify preview: https://pr-654--sunny-cactus-210e3e.netlify.app/ currently returns 404. Why previews are down (repo-wide findings)1. This branch is stale — 164 commits behind 2. The arviz failure was a red herring — do NOT pin arviz or rewrite plotting. A 2026-07-07 rebuild also failed in Note on recent timeline activityThis PR was close/reopened on 2026-07-07 by a maintainer session purely to trigger a rebuild test — not a content change. That rebuild failed on the stale-branch issue above. Apologies for the notification churn. Recommended first step for this PRUpdate this branch to This PR touches: |
📖 Netlify Preview Ready!Preview URL: https://pr-654--sunny-cactus-210e3e.netlify.app Commit: 📚 Changed LecturesBuild Info
|
| # Compute option price | ||
| p = consol_price(ap, ζ) | ||
| w = np.zeros(ap.n) | ||
| err.throw() |
There was a problem hiding this comment.
This seems to be added by mistake.
|
Many thanks @xuanguang-li , much appreciated. By the way, you added a file to this PR that I assume is a mistake: https://github.com/QuantEcon/lecture-python.myst/pull/654/changes#diff-200962c576f4fdd31f65eea1717388dafb176a3bb5ec8630dbe0840a61f49f57 You can leave this PR with me. I'll add any necessary fixes and then merge it. |
|
Hi @xuanguang-li . (CC @mmcky @HumphreyYang ) I've now reviewed this carefully, including testing with Claude on my CPU and GPU. I always ask Claude to read our current style guide before assessing. Here it recommends keeping the lecture in NumPy and I agree. JAX is slower on the GPU, and only somewhat faster if we pin it to using the CPU. This comes at some readability cost, with the pin to the CPU, lax.while loop, etc. For that reason, I've decided to close the PR without merging. This lecture can stay in NumPy. FYI, here is Claude's report: The GPU is ~5–6× slower than NumPy for this lecture, plus a ~0.3 s one-time compile hit. Root cause: call_option's jax.lax.while_loop This resolves the apparent contradiction with the PR description (which reported GPU as fastest): that benchmark was almost certainly Bottom line: this empirically confirms style-guide point #4 — markov_asset is not computationally intensive (tiny 25×25 / 5×5 My recommendation to you I'd lean toward not converting this lecture to JAX at all — keep it NumPy per the style guide's explicit carve-out — rather than |
This pull request modernizes the
markov_asset.mdnotebook by refactoring the codebase to use JAX and JAX NumPy.numpyandnumpy.linalgtojax.numpyandjax.numpy.linalg.AssetPriceModelclass with an immutable, type-safeNamedTupleversion and introduced acreate_ap_modelfactory function for consistent construction.jax.lax.while_loopandjax.lax.fori_loop.Update: Runtime Comparison Between
JAX (GPU),JAX (CPU), andNumPyMethodology:
JAXversion uses the code in this PR, while theNumPyversion uses the code inmain.JAX (GPU)is measured using Google Colab.qe.timeitover 1,000 iterations.Results:
JAX (CPU)>NumPy>JAX (GPU).