probmods / webppl

Probabilistic programming for the web
http://webppl.org
Other
619 stars 86 forks source link

Asynchronous evaluation #852

Closed insperatum closed 7 years ago

insperatum commented 7 years ago

Suppose I have a likelihood that can only be written as: getLikelihood(x, callback). Specifically, I'd like to have a child process continually running, which I send data off to for likelihood evaluation, and somehow pick it up with proc.stdout.on('data', function(d){...})

What do you think is the easiest way to achieve this, either taking the webppl code as is or with small modifications. All I want is to block until the callback returns something, but nodejs is very keen to avoid this pattern. Something with ES6 generators could work, but I feel like that would still have to exist inside webppl code, and I'm not sure where...?

Cheers, Luke

null-a commented 7 years ago

All I want is to block until the callback returns something

I've put together a WebPPL package that includes a callAsync method that allows asynchronous JS functions to be called in this way. Hopefully you can use this directly or adapt it to fit your situation? I'd be happy to talk more about the implementation if that's helpful to you.

insperatum commented 7 years ago

That worked perfectly! Thanks for being so helpful, things are much faster now that I can send data off to python for the heavy lifting. Also makes me wonder about hooking likelihood evaluation into Tensorflow...