Fix symbolic to numeric conversion using Symbolics.unwrap (#559) #561
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 #559 where
solvethrows aMethodError: cannot convert BasicSymbolic to a Float64when creating anODEProblemfrom aBasis.Problem
When creating an
ODEProblemfrom a recoveredBasis,get_parameter_valueswas returning symbolic values (SymbolicUtils.BasicSymbolic{Real}) instead of numeric values. This caused the ODE solver to fail when trying to convert symbolic values for use in the integrator.The issue occurred because:
Symbolics.getdefaultval()can returnNumtypes which wrap symbolic valueszero(Symbolics.symtype(p))returns a symbolic zero (typeSymbolicUtils.BasicSymbolic{Real}), not a numeric zeroSolution
Modified both
get_parameter_valuesandget_parameter_mapfunctions insrc/basis/type.jlto useSymbolics.unwrap()to extract numeric values from symbolic wrappers. This approach is cleaner and more appropriate than explicitFloat64conversion as it properly handles the symbolic unwrapping.Changes
src/basis/type.jl
get_parameter_valuesto useSymbolics.unwrap(val)get_parameter_mapto useSymbolics.unwrap(val)test/basis/basis.jl
solvethrowsMethodError: cannot convert BasicSymbolc to a Float64forODEProblemcreated fromBasis#559)"ODEProblemcreation withoutMethodErrorTesting
All 261 tests pass ✅
The new test specifically validates:
get_parameter_valuesreturns non-symbolic values (notNumtypes)get_parameter_mapreturns non-symbolic valuesODEProblem(basis, u0, tspan, params)works withoutMethodErrorsolve(problem, Tsit5())doesn't throw symbolic conversion errorsNotes
This approach using
Symbolics.unwrap()is preferred overFloat64()conversion as it:Fixes #559
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com