Refactor generic Rosenbrock perform_step! to converge with RosenbrockCache#3100
Closed
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
Closed
Conversation
oscardssmith
reviewed
Mar 1, 2026
| methods where a4j=a3j) into a properly-sized, type-converted tableau suitable for the | ||
| generic loop-based `perform_step!`. | ||
| """ | ||
| function _make_rosenbrock_tableau(raw_tab::RosenbrockAdaptiveTableau, ::Type{T}, ::Type{T2}) where {T, T2} |
Member
There was a problem hiding this comment.
Do we need any of this? Can't we just port these methods to the RosenbrockTableau directly?
15201b1 to
51ca208
Compare
…Cache Replace macro-generated code (gen_perform_step, gen_constant_perform_step, gen_initialize) with a shared loop function used by both GenericRosenbrockMutableCache and RosenbrockCache. Key changes: - Add GenericRosenbrockConstantCache abstract type for dispatch - Add _ks() accessors to get stage vectors as tuples from generic caches - Extract _rosenbrock_stage_loop!() shared by generic and Rodas methods - Add generic initialize!/perform_step! dispatching on abstract cache types - Refactor RosenbrockCache perform_step to use shared loop - Store array-based tableaus via _make_rosenbrock_tableau() instead of named-field structs, enabling uniform tab.a[i,j] access - Remove gen_initialize, gen_constant_perform_step, gen_perform_step - Strip :init and :performstep branches from all 5 macros - Fix bug: generated code never persisted cache.linsolve = linres.cache Net: -60 lines, eliminates ~230 lines of code generation while converging two independent implementations into one shared loop. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
51ca208 to
335565a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
perform_step!code (gen_perform_step,gen_constant_perform_step,gen_initialize) with a shared loop function_rosenbrock_stage_loop!()used by bothGenericRosenbrockMutableCacheandRosenbrockCacheGenericRosenbrockConstantCacheabstract type and_ks()accessors for dispatch on generic caches_make_rosenbrock_tableau()instead of named-field structs, enabling uniformtab.a[i,j]access across all methodscache.linsolve = linres.cacheDetails
The generic Rosenbrock (W) methods previously used macro-based code generation to produce specialized
perform_step!for 21 algorithms across 5 macro families (@ROS2,@ROS23,@ROS34PW,@Rosenbrock4,@RosenbrockW6S4OS). Meanwhile,RosenbrockCache(Rodas4/5/6P) already had a clean loop-basedperform_step!with an identical inner loop structure. This PR converges them.Key design decisions:
_rosenbrock_stage_loop!handles stages 2..s, parameterized bytab_a,dtC,dtd, andstage_limiter!to accommodate differences between generic (no stage limiter, locally allocated dtC) and Rodas (stage limiter, pre-allocated dtC)perform_step!because the firstdolinsolvecall has different kwargsfevaluation per step for 6 Rosenbrock4 algorithms (previously thea4j=a3joptimization avoided this), since the linear solve dominates costdolinsolvevsW\b)Test plan
Pkg.test("OrdinaryDiffEqRosenbrock")passes — convergence tests for all 21 generic + all Rodas methods🤖 Generated with Claude Code