Enzyme icon indicating copy to clipboard operation
Enzyme copied to clipboard

Full hessian (c++)

Open a-jp opened this issue 11 months ago • 7 comments
trafficstars

I'd like to consider this library to support my interaction with ipopt. For that to work I need the gradient, Jacobian, and hessian of functions with respect to the optimisation variable or variables. To that end I also need to provide to ipopt sparsity patterns for the jacobian and hessian. I need the hessian, not the HVP etc. My code is c++ and interfaces to ipopt using c++.

Taking all of the above into account would I be able to use enzyme now? If not, what is missing?

Thanks

a-jp avatar Nov 24 '24 18:11 a-jp

Is your Hessian sparse or dense? If dense, the Hessian can be computed efficiently using the HVP (ideally combined with batching). If sparse and you know the sparsity pattern, you can compute a coloring and efficiently obtain an assembled sparse Hessian using the HVP (some libraries, such as PETSc, will automate this for you). If you want Enzyme to figure out the sparsity pattern and put the matrix in a CSR format, I think that would be a new feature (don't know if Enzyme maintainers would consider it "patches welcome" or out of scope).

jedbrown avatar Nov 25 '24 06:11 jedbrown

The hessian and jacobian are sparse. I do not know the sparsity pattern and need to obtain this from the library. CSR is ideal for both jacobian and hessian. I do not know the HvP nor does the library I'm coupling to require it. I had naively assumed that on computing derivatives for the jacobian and hessian the library knows it's a zero entry and the sparsity would "come for free"?

a-jp avatar Nov 25 '24 07:11 a-jp

there is some work in Enzyme to automatically automate the sparsity detection x/ref https://c.wsmoses.com/presentations/weuroad23.pdf cc @martinjm97 @kmu @shoaibkamil

wsmoses avatar Nov 25 '24 23:11 wsmoses

though that said patches/features generally always welcome (but if it's a more significant thing, probably worth a github discussion, or discussion at the weekly enzyme meeting

wsmoses avatar Nov 25 '24 23:11 wsmoses

Thank you. Can you confirm at present dense (without sparsity calcs) hessian computations are possible? Is there an example of that?

a-jp avatar Nov 26 '24 06:11 a-jp

Hi, just following this up. Could you confirm pure hessian computations are possible, dense or otherwise? Could you provide an example?

Thanks

a-jp avatar Dec 17 '24 08:12 a-jp

Hi, just following this up. Could you confirm pure hessian computations are possible, dense or otherwise? Could you provide an example?

Thanks

Hi, just following this up. Any comments to help with this? Thanks

a-jp avatar Feb 08 '25 09:02 a-jp

@a-jp I was wondering where you got to with this? Did you see the Hessian C code in the link in this issue? https://github.com/EnzymeAD/Enzyme/issues/1123

Thanks.

jeffpollock9 avatar Sep 23 '25 17:09 jeffpollock9