Skip to content

Commit 2bb429e

Browse files
Fix symbolic to numeric conversion in get_parameter_values (#559)
When creating an ODEProblem from a Basis, get_parameter_values was returning symbolic values (SymbolicUtils.BasicSymbolic{Real}) instead of numeric values (Float64), causing the ODE solver to fail with a MethodError when trying to convert symbolic values to Float64. The issue occurred because: 1. Symbolics.getdefaultval() can return Num types 2. zero(Symbolics.symtype(p)) returns a symbolic zero, not numeric zero This fix ensures both get_parameter_values and get_parameter_map convert all parameter values to Float64 before returning them. Fixes #559 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6caca6b commit 2bb429e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/basis/type.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,14 @@ This extends `getmetadata` in a way that all parameters have a numeric value.
532532
"""
533533
function get_parameter_values(x::Basis)
534534
map(parameters(x)) do p
535-
if hasmetadata(p, Symbolics.VariableDefaultValue)
536-
return Symbolics.getdefaultval(p)
535+
val = if hasmetadata(p, Symbolics.VariableDefaultValue)
536+
Symbolics.getdefaultval(p)
537537
else
538-
return zero(Symbolics.symtype(p))
538+
zero(Symbolics.symtype(p))
539539
end
540+
# Convert symbolic values to numeric values for use in ODEProblem
541+
# This handles cases where default values are stored as Num types
542+
return val isa Num ? Float64(val) : Float64(val)
540543
end
541544
end
542545

@@ -552,11 +555,15 @@ This extends `getmetadata` in a way that all parameters have a numeric value.
552555
"""
553556
function get_parameter_map(x::Basis)
554557
map(parameters(x)) do p
555-
if hasmetadata(p, Symbolics.VariableDefaultValue)
556-
return p => Symbolics.getdefaultval(p)
558+
val = if hasmetadata(p, Symbolics.VariableDefaultValue)
559+
Symbolics.getdefaultval(p)
557560
else
558-
return p => zero(Symbolics.symtype(p))
561+
zero(Symbolics.symtype(p))
559562
end
563+
# Convert symbolic values to numeric values for use in ODEProblem
564+
# This handles cases where default values are stored as Num types
565+
numeric_val = val isa Num ? Float64(val) : Float64(val)
566+
return p => numeric_val
560567
end
561568
end
562569

0 commit comments

Comments
 (0)