Skip to content

Conversation

@torfjelde
Copy link
Member

This PR moves most of the mutating methods to the bang-bang convention + some changes to the compiler to allow the usage of immutable implementations of AbstractVarInfo.

The major change in the compiler is that we replace all return-statements with return (retval, __varinfo__), ensuring that we preserve support for features such as submodels.

Note that the (m::Model)(...) evaluator still only returns the original return-value, and thus from a user-perspective, nothing has changed. But methods such as _evaluate(m::Model, ...) now return a tuple with AbstractVarInfo as the second argument.

Most of the methods we can gracefully depreciate, with the only breaking change being x = @submodel m(...) no longer works since we need to handle the additional return-value, hence this has changed to @submodel x = m(...).

The original motivation of the work in this PR is to make something like #267 feasible.

torfjelde and others added 30 commits May 31, 2021 20:10
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
@torfjelde torfjelde force-pushed the tor/immutable-varinfo-support branch from 9bee395 to c3da562 Compare August 14, 2021 00:26
src/varinfo.jl Outdated
"""
function settrans!(vi::AbstractVarInfo, trans::Bool, vn::VarName)
return trans ? set_flag!(vi, vn, "trans") : unset_flag!(vi, vn, "trans")
function settrans!(vi::AbstractVarInfo, trans::Bool, vn::Union{VarName,AbstractArray{<:VarName}})
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function settrans!(vi::AbstractVarInfo, trans::Bool, vn::Union{VarName,AbstractArray{<:VarName}})
function settrans!(
vi::AbstractVarInfo, trans::Bool, vn::Union{VarName,AbstractArray{<:VarName}}
)

src/varinfo.jl Outdated
foreach(vns) do vn
unset_flag!(vi, vn, flag)
end

Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

@yebai
Copy link
Member

yebai commented Aug 31, 2021

Closed in facour of #309

@yebai yebai closed this Aug 31, 2021
bors bot pushed a commit that referenced this pull request Sep 8, 2021
This PR adds a `DynamicPPL.TestUtils` submodule which is meant to include functionality to make it easy to test new samplers, new implementations of `AbstractVarInfo`, etc.

As of right now, this is mainly just a collection of models with equivalent marginal posteriors using the different features of DPPL, e.g. some are using `.~`, some are using `@submodel`, etc.

Eventually this should be expanded to be of more use, but more immediately this will be useful to test functionality in open PRs, e.g. #269, #309, #295, #292.

These models are also already used in Turing.jl's test-suite (https://github.com/TuringLang/Turing.jl/blob/9f52d75c25390b68115624b2e6cf464275a88137/test/test_utils/models.jl#L55-L56), so this PR would avoid the code-duplication + make it easier to keep things up-to-date.
bors bot pushed a commit that referenced this pull request Sep 9, 2021
This PR adds a `DynamicPPL.TestUtils` submodule which is meant to include functionality to make it easy to test new samplers, new implementations of `AbstractVarInfo`, etc.

As of right now, this is mainly just a collection of models with equivalent marginal posteriors using the different features of DPPL, e.g. some are using `.~`, some are using `@submodel`, etc.

Eventually this should be expanded to be of more use, but more immediately this will be useful to test functionality in open PRs, e.g. #269, #309, #295, #292.

These models are also already used in Turing.jl's test-suite (https://github.com/TuringLang/Turing.jl/blob/9f52d75c25390b68115624b2e6cf464275a88137/test/test_utils/models.jl#L55-L56), so this PR would avoid the code-duplication + make it easier to keep things up-to-date.
bors bot pushed a commit that referenced this pull request Sep 9, 2021
This PR adds a `DynamicPPL.TestUtils` submodule which is meant to include functionality to make it easy to test new samplers, new implementations of `AbstractVarInfo`, etc.

As of right now, this is mainly just a collection of models with equivalent marginal posteriors using the different features of DPPL, e.g. some are using `.~`, some are using `@submodel`, etc.

Eventually this should be expanded to be of more use, but more immediately this will be useful to test functionality in open PRs, e.g. #269, #309, #295, #292.

These models are also already used in Turing.jl's test-suite (https://github.com/TuringLang/Turing.jl/blob/9f52d75c25390b68115624b2e6cf464275a88137/test/test_utils/models.jl#L55-L56), so this PR would avoid the code-duplication + make it easier to keep things up-to-date.
@yebai yebai deleted the tor/immutable-varinfo-support branch September 14, 2021 19:24
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

Successfully merging this pull request may close these issues.

4 participants