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

[Merged by Bors] - Re-opening of #310 #330

Closed
wants to merge 55 commits into from
Closed
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
1388502
show full timings for evaluation rather than just min
torfjelde Jul 14, 2021
678ef1d
initial work on allowing more than just real and array variables
torfjelde Jul 27, 2021
ddf761c
Merge branch 'master' into tor/allow-non-array-variables
torfjelde Jul 28, 2021
b867d00
ensure that varname uses concretize
torfjelde Jul 29, 2021
6ad5d95
update PointwiseLikelihoodContext
torfjelde Jul 29, 2021
4bf663f
update unwrap_right_left_vns and fix
torfjelde Jul 29, 2021
e4922c9
formatting
torfjelde Jul 29, 2021
ab4b384
fixed doctest
torfjelde Jul 30, 2021
9dadb3a
Merge branch 'tor/allow-non-array-variables' of github.com:TuringLang…
torfjelde Jul 30, 2021
26216e3
forgot to remove escaping some places
torfjelde Jul 31, 2021
405d52c
removed usage of Setfield.set for .= and some other niceties
torfjelde Jul 31, 2021
505d690
fixed a doctests that will inevitably fail on Julia 1.3
torfjelde Jul 31, 2021
9f8c47b
updated a comment
torfjelde Jul 31, 2021
0a47953
added deprecations of the tildes
torfjelde Jul 31, 2021
0c51329
Update src/DynamicPPL.jl
torfjelde Jul 31, 2021
54f8c89
Merge branch 'master' into tor/benchmark-improvements
torfjelde Jul 31, 2021
d3fe07c
Merge branch 'tor/benchmark-improvements' into tor/allow-non-array-va…
torfjelde Jul 31, 2021
8134a1a
use impl of get for VarName instead of the hacky stuff we currently have
torfjelde Aug 1, 2021
9d3c1dd
uncomment commented out test suite
torfjelde Aug 1, 2021
5c4bf0e
Merge branch 'master' into tor/allow-non-array-variables
torfjelde Aug 1, 2021
4121b0e
use BangBang to prefer mutation when using set
torfjelde Aug 1, 2021
a38168a
remove redundant and outdated tests for VarInfo in integration tests
torfjelde Aug 1, 2021
51e7426
formatting
torfjelde Aug 1, 2021
0a3655d
no longer need the custom make_set method after Setfield v0.7.1
torfjelde Aug 1, 2021
f82579e
formatting
torfjelde Aug 1, 2021
9aa7298
drop concretize argument to varname
torfjelde Aug 1, 2021
b130db9
added a couple of additional benchmarks
torfjelde Aug 1, 2021
1ae04b3
Merge branch 'master' into tor/allow-non-array-variables
torfjelde Aug 17, 2021
475da88
fixed tests
torfjelde Aug 17, 2021
4af7e30
formatting
torfjelde Aug 17, 2021
e03ef4e
Update src/context_implementations.jl
torfjelde Aug 17, 2021
5741d67
Get rid of repeated construction of varname lenses
phipsgabler Aug 21, 2021
47679d4
Apply suggestions from code review
phipsgabler Aug 30, 2021
7f27aed
Apply suggested edits & fix bugs
phipsgabler Aug 30, 2021
0ca5169
Remove old now misleading comment
phipsgabler Aug 30, 2021
a5705dd
Merge branch 'master' into phg/redundant_lenses
torfjelde Sep 11, 2021
7a51b27
replaced getindexing with getlens
torfjelde Sep 11, 2021
b90a747
formatting
torfjelde Sep 11, 2021
cb074cb
minor version bump
torfjelde Sep 14, 2021
ecf1e5d
attempt at fixing error doctest
torfjelde Dec 14, 2021
917334b
Update src/submodel_macro.jl
torfjelde Dec 14, 2021
29d692a
capture return-value in submodel
torfjelde Dec 14, 2021
73962ad
Merge branch 'tor/submodels-hotfixes' of github.com:TuringLang/Dynami…
torfjelde Dec 14, 2021
9ee336b
formatting and added test for return-value and submodel
torfjelde Dec 14, 2021
ce0a3e8
fixed typo
torfjelde Dec 14, 2021
59303d7
fix CI so as to not break poor bors
torfjelde Dec 14, 2021
274aebb
added docfilter for nested LoadError
torfjelde Dec 14, 2021
ef0faa5
Update docs/make.jl
torfjelde Dec 14, 2021
9ecb939
fixed doctestfilter
torfjelde Dec 14, 2021
c4e91a0
added LoadError doctest filter to tests
torfjelde Dec 14, 2021
9b32797
improved the LoadError filter
torfjelde Dec 14, 2021
ad049c2
updated turing tests compat bound
torfjelde Dec 14, 2021
705b1d3
Merge branch 'tor/submodels-hotfixes' into phg/redundant_lenses
torfjelde Dec 14, 2021
8e52e8e
Merge branch 'master' into phg/redundant_lenses
torfjelde Dec 14, 2021
29fb53a
fixed docstring and style
torfjelde Dec 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions src/compiler.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const INTERNALNAMES = (:__model__, :__context__, :__varinfo__)

"""
isassumption(expr)
isassumption(expr[, vn])

Return an expression that can be evaluated to check if `expr` is an assumption in the
model.
Expand All @@ -13,39 +13,44 @@ Let `expr` be `:(x[1])`. It is an assumption in the following cases:
but `x[1] === missing`.

When `expr` is not an expression or symbol (i.e., a literal), this expands to `false`.
"""
function isassumption(expr::Union{Symbol,Expr})
vn = gensym(:vn)

If `vn` is specified, it will be assumed to refer to a expression which
evaluates to a `VarName`, and this will be used in the subsequent checks.
If `vn` is not specified, `AbstractPPL.drop_escape(varname(expr))` will be
used in its place.
"""
function isassumption(expr::Union{Expr,Symbol}, vn=AbstractPPL.drop_escape(varname(expr)))
return quote
let $vn = $(AbstractPPL.drop_escape(varname(expr)))
if $(DynamicPPL.contextual_isassumption)(__context__, $vn)
# Considered an assumption by `__context__` which means either:
# 1. We hit the default implementation, e.g. using `DefaultContext`,
# which in turn means that we haven't considered if it's one of
# the model arguments, hence we need to check this.
# 2. We are working with a `ConditionContext` _and_ it's NOT in the model arguments,
# i.e. we're trying to condition one of the latent variables.
# In this case, the below will return `true` since the first branch
# will be hit.
# 3. We are working with a `ConditionContext` _and_ it's in the model arguments,
# i.e. we're trying to override the value. This is currently NOT supported.
# TODO: Support by adding context to model, and use `model.args`
# as the default conditioning. Then we no longer need to check `inargnames`
# since it will all be handled by `contextual_isassumption`.
if !($(DynamicPPL.inargnames)($vn, __model__)) ||
$(DynamicPPL.inmissings)($vn, __model__)
true
else
$(maybe_view(expr)) === missing
end
if $(DynamicPPL.contextual_isassumption)(__context__, $vn)
# Considered an assumption by `__context__` which means either:
# 1. We hit the default implementation, e.g. using `DefaultContext`,
# which in turn means that we haven't considered if it's one of
# the model arguments, hence we need to check this.
# 2. We are working with a `ConditionContext` _and_ it's NOT in the model arguments,
# i.e. we're trying to condition one of the latent variables.
# In this case, the below will return `true` since the first branch
# will be hit.
# 3. We are working with a `ConditionContext` _and_ it's in the model arguments,
# i.e. we're trying to override the value. This is currently NOT supported.
# TODO: Support by adding context to model, and use `model.args`
# as the default conditioning. Then we no longer need to check `inargnames`
# since it will all be handled by `contextual_isassumption`.
if !($(DynamicPPL.inargnames)($vn, __model__)) ||
$(DynamicPPL.inmissings)($vn, __model__)
true
else
false
$(maybe_view(expr)) === missing
end
else
false
end
end
end

# failsafe: a literal is never an assumption
isassumption(expr, vn) = :(false)
isassumption(expr) = :(false)

"""
contextual_isassumption(context, vn)

Expand Down Expand Up @@ -79,9 +84,6 @@ function contextual_isassumption(context::PrefixContext, vn)
return contextual_isassumption(childcontext(context), prefix(context, vn))
end

# failsafe: a literal is never an assumption
isassumption(expr) = :(false)

# If we're working with, say, a `Symbol`, then we're not going to `view`.
maybe_view(x) = x
maybe_view(x::Expr) = :(@views($x))
Expand Down Expand Up @@ -382,7 +384,7 @@ function generate_tilde(left, right)
# more selective with our escape. Until that's the case, we remove them all.
return quote
$vn = $(AbstractPPL.drop_escape(varname(left)))
$isassumption = $(DynamicPPL.isassumption(left))
$isassumption = $(DynamicPPL.isassumption(left, vn))
if $isassumption
$(generate_tilde_assume(left, right, vn))
else
Expand Down Expand Up @@ -439,7 +441,7 @@ function generate_dot_tilde(left, right)
@gensym vn isassumption value
return quote
$vn = $(AbstractPPL.drop_escape(varname(left)))
$isassumption = $(DynamicPPL.isassumption(left))
$isassumption = $(DynamicPPL.isassumption(left, vn))
if $isassumption
$(generate_dot_tilde_assume(left, right, vn))
else
Expand Down