Skip to content

Add warn_on_resize option to DiffCache#161

Merged
ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:add-warn-on-resize-option
Mar 25, 2026
Merged

Add warn_on_resize option to DiffCache#161
ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:add-warn-on-resize-option

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

Summary

  • Adds a warn_on_resize::Bool field to DiffCache and a corresponding keyword argument (default true) to all constructors
  • When warn_on_resize = false, the warning in enlargediffcache! is suppressed
  • zero and copy preserve the warn_on_resize setting

Motivation

Adaptive BVP solvers (and other adaptive algorithms) expect cache expansion as normal behavior. Currently, downstream packages have to wrap get_tmp calls in Logging.with_logger(Logging.NullLogger()) to suppress the warning, which adds overhead and obscures the code:

# Current workaround in downstream packages
@inline function get_tmp(dc, u)
    return Logging.with_logger(Logging.NullLogger()) do
        PreallocationTools.get_tmp(dc, u)
    end
end

With this PR, they can simply construct the cache with warnings disabled:

dc = DiffCache(u; warn_on_resize = false)

Usage

# Default behavior (warns on resize) — backward compatible
dc = DiffCache(zeros(10))

# Suppress resize warnings for adaptive solvers
dc = DiffCache(zeros(10); warn_on_resize = false)

Test plan

  • New tests verify warn_on_resize field is set correctly on construction
  • warn_on_resize = false suppresses warning during cache enlargement (@test_nowarn)
  • zero and copy preserve the warn_on_resize setting
  • All existing tests pass

🤖 Generated with Claude Code

Add a `warn_on_resize` keyword argument (default `true`) to `DiffCache`
constructors that controls whether a warning is emitted when the cache
is automatically enlarged during `get_tmp`. This is useful for adaptive
solvers (e.g. BVP solvers) where cache expansion is expected behavior
and the warning is noise.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChrisRackauckas ChrisRackauckas merged commit 33abce7 into SciML:master Mar 25, 2026
13 of 14 checks passed
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.

2 participants