Skip to content

Conversation

@longye-tian
Copy link
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
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
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

@github-actions
Copy link

📖 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
Copy link
Member

@HumphreyYang HumphreyYang left a comment

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!

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
Contributor Author

Hi @HumphreyYang ,

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

Best,
Longye

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@github-actions
Copy link

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@longye-tian
Copy link
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
Copy link
Contributor

jstac commented Oct 31, 2025

@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

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: mccall_model

@mmcky
Copy link
Contributor

mmcky commented Oct 31, 2025

@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
Copy link
Member

HumphreyYang commented Oct 31, 2025

@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
Copy link
Contributor

jstac commented Oct 31, 2025

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
Copy link
Contributor

jstac commented Nov 1, 2025

Please hold off on any edits to this PR.

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.

6 participants