JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://docs.sciml.ai/Symbolics/stable/
Other
1.35k stars 151 forks source link

Symbolics.hessian and Symbolics.sparsehessian discrepancy #1046

Open asterycs opened 7 months ago

asterycs commented 7 months ago

Hello! I encountered a use case that errors with sparsehessian but not with hessian. Below is an MVE:

using Symbolics

function f(x, y)
    y[1] * x'*x + y[2] * x'*x
end

@variables x[1:10] y[1:2]

H = Symbolics.hessian(f(collect(x), collect(y)), collect(x))
# H = Symbolics.sparsehessian(f(collect(x), collect(y)), collect(x)) # errors

hfuns = Symbolics.build_function(H, collect(x), collect(y), expression = Val{false}())

@show hfuns[1](ones(10), [2.0, 3.0])

The error message is rather long but starts with:

ERROR: LoadError: Failed to apply rule (~f)(~x, ~y) => begin ...
...
[40] top-level scope
    @ (...)/main.jl:10

Could this be a bug or is it perhaps a limitation of sparsehessian?

ChrisRackauckas commented 7 months ago

This looks like a bug.