Interesting. But complex from an implementation point
of view because we want to interrupt a loop within Stan,
but don't want to have to depend on R to do it.
So we'll have to provide a plug-in callback interrupter.
Shouldn't be too hard.
We could add a template parameter IF for the type of interrupter
to all the sampler classes, then down in the guts of
loops, have something like:
template <class IF, ...>
class XXX_sampler {
IF& interrupter_;
if (interrupter_()) {
...handle interrupt...
... stop ...
}
}
Then the question is how often we check.
One obvious choice would be to do it each time the log
probability/gradient function is called. Or once per
sample, or once per N samples.
I don't know how slow it is, and after you call their interrupt,
we apparently can't even assume we get control back,
so we might not be able to do any cleanup like flushing
buffers and closing files (I don't know if C++ does any
of that itself -- Java does).
- Bob
On 8/10/12 4:52 PM, Ben Goodrich wrote:
>
http://cran.r-project.org/doc/manuals/R-exts.html#Allowing-interrupts
>
>
> On Friday, August 10, 2012 4:49:48 PM UTC-4, Matt Hoffman wrote:
>
> This particular problem is fixed, but do we know the answer to
> Andrew's question about interrupting R functions when they hang in
> general? In Matlab the answer is (infuriatingly) in many cases that it
> has to be implemented by whoever wrote the c/c++ function that's
> interfacing with the environment. It's annoying, but at some point we
> should probably look into how to make Stan interruptible in R.
>
> Matt
>