mhtess / rwebppl

RWebPPL, an R interface to Webppl http://webppl.org
22 stars 7 forks source link

Switch to checking for existence of an "end file" to resume rwebppl #37

Closed mhtess closed 8 years ago

mhtess commented 8 years ago

Currently, rwebppl waits until either stderr or stdout files exist and have content. One problem with this is that in node, console.warn() writes to stderr, and so a warning in WebPPL will be interpreted as an error (which causes rwebppl to stop).

For example: A program that throws abeta sample overflow warning message to the console then kills the webppl call inside R. My hunch is that rwebppl is interpreting the warning as an error.

Note: Initialization warnings are printed using console.log() and hence, are correctly interpreted as warnings.

model = '
var data = [0.999,0.999,0.99,0.999,0.998,0.999,0.999,0.95,0.975,0.999,0.999,0.999,0.999,0.999,0.999,0.999,0.999,0.999,0.995,0.999,0.999,0.999,0.999,0.999,0.999,0.999,0.99,0.98,0.999,0.95,0.999,0.98,0.1,0.99,0.999,0.999,0.999,0.999,0.999,0.999]
var shapeAlpha = function(g, d){ return g * d };
var shapeBeta = function(g, d){ return (1-g) * d };

var model = function(){
  var g = uniformDrift({a: 0, b: 1, width:0.2});
  var d = uniformDrift({a: 0, b: 50, width:5});
  var a = shapeAlpha(g, d);
  var b = shapeBeta(g, d);

  map(function(d){ observe(Beta({a: a, b: b}), d) }, data)

  return {g: g, d:d, a:a, b:b, p: beta(a,b)};
}

Infer({method: "MCMC", samples: 10000, burn: 5000, verbose: T}, model)
'

webppl(model)

reports after a thousand or so iterations

beta sample overflow, rounded to nearest representable support value

which causes the webppl call to quit inside of R.

mhtess commented 8 years ago

Andreas suggested using the node function(s) try ... finally ... in our rwebppl binary. Whatever comes after finally will be done, even if try fails. So we will try to run webppl (via main()) and whatever happens, it will write a file webppl-done. We can then check for the existence of that file to know when to stop rwebppl