Skip to content

Commit

Permalink
Fixes warnings during REPL startup while using custom SYSIMG's (#185)
Browse files Browse the repository at this point in the history
* Fixes warnings during REPL startup while using custom SYSIMG's

We encounter following warning during Julia REPL startup if we include DistributionsAD in the default SYSIMG, this commit fixes that issue

```
┌ Warning: Error requiring `ForwardDiff` from `DistributionsAD`
│   exception =
│    LoadError: SystemError: opening file "/home/bmharsha/.julia/packages/DistributionsAD/pj8zf/src/reversediffx.jl": No such file or directory
│    Stacktrace:
│      [1] systemerror(p::String, errno::Int32; extrainfo::Nothing)
│        @ Base ./error.jl:168
│      [2] #systemerror#62
│        @ ./error.jl:167 [inlined]
│      [3] systemerror
│        @ ./error.jl:167 [inlined]
│      [4] open(fname::String; lock::Bool, read::Nothing, write::Nothing, create::Nothing, truncate::Nothing, append::Nothing)
│        @ Base ./iostream.jl:293
│      [5] open
│        @ ./iostream.jl:282 [inlined]
│      [6] open(f::Base.var"#326#327"{String}, args::String; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
│        @ Base ./io.jl:328
│      [7] open
│        @ ./io.jl:328 [inlined]
│      [8] read
│        @ ./io.jl:434 [inlined]
│      [9] _include(mapexpr::Function, mod::Module, _path::String)
│        @ Base ./loading.jl:1166
│     [10] include(mod::Module, _path::String)
│        @ Base ./Base.jl:386
│     [11] include(x::String)
│        @ DistributionsAD.ReverseDiffX ./reversediff.jl:1
│     [12] top-level scope
│        @ reversediff.jl:55
│     [13] eval
│        @ ./boot.jl:360 [inlined]
│     [14] include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
│        @ Base ./loading.jl:1116
│     [15] include_string(m::Module, txt::String, fname::String)
│        @ Base ./loading.jl:1126
│     [16] macro expansion
│        @ ~/.julia/packages/Requires/7Ncym/src/Requires.jl:42 [inlined]
│     [17] top-level scope
│        @ ~/.julia/packages/DistributionsAD/pj8zf/src/DistributionsAD.jl:74
│     [18] eval
│        @ ./boot.jl:360 [inlined]
│     [19] eval
│        @ ~/.julia/packages/DistributionsAD/pj8zf/src/DistributionsAD.jl:1 [inlined]
│     [20] (::DistributionsAD.var"#331#334")()
│        @ DistributionsAD ~/.julia/packages/Requires/7Ncym/src/require.jl:99
│     [21] err(f::Any, listener::Module, modname::String)
│        @ Requires ~/.julia/packages/Requires/7Ncym/src/require.jl:47
│     [22] (::DistributionsAD.var"#330#333")()
│        @ DistributionsAD ~/.julia/packages/Requires/7Ncym/src/require.jl:98
│     [23] withpath(f::Any, path::String)
│        @ Requires ~/.julia/packages/Requires/7Ncym/src/require.jl:37
│     [24] (::DistributionsAD.var"#329#332")()
│        @ DistributionsAD ~/.julia/packages/Requires/7Ncym/src/require.jl:97
│     [25] listenpkg(f::Any, pkg::Base.PkgId)
│        @ Requires ~/.julia/packages/Requires/7Ncym/src/require.jl:20
│     [26] macro expansion
│        @ ~/.julia/packages/Requires/7Ncym/src/require.jl:95 [inlined]
│     [27] top-level scope
│        @ ~/.julia/packages/DistributionsAD/pj8zf/src/DistributionsAD.jl:73
│     [28] eval
│        @ ./boot.jl:360 [inlined]
│     [29] eval
│        @ ~/.julia/packages/DistributionsAD/pj8zf/src/DistributionsAD.jl:1 [inlined]
│     [30] (::DistributionsAD.var"#307#320")()
│        @ DistributionsAD ~/.julia/packages/Requires/7Ncym/src/require.jl:99
│     [31] err(f::Any, listener::Module, modname::String)
│        @ Requires ~/.julia/packages/Requires/7Ncym/src/require.jl:47
│     [32] (::DistributionsAD.var"#306#319")()
│        @ DistributionsAD ~/.julia/packages/Requires/7Ncym/src/require.jl:98
│     [33] withpath(f::Any, path::String)
│        @ Requires ~/.julia/packages/Requires/7Ncym/src/require.jl:37
│     [34] (::DistributionsAD.var"#305#318")()
│        @ DistributionsAD ~/.julia/packages/Requires/7Ncym/src/require.jl:97
│     [35] listenpkg(f::Any, pkg::Base.PkgId)
│        @ Requires ~/.julia/packages/Requires/7Ncym/src/require.jl:20
│     [36] macro expansion
│        @ ~/.julia/packages/Requires/7Ncym/src/require.jl:95 [inlined]
│     [37] macro expansion
│        @ ~/.julia/packages/DistributionsAD/pj8zf/src/DistributionsAD.jl:70 [inlined]
│     [38] (::DistributionsAD.var"#301#314")()
│        @ DistributionsAD ~/.julia/packages/Requires/7Ncym/src/init.jl:11
│     [39] __init__()
│        @ DistributionsAD ~/.julia/packages/Requires/7Ncym/src/init.jl:18
│    in expression starting at reversediff.jl:1
└ @ Requires ~/.julia/packages/Requires/7Ncym/src/require.jl:49
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.2 (2021-07-14)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

�[?2004h
�[0Kjulia>
�[7C
�[7C
�[?2004l
```

* Bumps the version number in Project.toml

Preparing for a minor release

* Reverts the usage of Requires.@include Macro
  • Loading branch information
bmharsha authored Aug 19, 2021
1 parent c2a5918 commit 0ee831b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DistributionsAD"
uuid = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
version = "0.6.28"
version = "0.6.29"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
79 changes: 78 additions & 1 deletion src/reversediff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,84 @@ using ..DistributionsAD: TuringPoissonBinomial,
VectorOfMultivariate,
FillVectorOfMultivariate

include("reversediffx.jl")
###############
## logsumexp ##
###############

logsumexp(x::TrackedArray; dims=:) = track(logsumexp, x, dims = dims)
@grad function logsumexp(x::AbstractArray; dims)
x_value = value(x)
lse = logsumexp(x_value; dims=dims)
return lse, Δ ->.* exp.(x_value .- lse),)
end

############
## linalg ##
############

function LinearAlgebra.cholesky(A::Symmetric{<:Any, <:TrackedMatrix}; check=true)
uplo = A.uplo == 'U' ? (:U) : (:L)
factors, info = symm_turing_chol(parent(A), check, uplo)
return Cholesky{eltype(factors), typeof(factors)}(factors, 'U', info)
end
function LinearAlgebra.cholesky(A::TrackedMatrix; check=true)
factors, info = turing_chol(A, check)
return Cholesky{eltype(factors), typeof(factors)}(factors, 'U', info)
end

function symm_turing_chol(x::TrackedArray{V,D}, check, uplo) where {V,D}
tp = tape(x)
x_value = value(x)
(factors,info), back = DistributionsAD.symm_turing_chol_back(x_value, check, uplo)
C = Cholesky{eltype(factors), typeof(factors)}(factors, 'U', info)
out = track(C.factors, D, tp)
record!(tp, SpecialInstruction, symm_turing_chol, (x, check, uplo), out, (back, issuccess(C)))
return out, C.info
end
function turing_chol(x::TrackedArray{V,D}, check) where {V,D}
tp = tape(x)
x_value = value(x)
(factors,info), back = DistributionsAD.turing_chol_back(x_value, check)
C = Cholesky{eltype(factors), typeof(factors)}(factors, 'U', info)
out = track(C.factors, D, tp)
record!(tp, SpecialInstruction, turing_chol, (x, check), out, (back, issuccess(C)))
return out, C.info
end

for f in (:turing_chol, :symm_turing_chol)
@eval begin
@noinline function ReverseDiff.special_reverse_exec!(
instruction::SpecialInstruction{typeof($f)},
)
output = instruction.output
instruction.cache[2] || throw(PosDefException(C.info))
input = instruction.input
input_deriv = deriv(input[1])
P = instruction.cache[1]
input_deriv .+= P((factors = deriv(output),))[1]
unseed!(output)
return nothing
end
end
end

@noinline function ReverseDiff.special_forward_exec!(
instruction::SpecialInstruction{typeof(turing_chol)},
)
output, input = instruction.output, instruction.input
factors = turing_chol(value.(input)...)[1]
value!(output, factors)
return nothing
end

@noinline function ReverseDiff.special_forward_exec!(
instruction::SpecialInstruction{typeof(symm_turing_chol)},
)
output, input = instruction.output, instruction.input
factors = symm_turing_chol(value.(input)...)[1]
value!(output, factors)
return nothing
end

adapt_randn(rng::Random.AbstractRNG, x::TrackedArray, dims...) = adapt_randn(rng, value(x), dims...)

Expand Down
82 changes: 0 additions & 82 deletions src/reversediffx.jl

This file was deleted.

2 comments on commit 0ee831b

@yebai
Copy link
Member

@yebai yebai commented on 0ee831b Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/43121

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.29 -m "<description of version>" 0ee831b2132128fab97aa826dfa786675e1bface
git push origin v0.6.29

Please sign in to comment.