Skip to content

Commit

Permalink
Also pass in context as an argument to acclogp!! (#563)
Browse files Browse the repository at this point in the history
* also pass in `context` as an argument to `acclogp!!`

* Update src/utils.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* bump patch version

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
torfjelde and github-actions[bot] authored Nov 20, 2023
1 parent c9489aa commit 34be85c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.24.1"
version = "0.24.2"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
12 changes: 10 additions & 2 deletions src/abstract_varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,20 @@ Set the log of the joint probability of the observed data and parameters sampled
function setlogp!! end

"""
acclogp!!(vi::AbstractVarInfo, logp)
acclogp!!([context::AbstractContext, ]vi::AbstractVarInfo, logp)
Add `logp` to the value of the log of the joint probability of the observed data and
parameters sampled in `vi`, mutating if it makes sense.
"""
function acclogp!! end
function acclogp!!(context::AbstractContext, vi::AbstractVarInfo, logp)
return acclogp!!(NodeTrait(context), context, vi, logp)
end
function acclogp!!(::IsLeaf, context::AbstractContext, vi::AbstractVarInfo, logp)
return acclogp!!(vi, logp)
end
function acclogp!!(::IsParent, context::AbstractContext, vi::AbstractVarInfo, logp)
return acclogp!!(childcontext(context), vi, logp)
end

"""
resetlogp!!(vi::AbstractVarInfo)
Expand Down
8 changes: 4 additions & 4 deletions src/context_implementations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ probability of `vi` with the returned value.
"""
function tilde_assume!!(context, right, vn, vi)
value, logp, vi = tilde_assume(context, right, vn, vi)
return value, acclogp!!(vi, logp)
return value, acclogp!!(context, vi, logp)
end

# observe
Expand Down Expand Up @@ -181,7 +181,7 @@ probability of `vi` with the returned value.
"""
function tilde_observe!!(context, right, left, vi)
logp, vi = tilde_observe(context, right, left, vi)
return left, acclogp!!(vi, logp)
return left, acclogp!!(context, vi, logp)
end

function assume(rng, spl::Sampler, dist)
Expand Down Expand Up @@ -383,7 +383,7 @@ Falls back to `dot_tilde_assume(context, right, left, vn, vi)`.
"""
function dot_tilde_assume!!(context, right, left, vn, vi)
value, logp, vi = dot_tilde_assume(context, right, left, vn, vi)
return value, acclogp!!(vi, logp), vi
return value, acclogp!!(context, vi, logp), vi
end

# `dot_assume`
Expand Down Expand Up @@ -634,7 +634,7 @@ Falls back to `dot_tilde_observe(context, right, left, vi)`.
"""
function dot_tilde_observe!!(context, right, left, vi)
logp, vi = dot_tilde_observe(context, right, left, vi)
return left, acclogp!!(vi, logp)
return left, acclogp!!(context, vi, logp)
end

# Falls back to non-sampler definition.
Expand Down
4 changes: 3 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ true
"""
macro addlogprob!(ex)
return quote
$(esc(:(__varinfo__))) = acclogp!!($(esc(:(__varinfo__))), $(esc(ex)))
$(esc(:(__varinfo__))) = acclogp!!(
$(esc(:(__context__))), $(esc(:(__varinfo__))), $(esc(ex))
)
end
end

Expand Down

2 comments on commit 34be85c

@torfjelde
Copy link
Member Author

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/95695

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.24.2 -m "<description of version>" 34be85c6371cf4d0fe9f9db5c74a3fa7527452f7
git push origin v0.24.2

Please sign in to comment.