Skip to content

[numba.md] numba_ex3: run the solution at the n the exercise asks for - #601

Open
mmcky wants to merge 1 commit into
mainfrom
numba-ex3-large-n
Open

[numba.md] numba_ex3: run the solution at the n the exercise asks for#601
mmcky wants to merge 1 commit into
mainfrom
numba-ex3-large-n

Conversation

@mmcky

@mmcky mmcky commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Closes #579.

The exercise statement says to use a substantial sample size "such as n = 100_000_000", but the solution reused the shared n = 1_000_000 arrays. Benchmarked in the quantecon env (numba 0.62.1): at 10⁶ the jitted kernel runs in ~0.4 ms, so both timed cells in the published solution display 0.00 seconds — the parallelization the exercise teaches is invisible. Resolution chosen by @mmcky over the two options in the issue: make the solution actually do what the statement asks.

Changes

  • The solution draws its own u_big/v_big at n = 100_000_000 (with a note that the arrays occupy ~1.6 GB), leaving the shared 10⁶ arrays untouched — speed_ex1's pure-Python comparison would take minutes at 10⁸, so bumping the shared setup was not an option.
  • Adds a timed call of calculate_pi (the serial jitted function from speed_ex1) on the same points, so the serial-vs-parallel comparison the prose describes is actually visible in the built lecture instead of asking the reader to flip parallel=True themselves.
  • Prose updated to match, keeping the local-results caveat and extending it with why small samples can make the parallel version slower.

Validation

Ran the exact new cell sequence (shared setup → speed_ex1 compile → new solution) locally: parallel-with-compile 0.33 s, parallel 14 ms, serial 51 ms — a 3.6× visible speedup, π ≈ 3.14156 from all calls. Memory peaks at ~1.6 GB, comfortably inside every CI runner including the 7 GB macOS host; measured CI cost is a few seconds of extra execution.

🤖 Generated with Claude Code

The statement says to use a substantial sample size such as
n = 100_000_000, but the solution reused the shared 10^6 arrays --- at
that size both timed cells display as 0.00 seconds, demonstrating
nothing. The solution now draws its own 10^8 points (with a memory
note), times the parallel version, and compares against speed_ex1's
serial jitted function on the same arrays so the multithreading gain
is visible on the page.

The shared 10^6 arrays are unchanged: speed_ex1's pure-Python
comparison would take minutes at 10^8.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 4, 2026 00:44

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 numba_ex3 solution in the Numba lecture so it actually runs the Monte Carlo simulation at the substantial sample size (n = 100_000_000) requested by the exercise, making the intended serial-vs-parallel speed comparison visible in rendered outputs.

Changes:

  • Draws fresh large arrays (u_big, v_big) at n = 100_000_000 for numba_ex3, with a memory-usage note.
  • Adds a timed run of the serial jitted calculate_pi on the same large inputs to show the parallelization speedup directly.
  • Updates surrounding prose to explain why small n can hide (or reverse) parallel gains.

Comment thread lectures/numba.md
Comment on lines +758 to 762
```{code-cell} ipython3
with qe.Timer():
calculate_pi(u_big, v_big)
```

@mmcky mmcky added the in-work label Aug 4, 2026
@mmcky

mmcky commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author
  • get code and comparisons running first
  • edit prose to be QuantEcon style

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request August 4, 2026 00:51 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[numba.md] numba_ex3 asks for n = 100_000_000 but the shared setup and solution use n = 1_000_000

2 participants