On 12/2/13, 7:45 PM, Ross Boylan wrote:
> On Sat, 2013-11-30 at 12:26 -0500, Bob Carpenter wrote:
>> Also, anything with std::cout, std::cin, or std::cerr
>> hardcoded needs to be rewritten for RStan and PyStan.
>
> In python having subprocesses that do both input and output can be a bit
> challenging, at least if the sequence isn't known.
Rather than a subprocess (though I'm not sure what that is),
I was imagining something where R or Python writes the data
to file from R or Python, a separate process is executed,
which reads from that file and writes to disk, then R or Python
read it back in.
But anyway, it sounds like nobody wants to do it this way.
So we'll see how long it remains maintainable in the present
configuration of calling the Stan C++ code directly.
> I think more recent
> versions (still in the python 2 series) handled this somewhat
> better--maybe with the introduction of the subprocess module. ("Recent"
> is at least a few years old).
>
> So there might also be python version issues, if you don't want to
> exclude "old" pythons. Old probably means < 2.4, since that is when
> subprocess (
http://docs.python.org/2/library/subprocess.html) was
> introduced. As a point of reference, my system running a Debian that is
> 2 generations out of date still has python 2.5 (though it's possible I
> got a backport).
>
> From the motiving PEP (
http://www.python.org/dev/peps/pep-0324/):
> The subprocess module provides the following enhancements over
> previous functions:
> ......
> - A communicate() method, which makes it easy to send stdin data
> and read stdout and stderr data, without risking deadlocks.
> Most people are aware of the flow control issues involved with
> child process communication, but not all have the patience or
> skills to write a fully correct and deadlock-free select loop.
> This means that many Python applications contain race
> conditions. A communicate() method in the standard library
> solves this problem.
>
> It is definitely possible to hold onto C++ structures in R; I assume the
> present code does because you can reuse models without recompiling them.
Just models. The samples themselves are translated back into R
structures because there's not an easy way to make C++ structures
persistent. I don't know how important that is, but I think that
was the main design consideration.
> If stan ran in a separate process would that be possible?
>
> I'm not sure if the proposal contemplates exposing the command line
> invocation of stan to the R or python users; FWIW such a system seems a
> bit klunky to me, although it's clearly more robust against interface
> changes.
You could still wrap the command-line calls so the interface
from the R side wouldn't change, though that would mean that RStan
would need to change to keep up with CmdStan, which is our "reference"
implementation insofar as it's what most of our developers use.
- Bob