Skip to content

Validate dt against CFL stability bound in diffuse() (#1281)#1282

Merged
brendancol merged 1 commit into
mainfrom
issue-1281
Apr 27, 2026
Merged

Validate dt against CFL stability bound in diffuse() (#1281)#1282
brendancol merged 1 commit into
mainfrom
issue-1281

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • diffuse() validated user-supplied dt only as > 0. The explicit forward-Euler 5-point Laplacian is unconditionally unstable above the CFL bound dt = 0.25 * dx**2 / max(alpha), and steps is accepted up to 100,000, so an oversized dt silently produced compounding Inf/NaN with no error.
  • The dt=None branch already used this bound. This PR hoists it into cfl_max and raises ValueError when the user-supplied dt is larger.
  • The check runs in the public entrypoint, so it covers all four backends (numpy, cupy, dask+numpy, dask+cupy).

Test plan

  • dt above the bound raises ValueError
  • dt at the bound is accepted
  • dt=None still works
  • CFL check uses max(alpha) for spatially varying diffusivity
  • all 19 tests in test_diffusion.py pass

Closes #1281

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 27, 2026
diffuse() validated user-supplied dt only as > 0. The explicit
forward-Euler 5-point Laplacian is unconditionally unstable above
dt = 0.25 * dx**2 / max(alpha), and steps is accepted up to 100,000,
so an oversized dt silently produced compounding Inf/NaN with no error.

The dt=None branch already uses this exact bound. This commit hoists it
into cfl_max and raises ValueError when the user-supplied dt is larger.
The check runs in the public entrypoint, so it covers all four backends
(numpy, cupy, dask+numpy, dask+cupy).

Adds four regression tests: dt above the bound raises, dt at the bound
is accepted, dt=None still works, and the CFL check uses max(alpha) for
spatially varying diffusivity.

Updates the diffusion row in .claude/sweep-security-state.csv to record
this fix as a follow-up to #1267.
@brendancol brendancol merged commit cbf81d0 into main Apr 27, 2026
11 checks passed
@brendancol brendancol deleted the issue-1281 branch May 4, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

diffuse() does not validate user-supplied dt against CFL stability bound

1 participant