Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange error when evaluating the Jacobian for certain systems #3447

Closed
TorkelE opened this issue Mar 7, 2025 · 3 comments · Fixed by JuliaSymbolics/SymbolicUtils.jl#709
Closed
Assignees
Labels
bug Something isn't working

Comments

@TorkelE
Copy link
Member

TorkelE commented Mar 7, 2025

Seems to occur in relatively niche situations, hence it hasn't been caught. However, it have recently appeared in the Catalyst test (causing them to fail).

using Catalyst, ModelingToolkit

#Prepares the model.
rs = @reaction_network begin
    p1 * X3^2 + p2, X3 + Y3 --> Z3
end
u0 = [u => 1.0 for u in unknowns(rs)]
ps = [p => 1.0 for p in parameters(rs)]

# First Jacobian evaluation (fine)
osys = complete(convert(ODESystem, rs))
prob = ODEProblem(osys, u0, (0.0, 1.0), ps; jac = true)
J = zeros(length(u0), length(u0))
prob.f.jac(J, prob.u0, prob.p, 0.0)

# Second Jacobian evaluation (fails).
prob = ODEProblem(osys, u0, (0.0, 1.0), ps; jac = true)
J = zeros(length(u0), length(u0))
prob.f.jac(J, prob.u0, prob.p, 0.0) # Error

Gives a

ERROR: MethodError: Cannot `convert` an object of type SymbolicUtils.BasicSymbolic{Float64} to an object of type Float64
The function `convert` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  (::Type{T})(::SymbolicUtils.Symbolic) where T<:Union{AbstractFloat, Integer, Complex{<:AbstractFloat}, Complex{<:Integer}}
   @ Symbolics ~/.julia/packages/Symbolics/bKp7i/src/Symbolics.jl:178
  convert(::Type{T}, ::Unitful.Quantity) where T<:Real
   @ Unitful ~/.julia/packages/Unitful/nwwOk/src/conversion.jl:158
  convert(::Type{T}, ::Unitful.Level) where T<:Real
   @ Unitful ~/.julia/packages/Unitful/nwwOk/src/logarithm.jl:23
  ...

@ChrisRackauckas
Copy link
Member

I assume this is hash consing related.

@AayushSabharwal
Copy link
Member

Yeah maybe the caching is wrong in a way our tests don't catch

@hersle
Copy link
Contributor

hersle commented Mar 8, 2025

Is the cause likely to be the same as for JuliaSymbolics/Symbolics.jl#1470?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants