JuliaGeometry / JuliaGeometry/Rotations.jl
Support automatic differentiation with Zygote
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 188
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
Supporting reverse-mode autodiff with Zygote requires two things:
- custom pullbacks (reverse-mode differentiation rules, AKA adjoints) for functions that internally mutate arrays (Zygote does not support array mutation)
- custom pullbacks for constructors
I think the latter is the main thing missing for Zygote support. Supporting it would require adding custom rrules for constructors using ChainRulesCore, which has essentially no dependencies.
Here's an example that fails:
julia> using Rotations, Zygote
julia> foo(ω, v) = (RotationVec(ω...) * v)[1];
julia> ω, v = randn(3), randn(3)
([-0.5124874613220701, 0.27274002772526423, 1.0593705312514463], [-0.2329525748114141, -1.1183670007323072, -0.4878065893106537])
julia> foo(ω, v)
0.8904209135865043
julia> Zygote.gradient(foo, ω, v) # expected from finite differences: ([-0.18142454901446126, -0.16476417425397563, 0.8182962760715483], [0.47098619925782836, -0.8816660765248943, -0.028929735807022527])
ERROR: Need an adjoint for constructor RotationVec{Float64}. Gradient is of type Array{Float64,2}
In this case mathematically the missing pullback is for the exponential map exp: so(3) → SO(3).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Julia/Zygote example in the issue and inspect the RotationVec constructor, along with ChainRulesCore's rrule mechanism. Done means constructor pullbacks are available for the relevant rotation types, including the exponential-map case, and the example can compute the expected gradients without an adjoint error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100