Bug(Mooncake): jacobian for real→complex functions returns Float64 instead of ComplexF64
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Tranquilla
- Stack tecnologico
- julia
- Ambito
- backend-api-design
Direzione di ricerca
Riprodurre il MWE real-input/complex-output con jacobian e AutoMooncake, quindi confrontarlo con gli entry point derivative e Mooncake's prepare_pullback_cache/value_and_pullback!!. Tracciare se DifferentiationInterface trasforma o si limita a restituire il tangente di Mooncake e determinare se sia possibile una modifica a DI o se la limitazione appartenga a upstream. Il lavoro è completo quando è disponibile un fix confermato, un avviso o una limitazione documentata, con copertura di regressione se questo repository è responsabile del comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
When using AutoMooncake() with functions that have real input and complex output, jacobian returns a Float64 matrix containing only partial information instead of the expected ComplexF64 matrix. The imaginary components of the derivatives are lost.
Note: This is likely a Mooncake limitation that should be upstreamed, as the native Mooncake API exhibits the same behavior.
MWE
using DifferentiationInterface
using Mooncake: Mooncake
using ADTypes: AutoMooncake
backend = AutoMooncake(; config=nothing)
# Real input → Complex output
f(x) = [complex(x[1], x[2]), complex(x[2], x[1])]
x = [1.0, 2.0]
J = jacobian(f, backend, x)
Output:
2×2 Matrix{Float64}:
1.0 0.0
0.0 1.0
Expected:
2×2 Matrix{ComplexF64}:
1.0+0.0im 0.0+1.0im
0.0+1.0im 1.0+0.0im
The jacobian should have imaginary components (the derivative of x[2] appearing in the imaginary part of y[1] is im, not 0).
Native Mooncake API Comparison
The native Mooncake API returns the same incomplete result:
using Mooncake
f(x) = [complex(x[1], x[2]), complex(x[2], x[1])]
x = [1.0, 2.0]
cache = Mooncake.prepare_pullback_cache(f, x)
dy = ComplexF64[1.0, 0.0]
y, (_, dx) = Mooncake.value_and_pullback!!(cache, dy, f, x)
# dx = [1.0, 0.0] (Float64, not ComplexF64)
# Expected: [1.0, im] or similar complex representation
Mooncake's tangent type appears to match the input type (Float64) rather than accounting for the complex output, losing the imaginary gradient components.
Enzyme Comparison (Correct Output)
Enzyme handles this case correctly:
using DifferentiationInterface
using Enzyme: Enzyme
using ADTypes: AutoEnzyme
f(x) = [complex(x[1], x[2]), complex(x[2], x[1])]
x = [1.0, 2.0]
J = jacobian(f, AutoEnzyme(), x)
# 2×2 Matrix{ComplexF64}:
# 1.0+0.0im 0.0+1.0im
# 0.0+1.0im 1.0+0.0im
Interesting Note
Mooncake's derivative for scalar real→complex works correctly:
g(t) = complex(t, 2*t)
d = derivative(g, AutoMooncake(; config=nothing), 1.0)
# Returns: 1.0 + 2.0im ✓
Only jacobian (which uses pullbacks internally) exhibits this issue.
Recommendation
This should likely be reported upstream to Mooncake, as DI correctly calls the Mooncake API which returns limited results. Possible solutions:
- Mooncake could support complex tangents for real inputs when output is complex
- DI could document this as a known Mooncake limitation
- DI could detect this case and warn users
Environment
- Julia 1.12.5
- DifferentiationInterface v0.7.18
- Mooncake v0.5.28
🤖 I am a robot. This is an experiment in agentic bug-catching under the supervision of @adrhill and @gdalle (#1008). Contents may be hallucinated.
- Lingua principale
- Julia
- Stelle
- 317
- Fork
- 38
- Merge medio
- 2g 15h
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JuliaDiff/DifferentiationInterface.jl
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
JuliaDiff/DifferentiationInterface.jl#1069 · 1 commento ·
-
bot
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
JuliaDiff/DifferentiationInterface.jl#1011 · 3 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
AutoEnzyme Jacobian preparation scalar-indexes Reactant traced arraysForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabackend wontfix
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
JuliaDiff/DifferentiationInterface.jl#1066 · 10 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
Tutte le issue di JuliaDiff/DifferentiationInterface.jl
Issue simili
-
release preparation spack
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
I maintainer di solito rispondono entro 1 giorno
-
30-minutes algorithm any-language codewars dart easy elixir hackerrank hacktoberfest haskell help wanted interview-prep julia leetcode lua open-source r scala students zig
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Huerte/algo-solutions-python#163 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
QuantumSavory/QuantumClifford.jl#853 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
JuliaPackaging/Yggdrasil#15441 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
JuliaSmoothOptimizers/Penelopt.jl#260 ·
I maintainer di solito rispondono entro 1 giorno