Skip to content

[mccall_model] JAX conversion of the Job Search Model I#619

Open
longye-tian wants to merge 12 commits into
mainfrom
job_1
Open

[mccall_model] JAX conversion of the Job Search Model I#619
longye-tian wants to merge 12 commits into
mainfrom
job_1

Conversation

@longye-tian

Copy link
Copy Markdown
Contributor

I've updated the Job Search Model I, align with the change we've had before on Job Search Model II and III.

Overview

Converted lectures/mccall_model.md from NumPy/Numba to JAX implementation, following the patterns established in mccall_model_with_separation.md and mccall_fitted_vfi.md.

Key Changes

1. Library Updates

  • Replaced: numpyjax.numpy (jnp)
  • Replaced: numba.jitjax.jit
  • Removed: numba.experimental.jitclass
  • Added: jax, jax.numpy, typing.NamedTuple

2. Data Structure Changes

  • Before: Used Numba's @jitclass for the McCall model class
  • After: Used NamedTuple for immutable model structure, compatible with JAX's functional paradigm

3. Array Operations

  • Converted: All NumPy arrays to JAX arrays (jnp)
  • Updated: Array mutations to use JAX's functional update syntax (.at[].set())

4. Loop Transformations

  • Before: Standard Python while loops with Numba JIT
  • After: jax.lax.while_loop with condition and body functions

5. Random Number Generation

  • Before: NumPy's global random state (np.random.seed())
  • After: JAX's explicit PRNG key system (jax.random.PRNGKey)

6. Vectorization

  • Before: Manual loops over parameter grids
  • After: jax.vmap for automatic vectorization

@HumphreyYang

Copy link
Copy Markdown
Member

Many thanks @longye-tian!

I thought @shlff self-assigned this lecture in the issue here: QuantEcon/meta#173.

Just CCing @shlff here so we are not working on the same lecture separately : )

@longye-tian

Copy link
Copy Markdown
Contributor Author

Many thanks @longye-tian!

I thought @shlff self-assigned this lecture in the issue here: QuantEcon/meta#173.

Just CCing @shlff here so we are not working on the same lecture separately : )

Thank you for your notice @HumphreyYang .

So Sorry @shlff . I forgot to check this list...

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (6f9619b)

📚 Changed Lecture Pages: mccall_model

@longye-tian longye-tian marked this pull request as ready for review September 17, 2025 03:49

@HumphreyYang HumphreyYang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many thanks @longye-tian! Nice changes!!

Just some minor suggestions in the review.

Three minor general suggestions:

  1. There are some comments like this in the code:
    # == Now compute the reservation wage == #

It would be nice to convert them to more standard comments like

# Now compute the reservation wage
  1. We used jax.random many times. It might be a good idea to give it an alias in the import:
import jax.random as jr

and then use

jr.method_name()
  1. There are a few more lines that are longer than the box in the preview. It would be nice if you could follow the pattern in the review comment and cut them to fewer than 80 characters so they fit into the code cell in the preview nicely!

Comment thread lectures/mccall_model.md
Comment thread lectures/mccall_model.md Outdated
Comment thread lectures/mccall_model.md Outdated
Comment thread lectures/mccall_model.md Outdated
Comment thread lectures/mccall_model.md
Comment thread lectures/mccall_model.md
Comment thread lectures/mccall_model.md
Comment thread lectures/mccall_model.md
Comment thread lectures/mccall_model.md Outdated
longye-tian and others added 7 commits September 18, 2025 12:06
Co-authored-by: Humphrey Yang <39026988+HumphreyYang@users.noreply.github.com>
Co-authored-by: Humphrey Yang <39026988+HumphreyYang@users.noreply.github.com>
Co-authored-by: Humphrey Yang <39026988+HumphreyYang@users.noreply.github.com>
Co-authored-by: Humphrey Yang <39026988+HumphreyYang@users.noreply.github.com>
Co-authored-by: Humphrey Yang <39026988+HumphreyYang@users.noreply.github.com>
Co-authored-by: Humphrey Yang <39026988+HumphreyYang@users.noreply.github.com>
@longye-tian

Copy link
Copy Markdown
Contributor Author

Hi @HumphreyYang ,

Thank you for your detailed review. I've updated the lecture accordingly.

Best,
Longye

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (a1c0a5e)

📚 Changed Lecture Pages: mccall_model

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (94d2339)

📚 Changed Lecture Pages: mccall_model

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (01c5e80)

📚 Changed Lecture Pages: mccall_model

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (3711f5b)

📚 Changed Lecture Pages: mccall_model

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (1a748dc)

📚 Changed Lecture Pages: mccall_model

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (f66be67)

📚 Changed Lecture Pages: mccall_model

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (db5a05f)

📚 Changed Lecture Pages: mccall_model

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (75dc290)

📚 Changed Lecture Pages: mccall_model

Comment thread lectures/mccall_model.md
@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (d9cae86)

📚 Changed Lecture Pages: mccall_model

@longye-tian

Copy link
Copy Markdown
Contributor Author

Hi @mmcky ,

I've updated the lecture and revised according to very good suggestions from @HumphreyYang and @shlff .

What do you think?

Best,
Longye

@jstac

jstac commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

@mmcky FYI, I'm getting a 404 on the netlify link above.

I'll probably push some changes now, which might generate a fresh link that works.

@longye-tian @HumphreyYang Actually I disagree with import jax.random as jr, although I appreciate the suggestion. The only reason is that it's nonstandard, so requires a search if someone is trying to work out what it means.

I'll revert the change now and review the lecture.

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-619--sunny-cactus-210e3e.netlify.app (e75d48a)

📚 Changed Lecture Pages: mccall_model

@mmcky

mmcky commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

@mmcky FYI, I'm getting a 404 on the netlify link above.

thanks for reporting @jstac. I can't seem to replicate this on my end. The recent ones appear to work for me. Would you mind pasting the link that is 404'ing for you?

@HumphreyYang

HumphreyYang commented Oct 31, 2025

Copy link
Copy Markdown
Member

@longye-tian @HumphreyYang Actually I disagree with import jax.random as jr, although I appreciate the suggestion. The only reason is that it's nonstandard, so requires a search if someone is trying to work out what it means.

Many thanks @jstac, I think there is an entry in the style guide that suggests us to use import jax.random as jr so I proposed the change in this PR:
https://manual.quantecon.org/styleguide/jax-conversion.html#random-number-generation

I have opened a PR on this in the style sheet:
https://github.com/QuantEcon/QuantEcon.manual/pull/76

@jstac

jstac commented Oct 31, 2025

Copy link
Copy Markdown
Contributor

thanks for reporting @jstac. I can't seem to replicate this on my end. The recent ones appear to work for me. Would you mind pasting the link that is 404'ing for you?

All links working again after my last push. Do they go stale after a while?

Many thanks @jstac, I think there is an entry in the style guide that suggests us to use import jax.random as jr so I proposed the change in this PR:
https://manual.quantecon.org/styleguide/jax-conversion.html#random-number-generation

Ah, thanks for letting me know @HumphreyYang

I have opened a PR on this in the style sheet:
https://github.com/QuantEcon/QuantEcon.manual/pull/76

Nice work.

@jstac

jstac commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

Please hold off on any edits to this PR.

@jstac

jstac commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

🤖 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-619--sunny-cactus-210e3e.netlify.app/ currently returns 404.

Why previews are down (repo-wide findings)

1. This branch is stale — 178 commits behind main. A preview build compiles the whole site from this branch. This branch's lectures/house_auction.md still has unpinned !pip install prettytable, which now breaks on a wcwidth incompatibility. main fixed this on 2026-06-28 by pinning prettytable<3.18 (#939). This alone fails any rebuild of this branch until it's updated to main.

2. The arviz failure was a red herring — do NOT pin arviz or rewrite plotting. A 2026-07-07 rebuild also failed in ar1_bayes/ar1_turningpts with an arviz_plots figsize ValueError. That was a transient bug in an intermediate arviz-plots 1.x release, already fixed in arviz 1.2.0. Verified locally on a clean latest-stack venv: the real az.plot_trace(trace) cell (pymc + numpyro InferenceData) runs green. The lectures use only 1.x-compatible arviz APIs (plot_trace, summary, from_numpyro, compare).

Recommended first step for this PR

Update this branch to main (merge or rebase — pulls in #939 plus ~178 other commits), then let CI rebuild. On today's latest libraries the site builds clean, so the preview should return. house_auction is the known blocker; updating also picks up other since-merged fixes — rebuild and address any remaining per-lecture failures. Verify with:

curl -sI https://pr-619--sunny-cactus-210e3e.netlify.app/mccall_model.html

This PR touches: mccall_model.md. Last CI build: success@2025-10-31. Branch: 178 commits behind main as of 2026-07-08.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants