-
-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate standalone function compilation with RStan #422
Comments
I tried to put this in, but there seem to be several issues.
|
What I have so far is in commit 4d10329 but I had to comment out the version of |
|
I think the vast majority of people calling a user-defined function that ends in |
Just wanted to let you know, that I'll be happy to work to resolve the issues, but won't be able to dedicate time before Friday. |
@bgoodri re: #3 above: 1) we add an rstan function that generates an RNG and returns an R object referring to it (so that it is not deleted, this is what Rcpp::XPtr is for); 2) the _rng functions require this RNG pointer as one of their arguments; 3) we can create a default RNG in the rstan namespace and have the |
Should we piggyback on R's PRNG to initialize that so that the behavior is replicable with the same R seed? We could expose two additional functions for each
Namely
@bgoodri suggested the first of these is what R users will expect. I can see two alternative implementations:
|
So I tried to fix the RCpp export stuff and lgamma on a branch: stan-dev/stan#2347 Hope that helps. |
@sakrejda As of commit 09cefa3 we might be down to RNG issues with standalone functions. You first have to install StanHeaders (make sure to change the two subrepos under
|
Upon further review, it appears as if the problem is not merely with the RNGs or with the
|
Okay, as of b4ae642, which revives a few hacks from how
So, we need a way to deal with RNG before we can release RStan 2.17.x. @sakrejda ? |
That's great! I'll look at it now but I can't code anything till Tuesday (I'm on a chrome book till then). |
While I'm waiting on this cheapo laptop to install all stuff required for rstan, any chance you could dump the code here that generates that error? It's the c++ generated by Stan, right? |
I'm on my phone but it should just be expose_stan_functions (foo.stan)
where foo.stan has any function ending in _rng.
On Sep 10, 2017 9:39 PM, "Krzysztof Sakrejda" <notifications@github.com> wrote:
While I'm waiting on this cheapo laptop to install all stuff required for
rstan, any chance you could dump the code here that generates that error?
It's the c++ generated by Stan, right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#422 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqoeOFdyz0Tsia2mYj_ISYuh1SV0Tks5shI9GgaJpZM4N8G-S>
.
|
Yeah, I can't compile stanc on this thing so I'll try tomorrow on another computer. |
I got rstan installed! Maybe for rstan3 we could reduce the number of dependencies 'cause it's horrid. I'll check this out now. |
Ok, not sure exactly what the solution is since I haven't kept track of the PR we're working from but we're close. The issue is that the function doesn't meet this condition:
Here's the function:
The problem is that there's no Is one of these preferable? The complexity is about the same and I guess on the Stan side we want references to RNG's rather than pointers so we should probably write the |
OK, a little more progress before I leave this till tomorrow. The generated file compiles as-is if it includes the following code before anything else (including
With this code we could create a |
So I can find it later, here's what the C++ of the helper function would look like:
Used like so:
|
@bgoodri What do you think about adding the |
That sounds better than anything I would come up with on my own.
…On Thu, Sep 14, 2017 at 1:52 PM, Krzysztof Sakrejda < ***@***.***> wrote:
@bgoodri <https://github.com/bgoodri> What do you think about adding the
get_rng function to the src directory (and the matching R function to
import it). Then adding the as/wrap code to the src directory, and seeing
if we can run this by hand. Once we do that I can suggest a package-global
rng that can be refreshed with a seed through another R function. If that
sounds like a plan to you I don't mind doing it, I just don't want to forge
ahead if you have other plans.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#422 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqsu-sQlucXt2kHu3YwAyuuNqtzp6ks5siWfogaJpZM4N8G-S>
.
|
Great, I'm working on the makefiles at the moment so realistically I'll make some progress by Monday and then need to troubleshoot till it works... |
I have a rough branch and I've gotten it to work via sourceCpp but the build cycle to debug the rstan build is really long b/c the grammar has to be rebuilt. Should I just update this branch or make a separate one? |
You don't really need a branch. I do
R CMD INSTALL --preclean rstan/
to install it once locally and then I can make changes to the R and hit
Build and Reload in RStudio without having to rebuild the C++. If you do
change the C++, then you can do
R CMD INSTALL rstan/
and it will just rebuild the C++ files that have changed.
…On Mon, Sep 18, 2017 at 8:17 PM, Krzysztof Sakrejda < ***@***.***> wrote:
I have a rough branch and I've gotten it to work via sourceCpp but the
build cycle to debug the rstan build is really long b/c the grammar has to
be rebuilt. Should I just update this branch or make a separate one?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#422 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqiI9aZKqMw2wrIo2QG_Wbi1SwIufks5sjwgugaJpZM4N8G-S>
.
|
Ok, that should speed things up, thanks! |
I got almost all the way there... There's this thing:
That ultimately doesn't compile because |
I pushed what I have so far to a branch. I still don't have the types quite right in the exporter.h include file. |
@bgoodri; victory!
... there's still a bug somewhere b/c the RNG doesn't get advanced but at least I got the types straight. We could avoid finding how to not copy the RNG and just initialize it using R's RNG for the seed, or I could just figure out how to avoid the copies, I'm sure that's possible too. It's on a branch: |
Also is Stan generating that __create_rng function? That should go away b/c it breaks things. |
Yes, at least with standalone functions. I don't think it gets created when
you generate a model.
…On Wed, Sep 20, 2017 at 8:08 PM, Krzysztof Sakrejda < ***@***.***> wrote:
Also is Stan generating that __create_rng function? That should go away
b/c it breaks things.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#422 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqkkqaSweAsm4i7p6m81Wk2peIlO2ks5skajqgaJpZM4N8G-S>
.
|
I'll see if there's a change I can make to have it easily get wrapped by Rcpp and it would save us keeping |
Glad to see you are making progress even without my help. Sorry for any mess in my code. |
@bgoodri I softlinked StanHeaders/inst/include/src to a local stan/src directory and now it can't find cvodes.h... I have nearly everything else working, I just need a branch of stan-dev/stan that's ahead of develop (doesn't create the __create_rng function) for testing. Any suggestions about how to do it? |
https://raw.githubusercontent.com/stan-dev/rstan/develop/install_StanHeaders.R
Just set the branch arguments to something else.
…On Sun, Sep 24, 2017 at 1:49 PM, Krzysztof Sakrejda < ***@***.***> wrote:
@bgoodri <https://github.com/bgoodri> I softlinked
StanHeaders/inst/include/src to a local stan/src directory and now it can't
find cvodes.h... I have nearly everything else working, I just need a
branch of stan-dev/stan that's ahead of develop (doesn't create the
__create_rng function) for testing. Any suggestions about how to do it?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#422 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADOrqm_VlL36ro0RHTHyiWwBMolkVn-Xks5slpY1gaJpZM4N8G-S>
.
|
Ok, thanks.
…On Sun, Sep 24, 2017, 1:52 PM bgoodri ***@***.***> wrote:
https://raw.githubusercontent.com/stan-dev/rstan/develop/install_StanHeaders.R
Just set the branch arguments to something else.
On Sun, Sep 24, 2017 at 1:49 PM, Krzysztof Sakrejda <
***@***.***> wrote:
> @bgoodri <https://github.com/bgoodri> I softlinked
> StanHeaders/inst/include/src to a local stan/src directory and now it
can't
> find cvodes.h... I have nearly everything else working, I just need a
> branch of stan-dev/stan that's ahead of develop (doesn't create the
> __create_rng function) for testing. Any suggestions about how to do it?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#422 (comment)>,
or mute
> the thread
> <
https://github.com/notifications/unsubscribe-auth/ADOrqm_VlL36ro0RHTHyiWwBMolkVn-Xks5slpY1gaJpZM4N8G-S
>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#422 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAfA6WMmDk9k1PsPjP278_51HoD3jiwyks5slpbggaJpZM4N8G-S>
.
|
@martinmodrak This is much easier than doing the whole thing! 👍 |
@bgoodri can you check out my branch and let me know what else it needs? I don't have time to figure out what rstan standards are for getting code in but I do have time to make changes (one's much harder for me than the other). Branch: https://github.com/stan-dev/rstan/tree/feature/issue-422-standalone-functions-k |
Summary:
The development version of Stan supports standalone compilation of the functions block (stan-dev/stan#2267), this should be accessible from R.
Description:
Design and implement an interface in RStan to take advantage of standalone function compilation. I am currently unsure about the best way to do this, but will update in discussion here. I am also willing to implement this (on the horizon of few weeks), but cannot assign myself as I am not part of this project.
The text was updated successfully, but these errors were encountered: