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

No method matching Irrational{:log2π} #521

Closed
maxmouchet opened this issue Feb 20, 2020 · 13 comments
Closed

No method matching Irrational{:log2π} #521

maxmouchet opened this issue Feb 20, 2020 · 13 comments

Comments

@maxmouchet
Copy link

This seems similar to #309.

On Julia v1.3, Zygote v0.4.7 and Distributions v0.22.4:

using Distributions, Zygote

f(x) = logpdf(Normal(), x)
f(0.0) # -0.9189385332046728
f'(0.0)
# MethodError: no method matching Irrational{:log2π}(::Int64)
# Closest candidates are:
#  Irrational{:log2π}(::T) where T<:Number at boot.jl:718
#  Irrational{:log2π}() where sym at irrationals.jl:18
#  Irrational{:log2π}(!Matched::Complex) where T<:Real at complex.jl:37
@jessebett
Copy link

Yes, also getting this bug trying to differentiate through Normals

@mohamed82008
Copy link
Contributor

See JuliaLang/julia#34773. If you copy the code from that PR, the error should go away.

@mohamed82008
Copy link
Contributor

Also the next release of DistributionsAD.jl will fix this.

@jessebett
Copy link

Okay but can you give a previous version of Distributions that doesn't have this error? Working on an assignment starter code and students won't be expected to patch julia...

@mohamed82008
Copy link
Contributor

I am not sure which version. You can possibly make a file for them to include directly in their code. If you use the DistributionsAD#master now, your code should work. And in about week, a new release will be made.

@jessebett
Copy link

I'll try pinning DistributionsAD#master now

@mohamed82008
Copy link
Contributor

Or just pin DiffRules to 1.0.0 instead.

@mohamed82008
Copy link
Contributor

If you need nothing else from DistributionsAD.

@mohamed82008
Copy link
Contributor

If Zygote uses Compat.jl, this issue should be solved.

@CarloLucibello
Copy link
Member

@mohamed82008 using DistributionsAD the OP example is still not working. How am I supposed to use DistributionsAD?

@maxmouchet
Copy link
Author

maxmouchet commented Jun 3, 2020

On Julia v.1.4.2, Zygote v0.4.20, Distributions v0.23.2 and DistributionsAD v0.5.3:

using Distributions, DistributionsAD, Zygote

f(x) = logpdf(Normal(), x)
f(0.0) # -0.9189385332046728
f'(0.0) # -0.0

@NightMachinery
Copy link

I get this error on Zygote 0.5.3 and julia version 1.4.1:

julia> function poi(λ, x)
           ((ℯ^-λ)*(λ^x))/factorial(x)
       end
poi (generic function with 1 method)

julia> h(x) = poi(1,1) + x
h (generic function with 1 method)

julia> h(1)
1.3678794411714423

julia> h'(1)
ERROR: MethodError: no method matching Irrational{:ℯ}(::Int64)
Closest candidates are:
  Irrational{:ℯ}(::T) where T<:Number at boot.jl:715
  Irrational{:ℯ}() where sym at irrationals.jl:18
  Irrational{:ℯ}(::Complex) where T<:Real at complex.jl:37
  ...
Stacktrace:
 [1] convert(::Type{Irrational{:ℯ}}, ::Int64) at ./number.jl:7
 [2] one(::Type{Irrational{:ℯ}}) at ./number.jl:276
 [3] one(::Irrational{:ℯ}) at ./number.jl:277
 [4] (::ChainRules.var"#583#^_pullback#151"{Irrational{:ℯ},Int64,Float64})(::Float64) at /Users/evar/.julia/packages/ChainRulesCore/b8RFI/src/rule_definition_tools.jl:195
 [5] ZBack at /Users/evar/.julia/packages/Zygote/iFibI/src/compiler/chainrules.jl:75 [inlined]
 [6] poi at ./REPL[89]:2 [inlined]
 [7] (::typeof(∂(poi)))(::Float64) at /Users/evar/.julia/packages/Zygote/iFibI/src/compiler/interface2.jl:0
 [8] h at ./REPL[90]:1 [inlined]
 [9] (::typeof(∂(h)))(::Float64) at /Users/evar/.julia/packages/Zygote/iFibI/src/compiler/interface2.jl:0
 [10] (::Zygote.var"#41#42"{typeof(∂(h))})(::Float64) at /Users/evar/.julia/packages/Zygote/iFibI/src/compiler/interface.jl:45
 [11] gradient(::Function, ::Int64) at /Users/evar/.julia/packages/Zygote/iFibI/src/compiler/interface.jl:54
 [12] (::Zygote.var"#43#44"{typeof(h)})(::Int64) at /Users/evar/.julia/packages/Zygote/iFibI/src/compiler/interface.jl:57
 [13] top-level scope at REPL[92]:1

@sethaxen
Copy link
Contributor

I'm pretty sure this is the offending line of code, and yes, this should be fixed once one(::Irrational) works: https://github.com/JuliaDiff/ChainRules.jl/blob/v0.7.12/src/rulesets/Base/fastmath_able.jl#L144

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

6 participants