Fix isinplace detection for Basis types (#554)#558
Merged
ChrisRackauckas merged 1 commit intoSciML:masterfrom Oct 1, 2025
Merged
Fix isinplace detection for Basis types (#554)#558ChrisRackauckas merged 1 commit intoSciML:masterfrom
ChrisRackauckas merged 1 commit intoSciML:masterfrom
Conversation
Implement `DiffEqBase.isinplace` for `Basis` to correctly report whether
the basis supports in-place evaluation based on the `IMPL` type parameter.
The issue was that when creating an `ODEProblem` from a `Basis` with
controls but without implicit variables (Basis{false, true}), SciMLBase
would incorrectly detect it as in-place compatible. This caused a
MethodError because:
- Basis{false, CTRLS} only supports out-of-place signatures: (u, p, t) or (u, p, t, c)
- Basis{true, CTRLS} supports in-place signatures: (du, u, p, t) or (du, u, p, t, c)
The fix adds:
```julia
DiffEqBase.isinplace(::Basis{IMPL, CTRLS}, n) where {IMPL, CTRLS} = IMPL
```
This ensures that `isinplace` returns `true` only when the basis has
implicit variables (IMPL=true) and supports in-place evaluation,
and `false` otherwise.
Fixes SciML#554
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Author
Investigation SummaryRoot Cause AnalysisThe error occurred because there was no However, the actual signatures are:
The Implementation DetailsThe fix is minimal and elegant - just one line: DiffEqBase.isinplace(::Basis{IMPL, CTRLS}, n) where {IMPL, CTRLS} = IMPLThis leverages the existing type parameter to provide the correct answer without any runtime checks. Testing VerificationRan the full test suite ( |
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
This PR fixes issue #554 where creating an
ODEProblemfrom aBasiswith controls would throw aMethodErrorbecause SciMLBase incorrectly detected the basis as supporting in-place evaluation.Problem
When a
Basis{false, true}(no implicit variables, with controls) was passed toODEProblem, SciMLBase'sisinplacecheck would returntrue, causing it to call the basis with a 4-argument signature(du, u, p, t). However,Basis{false, CTRLS}only supports out-of-place signatures like(u, p, t)or(u, p, t, c).The
IMPLtype parameter determines whether a basis supports in-place evaluation:IMPL=false: Out-of-place only (returns result)IMPL=true: In-place (mutates first argumentdu)Solution
Added
DiffEqBase.isinplacemethod forBasistypes:This ensures
isinplacecorrectly returnsfalseforBasis{false, CTRLS}andtrueforBasis{true, CTRLS}, based solely on whether the basis has implicit variables.Testing
isinplacenow returns correct value for bothBasis{false, false}andBasis{false, true}ODEProblemcan now be created fromBasiswithout theMethodErrorFixes #554
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com