Open ErikQQY opened 3 days ago
Note that DI currently doesn't guarantee anything vis a vis complex number support (this should probably be emphasized in the docs, PR welcome). The reason is that many backends don't support them at all, and the remaining ones probably have wildly diverging conventions. So while we can relax the type annotation, complex support is not part of the API at the moment (which also means it is not tested).
I can understand that different AD backends may support this differently, so what is the current solution for this? I can PR to relax these type annotations and add proper tests(which I believe will resolve the ForwardDiff and ReverseDiff cases), we have to start somewhere right🤠?
Feel free to open a PR replacing any <:Real
annotation in the package with <:Number
, since it will solve your immediate problem. But I'm not ready to add complex number support to the promises of DI's public API yet, precisely because we cannot guarantee the answers will be the same across backends. And the concepts themselves are not necessarily well defined.
Do you have an idea which backends support complex numbers and how their support differs? I've never looked into it.
From my testing, the funny thing is that the dense AD using DI would just work when dealing with complex numbers(only tested on ForwardDiff), it’s only sparse AD that suffers problems.
Sure, but what I mean is that even if it "just works" (because DI forwards everything without constraining types), different backends may have different interpretations of what the complex derivatives mean. And I don't know if it is wise to expose these different interpretations under a common interface, possibly confusing users by letting them believe the operations are semantically the same. Does that make sense? There's a long thread which I never really read in detail about this, but I might have to dive back in: https://discourse.julialang.org/t/taking-complex-autodiff-seriously-in-chainrules/39317
And I don't know if it is wise to expose these different interpretations under a common interface, possibly confusing users by letting them believe the operations are semantically the same. Does that make sense?
Yeah, that does make sense. So now I just relax the type annotations of the compressed matrix for my special use case then.
Find this while implementing https://github.com/SciML/BoundaryValueDiffEq.jl/pull/258
This MWE is just proof of the idea and may not be meaningful, but I think it can still prove that the current DI lacks support for sparse Jacobian of complex numbers.
stack trace
I believe the culprit is the annotation of the compressed matrix being too restricted in the SparseMatrixColorings extensions, I locally changed this into more generic ones and the errors are gone.
https://github.com/JuliaDiff/DifferentiationInterface.jl/blob/cc8818a2bb0fb3dab2abf29ba213f89213a8613a/DifferentiationInterface/ext/DifferentiationInterfaceSparseMatrixColoringsExt/jacobian.jl#L3-L33