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

Clarify documentation on sparse second-order differentiation #268

Closed
ElOceanografo opened this issue May 21, 2024 · 5 comments · Fixed by #276
Closed

Clarify documentation on sparse second-order differentiation #268

ElOceanografo opened this issue May 21, 2024 · 5 comments · Fixed by #276
Labels
documentation Improvements or additions to documentation

Comments

@ElOceanografo
Copy link

Currently the documentation is not totally clear whether you should do AutoSparse(SecondOrder(OuterBackend(), InnerBackend(), ...)) or SecondOrder(AutoSparse(OuterBackend(), ...), InnerBackend()). Based on some quick timing experiments, I assume it's the former...would be good to have it laid out explicitly.

It would also be good to have a brief description of the difference between AutoSparse(InnerBackend(), ...) and AutoSparse(OuterBackend(), InnerBackend(), ...), i.e. when you'd want to do one or the other and the advantages/disadvantages.

@gdalle
Copy link
Owner

gdalle commented May 21, 2024

Currently the documentation is not totally clear whether you should do AutoSparse(SecondOrder(OuterBackend(), InnerBackend(), ...)) or SecondOrder(AutoSparse(OuterBackend(), ...), InnerBackend()).

Indeed you should wrap the whole backend inside AutoSparse, like so:

AutoSparse(SecondOrder(Outer(), Inner()))

I'll add it to the SecondOrder docstring.

It would also be good to have a brief description of the difference between AutoSparse(InnerBackend(), ...) and AutoSparse(OuterBackend(), InnerBackend(), ...),

I'm not sure what you mean here, can you perhaps fix the typo or forgotten SecondOrder?

@ElOceanografo
Copy link
Author

What I mean is, you can do e.g. AutoSparse(AutoZygote()) or AutoSparse(SecondOrder(AutoForwardDiff(), AutoZygote())). Both will work and produce a sparse Jacobian/Hessian, but it's not clear what exactly is the difference algorithmically. Is the first one basically equivalent to AutoSparse(SecondOrder(AutoZygote(), AutoZygote()))?

@gdalle
Copy link
Owner

gdalle commented May 21, 2024

Yes, this behavior is independent from AutoSparse. When a second order operator is not implemented by a given backend, then second_order_operator(f, backend, x) falls back on second_order_operator(f, SecondOrder(backend, backend), x). But you lose the benefits of preparation in this case, so it's better to specify a SecondOrder backend right away if you are sure that the backend alone will not suffice. I'll add this to the docs too

@gdalle gdalle added the documentation Improvements or additions to documentation label May 27, 2024
@gdalle gdalle linked a pull request May 27, 2024 that will close this issue
@gdalle
Copy link
Owner

gdalle commented May 27, 2024

@ElOceanografo I made an effort to clarify the documentation on sparse, second order and their interactions. This is visible in the dev docs, and in the docs of the newly-released DifferentiationInterface v0.4.2. Does it clarify things for you? Are there still uncertain aspects?

@ElOceanografo
Copy link
Author

Yes, that's much clearer, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants