Skip to content

[inventory_dynamics] Update code to JAX and latest style guide#623

Open
kp992 wants to merge 8 commits into
mainfrom
inventory_dyns
Open

[inventory_dynamics] Update code to JAX and latest style guide#623
kp992 wants to merge 8 commits into
mainfrom
inventory_dyns

Conversation

@kp992

@kp992 kp992 commented Sep 23, 2025

Copy link
Copy Markdown
Contributor

This PR:

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

@github-actions

Copy link
Copy Markdown

📖 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread lectures/inventory_dynamics.md
Comment thread lectures/inventory_dynamics.md
Comment thread lectures/inventory_dynamics.md
Comment thread lectures/inventory_dynamics.md
Comment thread lectures/inventory_dynamics.md Outdated
Comment thread lectures/inventory_dynamics.md Outdated
@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

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

📚 Changed Lecture Pages: inventory_dynamics

@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 @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
Copy Markdown
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

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

Why previews are down (repo-wide findings)

1. This branch is stale — 174 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 ~174 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-623--sunny-cactus-210e3e.netlify.app/inventory_dynamics.html

This PR touches: inventory_dynamics.md. Last CI build: success@2025-09-30. Branch: 174 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