Skip to content

Convert wealth dynamics lecture from NumPy/Numba to JAX#630

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-812b7e3e-c818-4a29-a183-7a25078f0a8d
Closed

Convert wealth dynamics lecture from NumPy/Numba to JAX#630
Copilot wants to merge 3 commits intomainfrom
copilot/fix-812b7e3e-c818-4a29-a183-7a25078f0a8d

Conversation

Copy link
Contributor

Copilot AI commented Sep 26, 2025

This PR converts the wealth dynamics lecture to use JAX instead of NumPy/Numba, addressing issue #812b7e3e-c818-4a29-a183-7a25078f0a8d.

Changes Made

JAX Conversion:

  • Replaced NumPy/Numba imports with JAX equivalents (jax, jax.numpy as jnp, typing.NamedTuple)
  • Converted the @jitclass WealthDynamics class to a JAX-compatible NamedTuple pattern
  • Updated all random number generation to use JAX's functional PRNG with proper key management
  • Applied @jax.jit decorators to performance-critical functions for optimization
  • Replaced NumPy array operations with JAX equivalents (jnp.exp, jnp.sqrt, etc.)
  • Implemented JAX-style control flow using jnp.where and jax.lax.scan

Technical Improvements:

  • Added 64-bit precision configuration with jax.config.update("jax_enable_x64", True)
  • Fixed QuantEcon function calls to work with JAX arrays by converting with np.array()
  • Implemented vectorized operations using jax.vmap for efficient parallel computation
  • Used memory-efficient jax.lax.scan instead of Python loops for time series generation

Code Quality:

  • Applied QuantEcon style guide formatting with consistent indentation and structure
  • Fixed spelling errors and improved grammar throughout
  • Cleaned up trailing whitespace and formatting inconsistencies
  • Updated plot labels for clarity and consistency
  • Added comprehensive docstrings following established patterns

Verification:

  • All core model functions tested and working correctly
  • Security vulnerability scan passed (0 issues found)
  • Jupyter Book integration confirmed working
  • JIT compilation performance validated

The lecture now uses modern JAX best practices while maintaining all original functionality and educational content. Performance is improved through JIT compilation, and the code follows functional programming patterns appropriate for scientific computing.

Original prompt

This section details on the original issue you should resolve

<issue_title>[wealth_dynamics] Update lecture</issue_title>
<issue_description>Please update the wealth dynamics lecture to:

  1. convert all code to JAX
  2. apple the QuantEcon style guide https://manual.quantecon.org/intro.html
  3. check spelling
  4. check grammar</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #629

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 26, 2025 02:46
Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
Copilot AI changed the title [WIP] [wealth_dynamics] Update lecture Convert wealth dynamics lecture from NumPy/Numba to JAX Sep 26, 2025
Copilot AI requested a review from mmcky September 26, 2025 02:50
@github-actions
Copy link

📖 Netlify Preview Ready!

Preview URL: https://pr-630--sunny-cactus-210e3e.netlify.app (9f1403f)

📚 Changed Lecture Pages: wealth_dynamics

@mmcky mmcky closed this Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wealth_dynamics] Update lecture

2 participants