Installing CmdStan using conda

Someone is trying to use the conda install route on Windows. Does below error give a clue what might be the problem? I wonder if the environment is not activated or even if this is possible in this case.

The user is able to test the examples:

I just installed cmstan on a Windows 10 machine via conda, as recommended in the cmdstan user guide. The cmdstan home directory is then C:\Users\Jakob\Anaconda3\Library\bin\cmdstan, from which I were able to succesfully run the cmdstan examples.

Does the 60 in the last line refer to line 60 in the makefile?

Thanks,
Rob

ENV["JULIA_CMDSTAN_HOME"] = "C:\\Users\\Jakob\\Anaconda3\\Library\\bin\\cmdstan"

using StanSample

model = "
	data { 
	  int<lower=0> N; 
	  int<lower=0,upper=1> y[N];
	} 
	parameters {
	  real<lower=0,upper=1> theta;
	} 
	model {
	  theta ~ beta(1,1);
	    y ~ bernoulli(theta);
	}
";

sm = SampleModel("bernoulli", model, tempdir())
This results in the following Error:

Error when compiling SampleModel bernoulli:
/usr/bin/expr: missing operand
Try '/usr/bin/expr --help' for more information.
/usr/bin/rm: missing operand
Try '/usr/bin/rm --help' for more information.
make: *** [make/program:60: C:\Users\Jakob\AppData\Local\Temp\bernoulli.exe] Error 1```

If anyone, @WardBrian would know.

2 Likes

I believe the error refers to $CMDSTAN/make/program (a makefile snippet we include in the top-level makefile) at line 60. I’ve never seen this particular error before. Has the user activated the conda environment? In addition to pointing Julia to the right place, they need all the other dependencies from that environment

1 Like

Thanks, will try to install via conda on my machine to reproduce the steps needed.

1 Like

Great! I’m not sure how many people have been using the conda installation alongside Julia, so it’s good to find any issues. I also found this Julia package which might do a better job of making sure all the binaries are found, if that ends up being the problem

Ah, that looks very promising! I’ll have a go at it and report back with progress over the next couple of days. Thanks for your help!

Hi @WardBrian & @rok_cesnovar

After going back and forth a bit, the conda install route works fine now.

Once you come to this point:

(stan-env) rob@Rob-16-MBP bernoulli % conda list cmdstan
# packages in environment at /Users/rob/opt/miniconda3/envs/stan-env:
#
# Name                    Version                   Build  Channel
cmdstan                   2.28.2               h8783527_0    conda-forge

and point the environment variable (in the Julia case) correct (shown below):

(stan-env) rob@Rob-16-MBP bernoulli % echo $JULIA_CMDSTAN_HOME                      
/Users/rob/.julia/conda/3/envs/stan_dev/bin/cmdstan

(stan-env) rob@Rob-16-MBP bernoulli % cd $JULIA_CMDSTAN_HOME
(stan-env) rob@Rob-16-MBP cmdstan % pwd
/Users/rob/.julia/conda/3/envs/stan_dev/bin/cmdstan

(stan-env) rob@Rob-16-MBP cmdstan % make examples/bernoulli/bernoulli               
make: 'examples/bernoulli/bernoulli' is up to date.


(stan-env) rob@Rob-16-MBP cmdstan % cd examples/bernoulli      
                     
(stan-env) rob@Rob-16-MBP bernoulli % ./bernoulli sample data file=bernoulli.data.json
method = sample (Default)
  sample
    num_samples = 1000 (Default)
    num_warmup = 1000 (Default)
    save_warmup = 0 (Default)
    thin = 1 (Default)

... <snipped>

Works! Both on Windows & MacOS Monterey. Very impressive work!!!

On my M1 I’ll stick with using/building the sources although I see no real reason why it wouldn’t work as long as I would use conda-forge for M1.

May the text in the installation docs can be updated?

The conda installation is designed so one can use the R, Python or Julia bindings to CmdStan seamlessly. 
1 Like

The “seamlessly” quote is because the Conda installation sets $CMDSTAN (Which both cmdstanr and cmdstanpy) look for. I’d want to set the Julia env (or encourage the Julia packages to use the same as the others) before claiming it’s truly seamless, but I’m very glad to hear it works!

That’s a good idea. I’ll look into it.

Done, either CMDSTAN or JULIA_CMDSTAN_HOME can now be used as environment variables.

Of course only JULIA_CMDSTAN_HOME would show up in versioninfo() but ENV["CMDSTAN"] will quickly show the value.

Interesting history: CMDSTAN_HOME (2011) → JULIA_CMDSTAN_HOME (~2019) → CMDSTAN (almost 2022).

Too much on my plate right now, but it would be interesting if Conda.jl would allow me to test “JuliaStan packages on Windows” in GitHub CI workflow!

2 Likes