stan-dev / cmdstanr

CmdStanR: the R interface to CmdStan
https://mc-stan.org/cmdstanr/
Other
143 stars 63 forks source link

cmdstan_path() set but I get a message about it not being set #378

Closed bbbales2 closed 3 years ago

bbbales2 commented 3 years ago

Hit a weird issue this morning where my path is set but when I try to build a model it tells me it isn't:

> library(cmdstanr)
This is cmdstanr version 0.2.0
- Online documentation and vignettes at mc-stan.org/cmdstanr
- CmdStan path set to: /home/bbales2/.cmdstanr/v2.25.0-rc1
- Use set_cmdstan_path() to change the path
> mod = cmdstan_model("bee.stan")
Compiling Stan program...
Error: CmdStan path has not been set yet. See ?set_cmdstan_path.
> cmdstan_path()
[1] "/home/bbales2/.cmdstanr/v2.25.0-rc1"
> set_cmdstan_path(cmdstan_path())
CmdStan path set to: /home/bbales2/.cmdstanr/v2.25.0-rc1
> mod = cmdstan_model("bee.stan")
Compiling Stan program...
Error: CmdStan path has not been set yet. See ?set_cmdstan_path.

That folder exists on my computer and appears to have a cmdstan in it.

rok-cesnovar commented 3 years ago

We debugged this with Ben in a chat. The problem was in the -rc release. Guess I can close?

bbbales2 commented 3 years ago

Well I'd prefer it keeps running and spits out a warning or something.

I suppose an error would be better than just not working with cmdstan missing.

Why did the rc work in the first place, for instance? When rc 2.26-rc1 comes along will it work?

jgabry commented 3 years ago

Weird, I didn't have any issue using the previous release candidate with cmdstanr. What did you figure out when debugging this?

bbbales2 commented 3 years ago

The was the output of some more commands:

> set_cmdstan_path(cmdstan_path())
CmdStan path set to: /home/bbales2/.cmdstanr/v2.25.0-rc1
> cmdstanr:::.cmdstanr$PATH
[1] "/home/bbales2/.cmdstanr/v2.25.0-rc1"
> cmdstanr:::.cmdstanr$VERSION
character(0)
> cmdstanr:::read_cmdstan_version("/home/bbales2/.cmdstanr/v2.25.0-rc1")
character(0)
jgabry commented 3 years ago

Hmm the path you have is

/home/bbales2/.cmdstanr/v2.25.0-rc1

but by default cmdstanr would use

/home/bbales2/.cmdstanr/cmdstan-2.25.0-rc1

That said, your version should still work because we want to allow you to set the path to wherever you want, but maybe the difference is causing the error? I haven't dug into the code so I'm not sure, but it's a possibility.

jgabry commented 3 years ago

The problem was in the -rc release. Guess I can close?

I think we should keep it open because don't we want it to work with release candidates too?

bbbales2 commented 3 years ago

/home/bbales2/.cmdstanr/v2.25.0-rc1

Good catch. I checked again and that folder does exist and contains stuff though.

rok-cesnovar commented 3 years ago

Yes, we should come to the bottom of this, but I honestly think was installed with a tarball that was later scratched because it either had the wrong name or something. We had a few times where we made a tarball but quickly saw it had the wrong name or some of the release replace-text procedures went wrong and we quickly replaced it.

I tried installing it locally on a Ubuntu/Windows and it works fine.

@bbbales2 can you check CMDSTAN_VERSION inside the Makefile in that folder?

rok-cesnovar commented 3 years ago

Actually run the following and let me know where it breaks:

  path <- "/home/bbales2/.cmdstanr/v2.25.0-rc1"
  makefile_path <- file.path(path, "makefile")
  if (!file.exists(makefile_path)) {
    warning(
      "Can't find CmdStan makefile to detect version number. ",
      "Path may not point to valid installation.",
      call. = FALSE
    )
    return(NULL)
  }
  makefile <- readLines(makefile_path)
  version_line <- grep("^CMDSTAN_VERSION :=", makefile, value = TRUE)
  sub("CMDSTAN_VERSION := ", "", version_line)
bbbales2 commented 3 years ago

It appears to not have a CMDSTAN_VERSION:

grep("^CMDSTAN_VERSION :=", makefile, value = TRUE) returns character(0)

rok-cesnovar commented 3 years ago

Yeah, that was a botched RC release try then and that was updated immediately. You were an early tester :) We rely on CMDSTAN_VERSION being there. If it isn't, we cant do anything else.

jgabry commented 3 years ago

In that case I'm not worried about this and I think we can close it. Although maybe we should add a check for this to read_cmdstan_version(). Something like this?

  if (length(version_line) == 0) {
    stop("CmdStan makefile is missing a version number.", call. = FALSE)
  }
rok-cesnovar commented 3 years ago

Let's add that. Would serve as a release-checker as well.

Luis188141 commented 1 year ago

I got the same error as follows. Can anyone can help me ? Error: CmdStan path has not been set yet. See ?set_cmdstan_path.

rok-cesnovar commented 1 year ago

Have you run cmdstanr::install_cmdstan()?

Luis188141 commented 1 year ago

Have you run cmdstanr::install_cmdstan()?

no yet. And I follow this instruction and then foud another error as follow. Error: Rtools42 is installed in a path with spaces or brackets, which is not supported. Please reinstall Rtools42 to a valid path, restart R, and then run cmdstanr::check_cmdstan_toolchain().

What puzzles me is that my path of Rtools42 is "C:\Program Files\R\rtools42". It seems that there is no spaces or brackets. What should I do next? Thank you so much for your advices.

rok-cesnovar commented 1 year ago

There is a space in Program Files

Luis188141 commented 1 year ago

There is a space in Program Files

Thank you so much for your suggestions. I had reinstalled the Rtools and I was in another problem.

The C++ toolchain required for CmdStan is setup properly!

I wonder if this is the problem arising from the language of location, i.e. 'D:\????'. Are there any solutions to this problem?

i55m commented 1 year ago

I have a similar problem with the CmdStan path not found, even though it is set, and version number being undetectable.

Any help very much appreciated.

I've installed through cmdstanr::install_cmdstan(), following instructions here

For example, after loading rethinking

library(rethinking)

Loading required package: rstan Loading required package: StanHeaders Loading required package: ggplot2 rstan (Version 2.21.5, GitRev: 2e1f913d3ca3) For execution on a local, multicore CPU with excess RAM we recommend calling options(mc.cores = parallel::detectCores()). To avoid recompilation of unchanged Stan programs, we recommend calling rstan_options(auto_write = TRUE) Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file Loading required package: cmdstanr This is cmdstanr version 0.5.3

Attaching package: ‘rethinking’

The following object is masked from ‘package:rstan’:

stan

The following object is masked from ‘package:stats’:

rstudent

Warning messages: 1: Can't find CmdStan makefile to detect version number. Path may not point to valid installation. 2: Can't find CmdStan makefile to detect version number. Path may not point to valid installation.

And this model leads to similar warnings

fit_stan <- ulam( f , data=list(y=c(-1,1)) ) Error: CmdStan path has not been set yet. See ?set_cmdstan_path. ?set_cmdstan_path cmdstanr::cmdstan_path() [1] "/cmvm.datastore.ed.ac.uk/cmvm/scs/users/imaccorm/.cmdstan/cmdstan-2.31.0" Warning message: Can't find CmdStan makefile to detect version number. Path may not point to valid installation. cmdstanr::set_cmdstan_path(path = NULL) CmdStan path set to: /cmvm.datastore.ed.ac.uk/cmvm/scs/users/imaccorm/.cmdstan/cmdstan-2.31.0 Warning message: Can't find CmdStan makefile to detect version number. Path may not point to valid installation.

Apparently makefile doesn't exist

grep("^CMDSTAN_VERSION :=", makefile, value = TRUE) Error in grep("^CMDSTAN_VERSION :=", makefile, value = TRUE) : object 'makefile' not found

rok-cesnovar commented 1 year ago

Is this the full path to the installation: "/cmvm.datastore.ed.ac.uk/cmvm/scs/users/imaccorm/.cmdstan/cmdstan-2.31.0"

Can you go there in file explorer and check if it exists?

i55m commented 1 year ago

Thanks for your prompt reply! Yes makefile exists in M:.cmdstan\cmdstan-2.31.0. (For me M: is /cmvm.datastore.ed.ac.uk/cmvm/scs/users)

Capture

rok-cesnovar commented 1 year ago

What about just setting cmdstan path as:

cmdstanr::set_cmdstan_path("M:/.cmdstan/cmdstan-2.31.0")
i55m commented 1 year ago

cmdstanr::set_cmdstan_path("M:/.cmdstan/cmdstan-2.31.0") CmdStan path set to: M:/.cmdstan/cmdstan-2.31.0 Warning message: Can't find CmdStan makefile to detect version number. Path may not point to valid installation.

drjhw commented 1 year ago

bug report I installed cmdstanr today, in order to use the glmmrBase and glmmrOptim packages. I have R version 4.2.1 (2022-06-23 ucrt) running on Windows 10 (ver 21H2).

I installed cmdstanr in directory: C:\Users\jonathanw\AppData\Local\R\win-library\4.2

I can load the installed cmdstanr into my R session:-

library(cmdstanr) This is cmdstanr version 0.5.3

  • CmdStanR documentation and vignettes: mc-stan.org/cmdstanr
  • Use set_cmdstan_path() to set the path to CmdStan
  • Use install_cmdstan() to install CmdStan

I then use set_cmdstan_path(), to set the path to cmdstanr:-

set_cmdstan_path('C:/Users/jonathanw/AppData/Local/R/win-library/4.2/cmdstanr') CmdStan path set to: C:/Users/jonathanw/AppData/Local/R/win-library/4.2/cmdstanr Warning message: Can't find CmdStan makefile to detect version number. Path may not point to valid installation.

cmdstan_path() finds the installation of cmdstanr, but also elicits the warning: cmdstan_path() [1] "C:/Users/jonathanw/AppData/Local/R/win-library/4.2/cmdstanr" Warning message: Can't find CmdStan makefile to detect version number. Path may not point to valid installation.

The cmdstan toolchain appears to be set up correctly check_cmdstan_toolchain(fix = FALSE, quiet = FALSE) The C++ toolchain required for CmdStan is setup properly!

When I try to use the glmmr packages, or simply install cmdstanr, I receive the same warning, but the glmmr procedure terminates with an error "CmdStan path has not been set yet", when it tries to fit models using Stan:-

Not run:

create example data with six clusters, five time periods, and five people per cluster-period

. ' '

fits the models using Stan

fit2 <- des$MCML(y = ysim, method="mcnr")

adds a simulated likelihood step after the MCEM algorithm

using method: mcnr

Start: -0.1326447 0.01828294 -0.1423836 -0.1530518 -0.06376128 0.5406558 0.01810778 0.3508911 1.101787 Loading required namespace: cmdstanr If this is the first time running this model, it will be compiled by cmdstan. Error: CmdStan path has not been set yet. See ?set_cmdstan_path.

You can see above that I have set_cmdstand_path(). So, what do I do now?

Thanks for your help

cchen22 commented 1 year ago

I got a similar problem. It is weird because I can get the code run properply inside R but if I use the command line Rscript mycode.R, it encounters this Error: CmdStan path has not been set yet. See ?set_cmdstan_path. Any idea is much appreciated!!