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

Feature/issue 422 clean standalone functions #459

Merged
merged 8 commits into from Jul 14, 2018

Conversation

Projects
None yet
4 participants
@sakrejda
Contributor

sakrejda commented Oct 17, 2017

Summary:

Remove most code-grepping from rstan::expose_stan_functions, hide generated code in namespace and call it via wrapper. There are warnings I'm not sure how to get rid of at the moment about get_rng and get_stream, we should fix those before merging.

Intended Effect:

This version of expose_stan_functions works with stan-dev/stan branch
"maintenance/issue-2401-remove-unnecessary-standalone-code-try-2". For
the moment the rng/stream must be passed explicitely, but next step is
to make default global objects. To check it out make a foo.stan like
so:

      functions {
        real f_rng(real mu) {
          real x = normal_rng(mu, 1);
          return x;
        }
      }
Then in R run:
     library(rstan)
     rstan::expose_stan_functions('foo.stan', cacheDir='.')
     o <- get_stream()
     rng <- get_rng(3)
     f_rng(3.3, rng, o)
     f_rng(3.3, rng, o)
     f_rng(3.3, rng, o)
     f_rng(3.3, rng, o)
     f_rng(3.3, rng, o)
Each call with the same RNG should return a new draw.  Re-initializing
the RNG with the same seed should restart the sequence.  Functions that
print will print via Rcpp::rcout.  The whole thing also works without explicitly 
loading the library:
rstan::expose_stan_functions('foo.stan')
f_rng(80.3, rstan::RNG, rstan::OUT)

How to Verify:

Use with the `` stan-dev/stan branch. Make sure the code above runs as expected. Also test a .stan function that prints output via print.

Side Effects:

None?

Documentation:

I don't know where we document expose_stan_functions but we should add documentation about the get_stream and get_rng functions there. Should also doc rstan::RNG and rstan::OUT. I haven't figured out how to inject those as the default arguments to the R wrappers for the exposed Stan functions yet.

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company):

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

sakrejda added some commits Sep 19, 2017

'works', except that 1) the __create_rng function makes things not co…
…mpile, that should go away; and 2) the RNG must get copied somewhere since it doesn't advance properly (repeat calls with same RNG get same value)... at worst one could create new RNG with random seed every time, at best I could make sure no copies occur.
Working cleaner expose_stan_functions
This version of expose_stan_functions works with stan-dev/stan branch
"maintenance/issue-2401-remove-unnecessary-standalone-code-try-2".  For
the moment the rng/stream must be passed explicitely, but next step is
to make default global objects.  To check it out make a foo.stan like
so:

  functions {
    real f_rng(real mu) {
      real x = normal_rng(mu, 1);
      return x;
    }
  }

Then in R run:

 library(rstan)
 rstan::expose_stan_functions('foo.stan', cacheDir='.')
 o <- get_stream()
 rng <- get_rng(3)
 f_rng(3.3, rng, o)
 f_rng(3.3, rng, o)
 f_rng(3.3, rng, o)
 f_rng(3.3, rng, o)
 f_rng(3.3, rng, o)

Each call with the same RNG should return a new draw.  Re-initializing
the RNG with the same seed should restart the sequence.  Functions that
print will print via Rcpp::rcout.

@sakrejda sakrejda requested a review from bgoodri Oct 17, 2017

@stan-buildbot

This comment has been minimized.

stan-buildbot commented Oct 17, 2017

Can one of the admins verify this patch?

@sakrejda

This comment has been minimized.

Contributor

sakrejda commented Oct 17, 2017

@bgoodri just figured out how to get rid of the warnings about rstan::RNG and rstan::OUT, pushed that.

@sakrejda

This comment has been minimized.

Contributor

sakrejda commented Oct 17, 2017

Here's the install_SteanHeaders.R for it:


path_rstan <- tempfile(pattern = "git2r-")
git2r::clone("http://github.com/stan-dev/rstan", path_rstan, branch = "feature/issue-422-standalone-functions-k")
git2r::clone("http://github.com/stan-dev/stan", 
             file.path(path_rstan, "StanHeaders", "inst", "include", "upstream"), 
             branch = "maintenance/issue-2401-remove-unnecessary-standalone-code-try-2") # may want to change this branch
git2r::clone("http://github.com/stan-dev/math", 
             file.path(path_rstan, "StanHeaders", "inst", "include", "mathlib"), 
             branch = "develop") # may want to change this branch
devtools::install(file.path(path_rstan, "StanHeaders"), args = "--preclean")

@ariddell ariddell referenced this pull request Jan 19, 2018

Open

Add support for stand-alone functions #409

0 of 2 tasks complete
@ariddell

This comment has been minimized.

Member

ariddell commented Feb 18, 2018

Is this going in 2.18?

@bgoodri

This comment has been minimized.

Contributor

bgoodri commented Feb 18, 2018

@sakrejda

This comment has been minimized.

Contributor

sakrejda commented Feb 28, 2018

No idea if this already made it in or not but if you need help finalizing it ping me. @bgoodri

@bgoodri bgoodri merged commit 4399d92 into develop Jul 14, 2018

0 of 3 checks passed

continuous-integration/jenkins/pr-merge This commit cannot be built
Details
continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
continuous-integration/travis-ci/push The Travis CI build could not complete due to an error
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment