The goal of the Mooncake.jl project is to produce an AD package written entirely in Julia that improves on ForwardDiff.jl, ReverseDiff.jl, and Zygote.jl in several ways.
Please refer to the docs for more info.
Important
Mooncake.jl accepts issues and pull requests pertaining to reproducible defects only. Feature requests, enhancements, redesign proposals, support requests, and debugging requests not accompanied by a minimal reproducible example are outside the scope of this project and will be closed. Mooncake.jl is intended to differentiate through the vast majority of Julia Base and the standard libraries. Known limitations are documented on the known limitations page. Requests for rules covering functionality outside Julia Base are considered out of scope.
Mooncake.jl is open-source software developed primarily by academic researchers working within grant-funded institutions. Consequently, our capacity to triage issues and review contributions is necessarily constrained by available resources. Organisations that depend on Mooncake.jl in a commercial or industrial setting are encouraged to consider contributing financially or through direct code contributions.
Check that you're running a version of Julia that Mooncake.jl supports.
See the SUPPORT_POLICY.md file for more info.
There are several ways to interact with Mooncake.jl. To interact directly with Mooncake.jl, use Mooncake's native API, which allows reuse of prepared caches for repeated gradient and Hessian evaluations:
import Mooncake as MC
f(x) = (1 - x[1])^2 + 100 * (x[2] - x[1]^2)^2 # Rosenbrock
x = [1.2, 1.2]
# Reverse mode
grad_cache = MC.prepare_gradient_cache(f, x);
val, grad = MC.value_and_gradient!!(grad_cache, f, x)
# Forward mode
fwd_cache = MC.prepare_derivative_cache(f, x);
val_fwd, grad_fwd = MC.value_and_gradient!!(fwd_cache, f, x)
# Hessian
hess_cache = MC.prepare_hessian_cache(f, x);
val, grad, H = MC.value_gradient_and_hessian!!(hess_cache, f, x)
# val : f(x)
# grad : ∇f(x) (length-n vector)
# H : ∇²f(x) (n×n matrix)You should expect that MC.prepare_gradient_cache and MC.prepare_hessian_cache take a little time to run, but that subsequent calls using the prepared caches are fast.
For details, see the interface docs. You can also interact with Mooncake.jl via DifferentiationInterface.jl, though it may lag behind new features and can break on non-breaking Mooncake releases, as it depends on Mooncake's internal details.
