Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with gradient when using tensors with Float64 and ComplexF64 entries #90

Closed
philihps opened this issue Nov 10, 2023 · 4 comments

Comments

@philihps
Copy link

philihps commented Nov 10, 2023

I am trying to compute the gradient of function, that takes a matrix as input and contracts with another tensor. If both tensors have either Float64 or ComplexF64 values, the Zygote gradient works. However, if one has Float64 and the other one ComplexF64 entries, it fails and returns an InexactError: Float64() error. Below I provide a MWE, which has the same behaviour as the actual function I need.

normDiff(a, b) = norm(a - b);

A = TensorMap(randn, Float64, ComplexSpace(2), ComplexSpace(2));
B = TensorMap(randn, Float64, ComplexSpace(2), ComplexSpace(2));
Zygote.gradient((x, y) -> normDiff(x, y), A, B)

A = TensorMap(randn, ComplexF64, ComplexSpace(2), ComplexSpace(2));
B = TensorMap(randn, ComplexF64, ComplexSpace(2), ComplexSpace(2));
Zygote.gradient((x, y) -> normDiff(x, y), A, B)

A = TensorMap(randn, Float64, ComplexSpace(2), ComplexSpace(2));
B = TensorMap(randn, ComplexF64, ComplexSpace(2), ComplexSpace(2));
Zygote.gradient((x, y) -> normDiff(x, y), A, B)
@Jutho
Copy link
Owner

Jutho commented Nov 15, 2023

Could you test this with the master version of TensorKit.jl? There was some fix for the chainrules in the case of mixed scalartype, which was not yet included in the latest registered version. We will provide a version update soon.

@Gertian
Copy link
Contributor

Gertian commented Nov 16, 2023

I had the same problem and updating TensorKit.jl to the current master fixed it.

@philihps
Copy link
Author

Thanks, using the current master fixes the problem.

@lkdvos
Copy link
Collaborator

lkdvos commented Jan 7, 2024

Tagged in v0.12.1

@lkdvos lkdvos closed this as completed Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants