From 2bb429e41494c8a7461ef2ffcb85fa48470a06fc Mon Sep 17 00:00:00 2001 From: ChrisRackauckas Date: Thu, 2 Oct 2025 04:58:24 -0400 Subject: [PATCH] Fix symbolic to numeric conversion in get_parameter_values (#559) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/basis/type.jl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/basis/type.jl b/src/basis/type.jl index f41b1a43..b5db7091 100644 --- a/src/basis/type.jl +++ b/src/basis/type.jl @@ -532,11 +532,14 @@ This extends `getmetadata` in a way that all parameters have a numeric value. """ function get_parameter_values(x::Basis) map(parameters(x)) do p - if hasmetadata(p, Symbolics.VariableDefaultValue) - return Symbolics.getdefaultval(p) + val = if hasmetadata(p, Symbolics.VariableDefaultValue) + Symbolics.getdefaultval(p) else - return zero(Symbolics.symtype(p)) + zero(Symbolics.symtype(p)) end + # Convert symbolic values to numeric values for use in ODEProblem + # This handles cases where default values are stored as Num types + return val isa Num ? Float64(val) : Float64(val) end end @@ -552,11 +555,15 @@ This extends `getmetadata` in a way that all parameters have a numeric value. """ function get_parameter_map(x::Basis) map(parameters(x)) do p - if hasmetadata(p, Symbolics.VariableDefaultValue) - return p => Symbolics.getdefaultval(p) + val = if hasmetadata(p, Symbolics.VariableDefaultValue) + Symbolics.getdefaultval(p) else - return p => zero(Symbolics.symtype(p)) + zero(Symbolics.symtype(p)) end + # Convert symbolic values to numeric values for use in ODEProblem + # This handles cases where default values are stored as Num types + numeric_val = val isa Num ? Float64(val) : Float64(val) + return p => numeric_val end end