Skip to content

Commit

Permalink
Merge branch 'master' into phg/densityinterface
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored May 6, 2024
2 parents 0351101 + d5ae280 commit 3760e45
Show file tree
Hide file tree
Showing 61 changed files with 5,226 additions and 563 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,14 @@ jobs:
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
with:
coverage: ${{ matrix.version == '1' && matrix.os == 'ubuntu-latest' && matrix.num_threads == 1 }}
env:
GROUP: All
JULIA_NUM_THREADS: ${{ matrix.num_threads }}
- uses: julia-actions/julia-processcoverage@v1
if: matrix.version == '1' && matrix.os == 'ubuntu-latest' && matrix.num_threads == 1
- uses: codecov/codecov-action@v1
if: matrix.version == '1' && matrix.os == 'ubuntu-latest' && matrix.num_threads == 1
with:
file: lcov.info
- uses: coverallsapp/github-action@master
if: matrix.version == '1' && matrix.os == 'ubuntu-latest' && matrix.num_threads == 1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.jl.mem
.DS_Store
Manifest.toml
**.~undo-tree~
58 changes: 47 additions & 11 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,39 +1,75 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.23.1"
version = "0.25.3"


[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
AbstractPPL = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
Bijectors = "76274a88-744f-5084-9051-94815aaf08c4"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
LogDensityProblemsAD = "996a588d-648d-4e1f-a8f0-a84b347e47b1"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"

[weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"

[extensions]
DynamicPPLChainRulesCoreExt = ["ChainRulesCore"]
DynamicPPLEnzymeCoreExt = ["EnzymeCore"]
DynamicPPLForwardDiffExt = ["ForwardDiff"]
DynamicPPLMCMCChainsExt = ["MCMCChains"]
DynamicPPLReverseDiffExt = ["ReverseDiff"]
DynamicPPLZygoteRulesExt = ["ZygoteRules"]

[compat]
AbstractMCMC = "2, 3.0, 4"
AbstractPPL = "0.5.3"
BangBang = "0.3"
Bijectors = "0.13"
ChainRulesCore = "0.9.7, 0.10, 1"
ADTypes = "0.2, 1"
AbstractMCMC = "5"
AbstractPPL = "0.8.4"
Accessors = "0.1"
BangBang = "0.4.1"
Bijectors = "0.13.9"
ChainRulesCore = "1"
Compat = "4"
ConstructionBase = "1.5.4"
DensityInterface = "0.4"
ConstructionBase = "1"
Distributions = "0.23.8, 0.24, 0.25"
DocStringExtensions = "0.8, 0.9"
Distributions = "0.25"
DocStringExtensions = "0.9"
EnzymeCore = "0.6, 0.7"
LinearAlgebra = "1.6"
LogDensityProblems = "2"
LogDensityProblemsAD = "1.7.0"
MCMCChains = "6"
MacroTools = "0.5.6"
OrderedCollections = "1"
Setfield = "0.7.1, 0.8, 1"
Random = "1.6"
Requires = "1"
Test = "1.6"
ZygoteRules = "0.2"
julia = "1.6"

[extras]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"
1 change: 1 addition & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
To run the benchmarks, simply do:

```sh
julia --project -e 'using DynamicPPLBenchmarks; weave_benchmarks();'
```
Expand Down
13 changes: 8 additions & 5 deletions benchmarks/benchmark_body.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ results["evaluation_typed"]
```

```julia; echo=false; results="hidden";
BenchmarkTools.save(joinpath("results", WEAVE_ARGS[:name], "$(nameof(m))_benchmarks.json"), results)
BenchmarkTools.save(
joinpath("results", WEAVE_ARGS[:name], "$(nameof(m))_benchmarks.json"), results
)
```

```julia; wrap=false
Expand All @@ -32,15 +34,16 @@ end
```julia; echo=false; results="hidden"
if WEAVE_ARGS[:include_typed_code]
# Serialize the output of `typed_code` so we can compare later.
haskey(WEAVE_ARGS, :name) && serialize(joinpath("results", WEAVE_ARGS[:name],"$(nameof(m)).jls"), string(typed));
haskey(WEAVE_ARGS, :name) &&
serialize(joinpath("results", WEAVE_ARGS[:name], "$(nameof(m)).jls"), string(typed))
end
```

```julia; wrap=false; echo=false;
if haskey(WEAVE_ARGS, :name_old)
# We want to compare the generated code to the previous version.
import DiffUtils
typed_old = deserialize(joinpath("results", WEAVE_ARGS[:name_old], "$(nameof(m)).jls"));
DiffUtils.diff(typed_old, string(typed), width=130)
using DiffUtils: DiffUtils
typed_old = deserialize(joinpath("results", WEAVE_ARGS[:name_old], "$(nameof(m)).jls"))
DiffUtils.diff(typed_old, string(typed); width=130)
end
```
24 changes: 12 additions & 12 deletions benchmarks/benchmarks.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ import DynamicPPLBenchmarks: time_model_def, make_suite, typed_code, weave_child
m ~ Normal()
x ~ Normal(m, 1)

return (m = m, x = x)
return (m=m, x=x)
end

model_def = demo1;
data = 1.0;
```

```julia; results="markup"; echo=false
weave_child(WEAVE_ARGS[:benchmarkbody], mod = @__MODULE__, args = WEAVE_ARGS)
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS)
```

### `demo2`

```julia
@model function demo2(y)
@model function demo2(y)
# Our prior belief about the probability of heads in a coin.
p ~ Beta(1, 1)

Expand All @@ -50,7 +50,7 @@ data = rand(0:1, 10);
```

```julia; results="markup"; echo=false
weave_child(WEAVE_ARGS[:benchmarkbody], mod = @__MODULE__, args = WEAVE_ARGS)
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS)
```

### `demo3`
Expand All @@ -74,7 +74,7 @@ weave_child(WEAVE_ARGS[:benchmarkbody], mod = @__MODULE__, args = WEAVE_ARGS)
k = Vector{Int}(undef, N)
for i in 1:N
k[i] ~ Categorical(w)
x[:,i] ~ MvNormal([μ[k[i]], μ[k[i]]], 1.)
x[:, i] ~ MvNormal([μ[k[i]], μ[k[i]]], 1.0)
end
return k
end
Expand All @@ -88,11 +88,11 @@ N = 30
μs = [-3.5, 0.0]

# Construct the data points.
data = mapreduce(c -> rand(MvNormal([μs[c], μs[c]], 1.), N), hcat, 1:2);
data = mapreduce(c -> rand(MvNormal([μs[c], μs[c]], 1.0), N), hcat, 1:2);
```

```julia; echo=false
weave_child(WEAVE_ARGS[:benchmarkbody], mod = @__MODULE__, args = WEAVE_ARGS)
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS)
```

### `demo4`: loads of indexing
Expand All @@ -107,24 +107,24 @@ weave_child(WEAVE_ARGS[:benchmarkbody], mod = @__MODULE__, args = WEAVE_ARGS)
end

model_def = demo4
data = (100_000, );
data = (100_000,);
```

```julia; echo=false
weave_child(WEAVE_ARGS[:benchmarkbody], mod = @__MODULE__, args = WEAVE_ARGS)
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS)
```

```julia
@model function demo4_dotted(n, ::Type{TV}=Vector{Float64}) where {TV}
m ~ Normal()
x = TV(undef, n)
x .~ Normal(m, 1.0)
return x .~ Normal(m, 1.0)
end

model_def = demo4_dotted
data = (100_000, );
data = (100_000,);
```

```julia; echo=false
weave_child(WEAVE_ARGS[:benchmarkbody], mod = @__MODULE__, args = WEAVE_ARGS)
weave_child(WEAVE_ARGS[:benchmarkbody]; mod=@__MODULE__, args=WEAVE_ARGS)
```
7 changes: 4 additions & 3 deletions benchmarks/src/DynamicPPLBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using Markdown: Markdown

using LibGit2: LibGit2
using Pkg: Pkg
using Random: Random

export weave_benchmarks

Expand All @@ -33,9 +34,9 @@ function benchmark_typed_varinfo!(suite, m)
end

function typed_code(m, vi=VarInfo(m))
rng = DynamicPPL.Random.MersenneTwister(42)
spl = DynamicPPL.SampleFromPrior()
ctx = DynamicPPL.SamplingContext(rng, spl, DynamicPPL.DefaultContext())
rng = Random.MersenneTwister(42)
spl = SampleFromPrior()
ctx = SamplingContext(rng, spl, DefaultContext())

results = code_typed(m.f, Base.typesof(m, vi, ctx, m.args...))
return first(results)
Expand Down
10 changes: 5 additions & 5 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"

[compat]
Accessors = "0.1"
DataStructures = "0.18"
Distributions = "0.25"
Documenter = "0.27"
Documenter = "1"
FillArrays = "0.13, 1"
LogDensityProblems = "2"
MLUtils = "0.3, 0.4"
Setfield = "0.7.1, 0.8, 1"
MCMCChains = "5, 6"
StableRNGs = "1"
12 changes: 8 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using Documenter
using DynamicPPL
using DynamicPPL: AbstractPPL
# NOTE: This is necessary to ensure that if we print something from
# Distributions.jl in a doctest, then the shown value will not include
# a qualifier; that is, we don't want `Distributions.Normal{Float64}`
# but rather `Normal{Float64}`. The latter is what will then be printed
# in the doctest as run in `test/runtests.jl`, and so we need to stay
# consistent with that.
using Distributions

# Doctest setup
DocMeta.setdocmeta!(
DynamicPPL, :DocTestSetup, :(using DynamicPPL, Distributions); recursive=true
)
DocMeta.setdocmeta!(DynamicPPL, :DocTestSetup, :(using DynamicPPL); recursive=true)

makedocs(;
sitename="DynamicPPL",
Expand All @@ -16,7 +21,6 @@ makedocs(;
"API" => "api.md",
"Tutorials" => ["tutorials/prob-interface.md"],
],
strict=true,
checkdocs=:exports,
)

Expand Down
Loading

0 comments on commit 3760e45

Please sign in to comment.