Convert nlsolver.γ to tTypeNoUnits to avoid expensive rationalize calls #2923
+18
−13
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
This PR fixes #2921 by converting the
nlsolver.γparameter totTypeNoUnitsinbuild_nlsolver, preventing expensiverationalize()calls during QNDF integration.Problem
When using QNDF solvers, the
nlsolver.γwas initialized asRational{Int64}(e.g.,Int64(1)//1). Later, during the step function, aFloat64value would be assigned tonlsolver.γ = β₀. This triggered Julia's conversion fromFloat64toRational{Int64}, which callsrationalize()- an expensive operation that was consuming significant computation time.Solution
Convert
γtotTypeNoUnits(typicallyFloat64) inbuild_nlsolverbefore:nlp_paramstuples forNonlinearSolveAlgNLSolverobjectThis ensures the type parameter
gamTypeisFloat64from the start, so later assignments are justFloat64toFloat64(no conversion needed).Changes
lib/OrdinaryDiffEqNonlinearSolve/src/utils.jl: Addedγ = tTypeNoUnits(γ)conversion in bothVal{true}(in-place) andVal{false}(out-of-place) versions ofbuild_nlsolverBenchmark Results
Test Plan
Pkg.test("OrdinaryDiffEqBDF")passes (70 tests)Pkg.test("OrdinaryDiffEqNonlinearSolve")passesPkg.test("OrdinaryDiffEqSDIRK")passesCloses #2921
🤖 Generated with Claude Code