Skip to content

Conversation

kp992
Copy link
Contributor

@kp992 kp992 commented Sep 23, 2025

This PR:

  • Removes numba and numpy support.
  • Updates all the code to use JAX.
  • fixes minor typos and title errors.

@github-actions
Copy link

📖 Netlify Preview Ready!

Preview URL: https://pr-623--sunny-cactus-210e3e.netlify.app (2b7c4fe)

📚 Changed Lecture Pages: inventory_dynamics

@kp992 kp992 added the ready label Sep 24, 2025
@kp992 kp992 requested review from HumphreyYang and mmcky September 24, 2025 00:38
@mmcky mmcky added review and removed ready labels Sep 24, 2025
@mmcky mmcky requested a review from Copilot September 24, 2025 01:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the inventory dynamics lecture to use JAX instead of numba and numpy, modernizing the codebase and improving performance. The changes align with the latest style guide and fix minor formatting issues.

Key changes:

  • Replaces numba-based Firm class with JAX-based functions using NamedTuple
  • Converts simulation functions to use JAX's functional programming paradigm with jax.lax.scan and jax.vmap
  • Updates all numpy operations to JAX numpy equivalents

@github-actions
Copy link

📖 Netlify Preview Ready!

Preview URL: https://pr-623--sunny-cactus-210e3e.netlify.app (54d1cac)

📚 Changed Lecture Pages: inventory_dynamics

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 @kp992! These are really nice! Just two very minor observations.

I think we should remove the grid in the figures to maintain consistency in the style:

for ax in axes:
    ax.grid(alpha=0.4)

Comment on lines +515 to +521
# Generate independent random keys for each firm
firm_keys = random.split(key, (num_firms, sim_length))
# Run simulation for all firms
restock_indicators = vectorized_simulate(firm_keys)
# Compute frequency (fraction of firms that restocked > 1 times)
frequency = jnp.mean(restock_indicators)
return frequency
Copy link
Member

Choose a reason for hiding this comment

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

I think it might look better if we add some spaces in between:

Suggested change
# Generate independent random keys for each firm
firm_keys = random.split(key, (num_firms, sim_length))
# Run simulation for all firms
restock_indicators = vectorized_simulate(firm_keys)
# Compute frequency (fraction of firms that restocked > 1 times)
frequency = jnp.mean(restock_indicators)
return frequency
# Generate independent random keys for each firm
firm_keys = random.split(key, (num_firms, sim_length))
# Run simulation for all firms
restock_indicators = vectorized_simulate(firm_keys)
# Compute frequency (fraction of firms that restocked > 1 times)
frequency = jnp.mean(restock_indicators)
return frequency

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.

3 participants