Skip to content

[feature] Add autodiff #12

Closed
Closed

Description

@GermanHeim

Is your feature request related to a problem? Please describe.
It would be nice to have autodiff:

  1. Some NLP solvers need you to pass the gradient and Hessian.
  2. Some users might want to include the gradient as a constraint (See Global optimization of nonlinear least-squares problems by branch-and-bound and optimality constraints, Sahinidis et al., 10.1007/s11750-011-0178-8)

Describe alternatives you've considered
I am considering using std::autodiff, which uses Enzyme. The API is nice, and it is (now) easy to add in nightly (rustup +nightly component add enzyme in supported toolchains, see https://rustc-dev-guide.rust-lang.org/autodiff/installation.html#installation-guide)

I am also considering using num_dual (Pros: works outside of nightly, Cons: Probably worse performance) and symdiff (this one is symbolic, closer to Pyomo than JuMP).

While I'm not focused on performance right now, I think a nightly crate is acceptable and the way forward. Plus, not all of the users will require it, since many solvers handle derivatives themselves.

Activity

  1. added
    enhancement
    on Jun 1, 2026
  2. self-assigned this
    on Jun 11, 2026
  3. GermanHeim commented on Jun 11, 2026

    @GermanHeim
    MemberAuthor

    I've been working on this issue.
    I think std::autodiff is the way to go, and I have written a lot of code with it, using forward-over-reverse mode. The API is quite nice.

    As for N° 2, I don't think we can do exactly this using autodiff. We would need symbolic expressions.
    For now, I think the way to go is to provide autodiff for the solvers that need it and an API to perform linearization using a first-order Taylor approximation for these uses.

    I think that, in the end, we should offer two crates:

    • oximo-autodiff (this work, using std::autodiff + linearization for now)
    • oximo-symdiff (symbolic differences)

    However, I am not sure symdiff is the right approach for this use case.
    One option is symb_anafis.
    Another option, which I really like, is Symbolica, however the license seems like a no-go:

    FAQ:
    Whether end users need a license is decided on a case-by-case basis. In most situations, when Symbolica is only a small part of the API exposed to your users, they do not need a separate license to run your program with multi-core or multi-instance support.

    So I will need to ask around!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions