-
Notifications
You must be signed in to change notification settings - Fork 37
Allow usage of array literals on LHS of ~
#261
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
Conversation
|
It seems this fails if one writes [x, y] ~ ...where |
|
So maybe only default to being an observation statement if it is an array of literals and otherwise determine it in |
|
Yep, that will result in those variables being treated as literal observations. But unclear to me how we can allow this for variables 😕 |
|
|
I guess it is OK to check it recursively? The |
Think that's going to be quite complicated though since when to perform the checks is unclear. Do you check Or are you referring to checking whether it's a literal or not? E.g. just traversing the expression, ensuring that all args are literals? If so, that makes 👍
Yeah fair, I'm fine that 👍
Well, that also holds for also allowing it 😅 But I agree, I'll add a |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
bors try |
| """ | ||
| isliteral(e) = false | ||
| isliteral(::Number) = true | ||
| isliteral(e::Expr) = !isempty(e.args) && all(isliteral, e.args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a bit general, e.g., also tuples of numbers or arrays of tuples of numbers or arrays of arrays of numbers etc are considered as literals now, in contrast to what the docstring mentions. But maybe this was your intention?
In any case, I guess it would be good to add some simple tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my intention yeah. These might still throw errors later when calling the model, e.g. mby there's no impl for assume for a tuple, but figured it was a good idea to not be very restrictive in the actual model-macro as we/people might add implementations for their distribution or w/e.
In any case, I guess it would be good to add some simple tests.
Yeah I'll add some 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good now?
tryBuild failed: |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
Waiting for new release of Bijectors.jl to hit. Should I update the compat bounds for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, probably good to update the compatibilities for the tests if this fixes the test errors.
|
An additional thought: is it necessary to update the compatibilities also in Project.toml? |
I guess the annoying part is that if it doesn't update automatically, i.e. some package restricts Bijectors.jl to an older version, you're stuck untill the package updates even though nor you or the package every runs into this error. My general "rule" for whether to bump patch-version in compat entries is if the bug is significant and silent. This is neither so to me it's whatever. |
|
I don't mind either, let's just keep them for now then, I guess. |
|
bors r+ |
Currently: ```julia julia> using DynamicPPL julia> @model function gdemo6() # `assume` and literal `observe` m ~ MvNormal(2, 1.0) [10.0, 10.0] ~ MvNormal(m, 0.5 * ones(2)) end ERROR: LoadError: "Malformed variable name [10.0, 10.0]!" Stacktrace: [1] varname(expr::Expr) @ AbstractPPL ~/.julia/packages/AbstractPPL/CyEC9/src/varname.jl:258 [2] generate_tilde(left::Expr, right::Expr) @ DynamicPPL ~/.julia/packages/DynamicPPL/emAbx/src/compiler.jl:258 [3] generate_mainbody!(mod::Module, found::Vector{Symbol}, expr::Expr, warn::Bool) ... ``` This also means that using variables in this manner on the LHS isn't allowed, e.g. observe on something `[x, x]`. Therefore, we might as well just treat it as literals. This also make it possible to write `[x, x] ~ ...` where `x` is an argument to the model. This PR allows this by simply falling back to the literal observe whenever we have `Meta.isexpr(left, :vect)`. Maybe also worth pointing out that there are docstrings lying about indicating that such a model would be valid: https://github.com/TuringLang/DynamicPPL.jl/blob/9083299db3f623136895cae80ef5f10d7fcf8d2c/src/context_implementations.jl#L377-L384.
|
Build failed: |
|
@KDr2 It seems Libtask 0.5.2 broke something: https://github.com/TuringLang/DynamicPPL.jl/runs/2783332077#step:6:1112 It fails due to https://github.com/TuringLang/Libtask.jl/blob/c66b8c90a8413d4532aecf36cc157767ec51d68d/src/tarray.jl#L81 (the key does not exist in the dictionary), which is caused by the call of |
|
Should I just add a compat bound for Libtask to the tests for now? Or ignore the error since we're popping out a new breaking release and so it won't be possible to run the Turing-tests anyways? |
Sounds good to ignore the error for now - @KDr2 should be able to fix the |
Simply using I've checked the code, every time we copy a task (or more precisely a CTask), we assign a new value to that data dict with the newly copied task as its key in the function |
But the older version didn't fail this testcase, right? Or it's a new testcase? |
|
No, it's an old test case that worked with Libtask 0.5.1. And everything works fine after upper bounding Libtask. |
|
I ran the testcase locally on master branch, it passed :) I will try again to reproduce the bug. |
Which version of Libtask are you using? I think @torfjelde capped the version of Libtask in Turing/DynamicPPL to in order to make CI pass. |
|
Ah, you are right, I reproduced the bug with the Libtask version loosed, I am on it now. |
* fix TuringLang/DynamicPPL.jl#261 (comment) * add testcase
Currently:
This also means that using variables in this manner on the LHS isn't allowed, e.g. observe on something
[x, x].Therefore, we might as well just treat it as literals. This also make it possible to write
[x, x] ~ ...wherexis an argument to the model.This PR allows this by simply falling back to the literal observe whenever we have
Meta.isexpr(left, :vect).Maybe also worth pointing out that there are docstrings lying about indicating that such a model would be valid:
DynamicPPL.jl/src/context_implementations.jl
Lines 377 to 384 in 9083299