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

[ITensors] [BUG] logdot and lognorm are not compatible with AD due to try/catch #77

Open
ArtemStrashko opened this issue Oct 21, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@ArtemStrashko
Copy link

ArtemStrashko commented Oct 21, 2022

Description of bug

Due to try/catch in lognorm and logdot, they are not supported by AD.

Minimal code demonstrating the bug or unexpected behavior

Minimal runnable code

l1 = x -> logdot(x, b)
l2 = x -> lognorm(x, b)
l3 = x -> norm(x, b)
inds = [Index(2) for _ in 1:10]
a = randomMPS(inds)
b = randomMPS(inds)
l1'(a)
l2'(a)
l3'(a)

Expected output or behavior

Return a valid gradient.

Actual output or behavior

Output of minimal runnable code

Compiling Tuple{ITensors.var"##_log_or_not_dot#663", Bool, typeof(ITensors._log_or_not_dot), MPS, MPS, Bool}: try/catch is not supported.

Version information

  • Output from versioninfo():
julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf260 (2022-09-29 15:21 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.3.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 1 on 8 virtual cores
  • Output from using Pkg; Pkg.status("ITensors"):
julia> using Pkg; Pkg.status("ITensors")
Status `~/.julia/environments/v1.8/Project.toml`
  [9136182c] ITensors v0.3.20
@ArtemStrashko ArtemStrashko added the bug Something isn't working label Oct 21, 2022
@mtfishman
Copy link
Member

Thanks for the report @ArtemStrashko. I think you mean l2 = x -> lognorm(x) in the example you show?

I was thinking of handling this by defining custom rrules for logdot/lognorm by using the chain rule for log(dot(x, y)) and log(norm(x)) and making use of the fact that dot(x, y) and norm(x) already have derivatives defined. So basically define the rrule by explicitly using that d(logdot(x, y))/dx = inv(dot(x, y)) * d(dot(x, y))/dx and use the result for d(dot(x, y))/dx from the rrule written for that function.

I won't have time to investigate this right now but feel free to take a look at it if you are interested.

@mtfishman mtfishman transferred this issue from ITensor/ITensors.jl Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants