I’m running a code in stan and for some time now it has stopped running, I really don’t know what to do. I installed new versions of the library and the program and I’m still getting this problem.
> # fit model
> check_cmdstan_toolchain(fix=T)
The C++ toolchain required for CmdStan is setup properly!
> set_cmdstan_path("/Users/marioquijada/.cmdstan/cmdstan-2.30.0")
CmdStan path set to: /Users/marioquijada/.cmdstan/cmdstan-2.30.0
> setwd("/Users/marioquijada/R")
> mod <- cmdstan_model("timeVarying.stan", pedantic=T)
Compiling Stan program...
In file included from src/cmdstan/main.cpp:1:
In file included from src/cmdstan/command.hpp:30:
In file included from stan/src/stan/io/dump.hpp:7:
In file included from stan/lib/stan_math/stan/math/prim.hpp:15:
In file included from stan/lib/stan_math/stan/math/prim/functor.hpp:14:
In file included from stan/lib/stan_math/stan/math/prim/functor/integrate_ode_rk45.hpp:6:
In file included from stan/lib/stan_math/stan/math/prim/functor/ode_rk45.hpp:9:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint.hpp:25:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint/util/ublas_wrapper.hpp:23:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/ublas/vector.hpp:21:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/ublas/storage.hpp:22:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/serialization/array.hpp:26:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/serialization/array_wrapper.hpp:17:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/serialization/nvp.hpp:35:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/serialization/split_free.hpp:22:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/serialization/serialization.hpp:14:
In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/serialization/strong_typedef.hpp:28:
stan/lib/stan_math/lib/boost_1.78.0/boost/type_traits/has_nothrow_assign.hpp:65:7: warning: builtin __has_nothrow_assign is deprecated; use __is_nothrow_assignable instead [-Wdeprecated-builtins]
BOOST_HAS_NOTHROW_ASSIGN(T)
^
stan/lib/stan_math/lib/boost_1.78.0/boost/type_traits/intrinsics.hpp:205:43: note: expanded from macro 'BOOST_HAS_NOTHROW_ASSIGN'
# define BOOST_HAS_NOTHROW_ASSIGN(T) (__has_nothrow_assign(T) && !is_volatile<T>::value && is_assignable<T&, const T&>::value)
^
12 warnings and 14 errors generated.
make: *** [src/cmdstan/main.o] Error 1
It looks like you don’t actually have the newest version. You have CmdStan 2.30.0
but the latest version is 2.33.1. Also which version of the cmdstanr package do you have? You can check with packageVersion("cmdstanr").
You could try installing the latest versions of both using:
# in a fresh R session
remotes::install_github("stan-dev/cmdstanr")
library(cmdstanr)
install_cmdstan() # optionally set argument 'cores' to speed it up
set_cmdstan_path(“/Users/marioquijada/.cmdstan/cmdstan-2.33.1”)
CmdStan path set to: /Users/marioquijada/.cmdstan/cmdstan-2.33.1
setwd(“/Users/marioquijada/R”)
mod ← cmdstan_model(“timeVarying.stan”, pedantic=T)
Compiling Stan program…
Error in ‘/var/folders/xp/y9tywk8n3ds_0xsf2bm2rys00000gn/T/RtmpHRZuSq/model-a273ca23a97.stan’, line 37, column 2: Declaration
of arrays by placing brackets after a variable name was removed in Stan
2.33.0. Instead use the array keyword before the type. This can be
changed automatically using the auto-format flag to stanc
Error in ‘/var/folders/xp/y9tywk8n3ds_0xsf2bm2rys00000gn/T/RtmpHRZuSq/model-a273ca23a97.stan’, line 21, column 2: Declaration
of arrays by placing brackets after a variable name was removed in Stan
2.33.0. Instead use the array keyword before the type. This can be
changed automatically using the auto-format flag to stanc
Error in ‘/var/folders/xp/y9tywk8n3ds_0xsf2bm2rys00000gn/T/RtmpHRZuSq/model-a273ca23a97.stan’, line 12, column 2: Declaration
of arrays by placing brackets after a variable name was removed in Stan
2.33.0. Instead use the array keyword before the type. This can be
changed automatically using the auto-format flag to stanc
Error in ‘/var/folders/xp/y9tywk8n3ds_0xsf2bm2rys00000gn/T/RtmpHRZuSq/model-a273ca23a97.stan’, line 10, column 2: Declaration
of arrays by placing brackets after a variable name was removed in Stan
2.33.0. Instead use the array keyword before the type. This can be
changed automatically using the auto-format flag to stanc
make: *** [/var/folders/xp/y9tywk8n3ds_0xsf2bm2rys00000gn/T/RtmpHRZuSq/model-a273ca23a97.hpp] Error 65
Error: An error occured during compilation! See the message above for more information.
Oh yeah this is a somewhat confusing error message. It means that you’re using some syntax for arrays that isn’t supported anymore as of version 2.33 (previous versions warned about it but as of 2.33 it’s an error). CmdStanR can update the syntax for you using the format method:
mod <- cmdstan_model(stan_file, compile = FALSE)
# print fixed version of your Stan program
mod$format(canonicalize = list("deprecations"))
# or you can overwrite your file with the edits
mod$format(canonicalize = list("deprecations"), overwrite_file = TRUE)
Hi Jonah. The syntax for array is fixed with the code that you shared (Thank u very much). Now I get this error and I’m trying to figure out how to fix it.
fit model
check_cmdstan_toolchain(fix=T)
The C++ toolchain required for CmdStan is setup properly!
set_cmdstan_path(“/Users/marioquijada/.cmdstan/cmdstan-2.33.1”)
CmdStan path set to: /Users/marioquijada/.cmdstan/cmdstan-2.33.1
setwd(“/Users/marioquijada/R”)
mod ← cmdstan_model(“timeVarying.stan”, pedantic=T)
Compiling Stan program…
Warning in ‘/var/folders/xp/y9tywk8n3ds_0xsf2bm2rys00000gn/T/RtmpVoh2ad/model-15946a5b7486.stan’, line 77, column 20: Argument
0.05 suggests there may be parameters that are not unit scale; consider
rescaling with a multiplier (see manual section 22.12).
Warning in ‘/var/folders/xp/y9tywk8n3ds_0xsf2bm2rys00000gn/T/RtmpVoh2ad/model-15946a5b7486.stan’, line 76, column 20: Argument
0.05 suggests there may be parameters that are not unit scale; consider
rescaling with a multiplier (see manual section 22.12).
Warning: Your Stan program has a parameter lam_t with a lower and upper bound
in its declaration. These hard constraints are not recommended, for two
reasons: (a) Except when there are logical or physical constraints, it is
very unusual for you to be sure that a parameter will fall inside a
specified range, and (b) The infinite gradient induced by a hard
constraint can cause difficulties for Stan’s sampling algorithm. As a
consequence, we recommend soft constraints rather than hard constraints;
for example, instead of constraining an elasticity parameter to fall
between 0, and 1, leave it unconstrained and give it a normal(0.5,0.5)
prior distribution.
Warning: Your Stan program has a parameter lam_H with a lower and upper bound
in its declaration. These hard constraints are not recommended, for two
reasons: (a) Except when there are logical or physical constraints, it is
very unusual for you to be sure that a parameter will fall inside a
specified range, and (b) The infinite gradient induced by a hard
constraint can cause difficulties for Stan’s sampling algorithm. As a
consequence, we recommend soft constraints rather than hard constraints;
for example, instead of constraining an elasticity parameter to fall
between 0, and 1, leave it unconstrained and give it a normal(0.5,0.5)
prior distribution.
error: PCH file was compiled for the target ‘arm64-apple-macosx14.0.0’ but the current translation unit is being compiled for target ‘x86_64-apple-macosx14.0.0’
Error: An error occured during compilation! See the message above for more information.
In addition: Warning message:
CmdStan’s precompiled header (PCH) files may need to be rebuilt.
If your model failed to compile please run rebuild_cmdstan().
If the issue persists please open a bug report.