NUTS and parallelized black box likelihood

The problem is that pymc creates deamon process to sample for each chain. Those processes aren’t allowed (a restriction from the python std lib) to create child processes. But if you want to sample several chains in parallel, where each chain uses multiple cores, nobody is stopping you from doing this in several python processes. If you write a script that samples one chain with pm.sample(cores=1), and stores the trace eg in an netcdf file (convert it with arviz) then you can run several instances of that script in parallel and then combine those files with xarray.concat.
Keep in mind that this is probably only a good idea if the parallel code runs for a very short time or if you have a lot of cores.

1 Like