I would like easily switch between different versions of Stan. E.g. use latest version of Stan most of the time (i.e. master branch) but be able to switch to earlier versions so that I can reproduce previous analysis.
I tried adapting the instructions on Getting-Started-with-CmdStan under the heading “Using a different Stan branch” but I get an error message that I don’t know how to fix.
Here are the commands I tried running.
git clone https://github.com/stan-dev/cmdstan.git --recursive
cd cmdstan
make stan-update
make build # successful
git checkout v2.23.0
make stan-update/v2.23.0 # recipe failed: Please specify which branch you want to merge with.
make clean-all
make build # error: No rule to make target 'src/cmdstan/main.o', needed by 'build'
Is there an easy way to checkout tagged commits with the appropriate submodule commits?
make clean-all # first clean because checkout or update can fail if not cleaned previously
git checkout v2.23.0
make stan-update # just stan-update
make build
As another option, would using cmdstanr::install_cmdstan() with the release_url argument help here? To install stan and cmdstan v2.22.0, for example, you could do
I am still getting the same error. This is really puzzling. I am pretty sure the commit ids for stan and stan_math are the same as what you posted. Here is some info about the state of my check out from git.
[philipm@oban cmdstan]$ git status
HEAD detached at v2.23.0
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: stan (modified content)
no changes added to commit (use "git add" and/or "git commit -a")
[philipm@oban cmdstan]$ git diff
diff --git a/stan b/stan
--- a/stan
+++ b/stan
@@ -1 +1 @@
-Subproject commit d44315be81899824ff32da81a6c74101dba995e1
+Subproject commit d44315be81899824ff32da81a6c74101dba995e1-dirty
[philipm@oban cmdstan]$ cd stan/
[philipm@oban stan]$ git status
HEAD detached at d44315b
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: lib/stan_math (untracked content)
no changes added to commit (use "git add" and/or "git commit -a")
[philipm@oban stan]$ cd lib/stan_math/
[philipm@oban stan_math]$ git status
HEAD detached at d4c32ed
Untracked files:
(use "git add <file>..." to include in what will be committed)
lib/boost_1.72.0/tools/build/src/engine/b2
lib/boost_1.72.0/tools/build/src/engine/bjam
nothing added to commit but untracked files present (use "git add" to track)
[philipm@oban stan_math]$ cd ../../..
[philipm@oban cmdstan]$ cat .gitmodules
[submodule "stan"]
path = stan
url = https://github.com/stan-dev/stan
[philipm@oban cmdstan]$ git submodule status --recursive
d44315be81899824ff32da81a6c74101dba995e1 stan (v2.23.0)
d4c32ed277a26b86bde275edce81ba1e35b508c5 stan/lib/stan_math (v3.2.0)
I have now found a solution to this. The problem was specific to v2.23.0 and to a subset of the machines I tried. Here is a minimal example.
wget https://github.com/stan-dev/cmdstan/releases/download/v2.23.0/cmdstan-2.23.0.tar.gz
tar -xzvf cmdstan-2.23.0.tar.gz
cd cmdstan-2.23.0
make build # error: No rule to make target 'src/cmdstan/main.o', needed by 'build'
The problem was that some implicit rules that were assumed by the Stan makefile were not defined (at least in v2.23). I guess most machines define these implicit rules for the user, but in some environments they need to be defined explicitly. Putting the following in make/local solved the problem for me.
@philipm, I’m glad you got it sorted out. Maybe this info would help… if it doesn’t, feel free to ignore:
I have multiple folders containing different versions of CmdStan (and Math). I’m not creative… so I’ll have cmdstan, cmdstan2, and cmdstan3 all at different versions.
if you go back far enough, you’ll have to be careful how to build and follow the instructions for that version (usually in the README.md). At some point we switched from using CC as the compiler to CXX. We had started using CC well before v1.0 and it stayed around until we could make a serious overhaul of the build.
you might want to check you make version. There is actually quite a lot of difference in functionality between the different versions of make; we used to write workarounds in the makefiles, but we’re doing that less and encouraging upgrading to what we know works. (that might explain your implicit rule problem)