Open phipsgabler opened 2 years ago
I guess this is the same as in any place when you use the same LHS twice, but isn't there some way to fail this more informatively?
@submodel prefix=true ...
is the way to go:
julia> @model function test(n1, n2)
x1 ~ product_distribution(Fill(Uniform(), n1))
@submodel prefix=true y1 = linear(x1, 1, 1)
x2 ~ product_distribution(Fill(Uniform(), n2))
@submodel prefix=true y2 = linear(x2, 2, 2)
end
test (generic function with 2 methods)
julia> keys(SimpleVarInfo(test(5, 2)))
(x1, y1.y, x2, y2.y)
So one alternative is to just to make the prefix=true
by default? :shrug:
But improving error message seems more difficult :confused:
Hi guys,
We ran into the same issue around developing an epidemiological modelling/inference package (see here).
Personally, I'd support prefix=true
default.
Unfortunately it's a bit difficult to perform automatic prefixing in general because it's possible to put arbitrary expressions on the LHS of =
in @submodel
, e.g. @submodel (; x, y, z) = ...
is valid.
But what we can do, is to perform a check on the model before inference occurs to make sure nothing strange has occurred, and if it has, warn the user about it or error. This would then catch issues such as repeating varnames.
Consider
test(5, 5)()
works, but probably erroneously. OTOH,test(5, 2)()
fails withwhich makes it really hard to find the root cause of the error unless you know what's going on in the internals (all manual checking for whether the arrays match is going fine!).
I guess this is the same as in any place when you use the same LHS twice, but isn't there some way to fail this more informatively?