probcomp / GenExperimental.jl

Featherweight embedded probabilistic programming language and compositional inference programming library
MIT License
17 stars 2 forks source link

Parallelize SIR in the goal inference tutorial notebook #16

Closed marcoct closed 7 years ago

marcoct commented 7 years ago

The only challenge will be seeing if we can avoid using @everywhere all over the place, which will clutter the code. We need to use @everwhere to define functions that are used during the computation. It should suffice to label the model program (e.g. agent_waypoint_model) and the SIR algorithm (e.g. agent_waypoint_model_importance_sampling)

marcoct commented 7 years ago

Once set up, this should be tested on a 64-core probcomp machine.

marcoct commented 7 years ago

I tried this like so:

trace = Trace()
intervene!(trace, "start", Point(10, 10))
for (i, (x, y)) in enumerate(zip(xs, ys))
    constrain!(trace, "x$i", x)
    constrain!(trace, "y$i", y)
end
renderer = JupyterInlineRenderer("agent_model_renderer", Dict("mode" => "overlay", "show_path" => true, "show_score" => false))
num_samples = 50
for (i, num_particles) in enumerate(all_num_particles)
    attach(renderer, figure => i)
    samples = pmap((j) -> agent_waypoint_model_importance_sampling(trace, num_particles), 1:num_samples)
    for sample in samples
        render(renderer, sample)
    end
end

but traces are no longer incrementally rendered, because rendering and sampling are not done in the same loop. That incremental rendering was a feature that was lost.

marcoct commented 7 years ago

I don't think we can avoid @everywhere, which is part of Julia's design and unlikely to go away. Here is a sequence that works for Julia 0.5.2:

addprocs(32);
import Gen
@everywhere using Gen;
@everywhere include("scene.jl")
@everywhere include("path_planner.jl")
@everywhere include("uniform_2d.jl");

see: https://github.com/probcomp/gen-examples/blob/master/holonomic-rrt-goal-inference/goals.ipynb It seems like the parallelization syntax might change a bit in coming versions of Julia, so this is relevant to https://github.com/probcomp/Gen.jl/issues/21