Bug(Mooncake): jacobian for real→complex functions returns Float64 instead of ComplexF64

Aperta
#1,010 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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

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

bot

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:

  1. Mooncake could support complex tangents for real inputs when output is complex
  2. DI could document this as a known Mooncake limitation
  3. 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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaDiff/DifferentiationInterface.jl

Tutte le issue di JuliaDiff/DifferentiationInterface.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.