Skip to content

Adding Mooncake to the AD list. #936

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Adding Mooncake to the AD list. #936

wants to merge 2 commits into from

Conversation

yebai
Copy link

@yebai yebai commented Jun 30, 2025

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Add any other context about the problem here.

@yebai
Copy link
Author

yebai commented Jun 30, 2025

cc @ChrisRackauckas

@ChrisRackauckas
Copy link
Member

That's not supported here yet?

@yebai
Copy link
Author

yebai commented Jun 30, 2025

I thought all ADTypes are supported. Turing uses this package with Mooncake, and it works fine.

Cc @penelopeysm

@yebai
Copy link
Author

yebai commented Jul 9, 2025

@penelopeysm, can you confirm whether AutoMooncake is supported by Optimization.jl?

@penelopeysm
Copy link

I don't maintain Optimization so I can't speak for @ChrisRackauckas.

However, my guess would be that it should be tested:

https://github.com/SciML/Optimization.jl/blob/master/test/ADtests.jl

And perhaps a docstring here would be needed too:

https://github.com/SciML/OptimizationBase.jl/blob/main/src/adtypes.jl

@yebai
Copy link
Author

yebai commented Jul 9, 2025

I can confirm this example with BFGS() + AutoMooncake() works:

julia> using Optimization, OptimizationOptimJL, Mooncake

julia> rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2;

julia> x0 = zeros(2);

julia> p = [1.0, 100.0];

julia> f = OptimizationFunction(rosenbrock, Optimization.AutoMooncake());

julia> prob = OptimizationProblem(f, x0, p);

julia> sol = solve(prob, BFGS())
retcode: Success
u: 2-element Vector{Float64}:
 0.9999999999373603
 0.9999999998686199


(jl_dDLpBs) pkg> st
Status `/private/var/folders/yz/wf9sm7mj3p3grdq9ysdy9c1m0000gn/T/jl_dDLpBs/Project.toml`
  [f6369f11] ForwardDiff v1.0.1
  [da2b9cff] Mooncake v0.4.138
  [7f7a1694] Optimization v4.4.0
  [36348300] OptimizationOptimJL v0.4.3

@yebai
Copy link
Author

yebai commented Jul 9, 2025

And perhaps a docstring here would be needed too:

That is inherited automatically from ADTypes. See

help?> Optimization.AutoMooncake
  AutoMooncake

  Struct used to select the Mooncake.jl (https://github.com/compintell/Mooncake.jl) backend for automatic
  differentiation.

  Defined by ADTypes.jl (https://github.com/SciML/ADTypes.jl).

  Constructors
  ≡≡≡≡≡≡≡≡≡≡≡≡

  AutoMooncake(; config=nothing)

  Fields
  ≡≡≡≡≡≡

    •  config: either nothing or an instance of Mooncake.Config – see the docstring of Mooncake.Config for more
       information. AutoMooncake(; config=nothing) is equivalent to AutoMooncake(; config=Mooncake.Config()), i.e.
       the default configuration.

@yebai
Copy link
Author

yebai commented Jul 9, 2025

@ChrisRackauckas, this should be ready if tests pass.

@penelopeysm
Copy link

penelopeysm commented Jul 9, 2025

That is inherited automatically from ADTypes

I am aware, but the others have custom docstrings that are specifically written in OptimizationBase and are displayed on https://docs.sciml.ai/Optimization/stable/API/ad/. I presume it's so that Optimization can add additional comments about individual backends if relevant. Of course, I don't know what would need to go into the corresponding Mooncake docstring that isn't in the original ADTypes.jl docstring. I guess someone else could comment on that if necessary.

@yebai
Copy link
Author

yebai commented Jul 10, 2025

A quick note: in my view, we should not overload ADTypes docstrings. If needed, we should update the docstring in ADTypes.

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

Successfully merging this pull request may close these issues.

3 participants