Symbolics.jl icon indicating copy to clipboard operation
Symbolics.jl copied to clipboard

Symbolics.hessian and Symbolics.sparsehessian discrepancy

Open asterycs opened this issue 1 year ago • 1 comments

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?

asterycs avatar Jan 29 '24 11:01 asterycs

This looks like a bug.

ChrisRackauckas avatar Feb 01 '24 19:02 ChrisRackauckas