Closed cscherrer closed 3 years ago
call simplify_ex
once before calling solve_xxx
. JuliaVariables does not handle Expr(:(->)
, but Expr(:function
Got it, thank you @thautwarm !
julia> unwrap_scoped(ex) =
@match ex begin
Expr(:scoped, _, a) => unwrap_scoped(a)
Expr(head, args...) => Expr(head, map(unwrap_scoped, args)...)
a => a
end
unwrap_scoped (generic function with 1 method)
julia> m = @model begin
a ~ For(3) do x Normal(μ=x) end
x ~ Normal(μ=sum(a))
end;
julia> m.dists.a |> MacroTools.prettify |> simplify_ex |> solve_from_local |> unwrap_scoped
:((@global For)(function (x,)
(@global Normal)(μ = @local x)
end, 3))
I had brought this up in https://github.com/cscherrer/Soss.jl/issues/245, but I think it's really a different issue, so I'm splitting it.
The problem is in models like
Soss thinks the graph is
But this is wrong! The
x
referred to ina ~ ...
is a local variable.I think JuliaVariables.jl ought to be able to help with this. The idea is
solve
each rhs, which adds@local
and@global
annotations@global
ones, which should give the true dependenciesHere's my first attempt:
I'm not sure what's going on in that
@global x
, sincex
is clearly a local variable. My guess is that thedo
notation is throwing off the solver and needs to be rewritten.