I’m using rstan and encountered problems on a server. I’ve written some stan codes and they can run and compile successfully on my laptop (MacBook, R version 4.4.1, stan 2.32.2, rstan 2.32.6). I’ve just uploaded the codes on a server, and somehow couldn’t compile it (R version 4.2.2, stan 2.32.2, rstan 2.32.6).
The error message is:
Error in compileCode(f, code, language = language, verbose = verbose) :
/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/stan/math/rev/core/arena_matrix.hpp:13:7: required from ‘class stan::math::arena_matrix<Eigen::Matrix<double, 1, -1>, void>’/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/src/stan/model/indexing/rvalue_varmat.hpp:145:15: required from here/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:56:30: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits<double>::type’ {aka ‘__m128d’} [-Wignored-attributes]g++: fatal error: Killed signal terminated program cc1pluscompilation terminated.make: *** [/usr/local/lib/R/etc/Makeconf:178: file3f25c639c707f6.o] Error 1
Error in sink(type = "output") : invalid connection
I noticed that this seems to be similar to this post.
So if I run
system.file("include", "src", "stan", "model", "model_header.hpp",
package = "StanHeaders")
I get:
"/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/src/stan/model/model_header.hpp"
And if I run
example(stan_model, package = "rstan", run.dontrun = TRUE)
this is what I got:
g++ -std=gnu++17 -I"/usr/local/lib/R/include" -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include/" -I"/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/RcppEigen/include/" -I"/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/RcppEigen/include/unsupported" -I"/usr/local/lib/R/site-library/BH/include" -I"/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/src/" -I"/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/" -I"/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/RcppParallel/include/" -I"/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0 -include '/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/include/stan/math/prim/fun/Eigen.hpp' -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I"/usr/local/lib/R/site-library/Rcpp/include" -I/usr/local/include -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c file3f25c62f46217c.cpp -o file3f25c62f46217c.o
if test "zfile3f25c62f46217c.o" != "z"; then \
echo g++ -std=gnu++17 -shared -L"/usr/local/lib/R/lib" -L/usr/local/lib -o file3f25c62f46217c.so file3f25c62f46217c.o '/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/rstan/lib//libStanServices.a' -L'/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/lib/' -lStanHeaders -L'/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/RcppParallel/lib/' -ltbb -L"/usr/local/lib/R/lib" -lR; \
g++ -std=gnu++17 -shared -L"/usr/local/lib/R/lib" -L/usr/local/lib -o file3f25c62f46217c.so file3f25c62f46217c.o '/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/rstan/lib//libStanServices.a' -L'/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders/lib/' -lStanHeaders -L'/home/ys288/R/x86_64-pc-linux-gnu-library/4.2/RcppParallel/lib/' -ltbb -L"/usr/local/lib/R/lib" -lR; \
fi
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1:
2: // includes from the plugin
3: // [[Rcpp::plugins(cpp14)]]
4:
5:
6: // user includes
7: #include <Rcpp.h>
8: using namespace Rcpp;
9: #ifndef MODELS_HPP
10: #define MODELS_HPP
11: #define STAN__SERVICES__COMMAND_HPP
12: #include <rstan/rstaninc.hpp>
13: #ifndef USE_STANC3
14: #define USE_STANC3
15: #endif
16: // Code generated by stanc v2.32.2
17: #include <stan/model/model_header.hpp>
18: namespace model3f25c6155950bf__namespace {
19: using stan::model::model_base_crtp;
20: using namespace stan::math;
21: stan::math::profile_map profiles__;
22: static constexpr std::array<const char*, 4> locations_array__ =
23: {" (found before start of program)",
24: " (in 'anon_model', line 1, column 32 to column 39)",
25: " (in 'anon_model', line 1, column 48 to column 69)",
26: " (in 'anon_model', line 1, column 6 to column 18)"};
27: class model3f25c6155950bf_ final : public model_base_crtp<model3f25c6155950bf_> {
28: private:
29: double y_mean;
30: public:
31: ~model3f25c6155950bf_() {}
32: model3f25c6155950bf_(stan::io::var_context& context__, unsigned int
33: random_seed__ = 0, std::ostream* pstream__ = nullptr)
34: : model_base_crtp(0) {
35: int current_statement__ = 0;
36: using local_scalar_t__ = double;
37: boost::ecuyer1988 base_rng__ =
38: stan::services::util::create_rng(random_seed__, 0);
39: // suppress unused var warning
40: (void) base_rng__;
41: static constexpr const char* function__ =
42: "model3f25c6155950bf__namespace::model3f25c6155950bf_";
43: // suppress unused var warning
44: (void) function__;
45: local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
46: // suppress unused var warning
47: (void) DUMMY_VAR__;
48: try {
49: int pos__ = std::numeric_limits<int>::min();
50: pos__ = 1;
51: current_statement__ = 3;
52: context__.validate_dims("data initialization", "y_mean", "double",
53: std::vector<size_t>{});
54: y_mean = std::numeric_limits<double>::quiet_NaN();
55: current_statement__ = 3;
56: y_mean = context__.vals_r("y_mean")[(1 - 1)];
57: } catch (const std::exception& e) {
58: stan::lang::rethrow_located(e, locations_array__[current_statement__]);
59: }
60: num_params_r__ = 1;
61: }
62: inline std::string model_name() const final {
63: return "model3f25c6155950bf_";
64: }
65: inline std::vector<std::string> model_compile_info() const noexcept {
66: return std::vector<std::string>{"stanc_version = stanc3 v2.32.2",
67: "stancflags = --"};
68: }
69: template <bool propto__, bool jacobian__, typename VecR, typename VecI,
70: stan::require_vector_like_t<VecR>* = nullptr,
71: stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
72: inline stan::scalar_type_t<VecR>
73: log_prob_impl(VecR& params_r__, VecI& params_i__, std::ostream*
74: pstream__ = nullptr) const {
75: using T__ = stan::scalar_type_t<VecR>;
76: using local_scalar_t__ = T__;
77: T__ lp__(0.0);
78: stan::math::accumulator<T__> lp_accum__;
79: stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
80: int current_statement__ = 0;
81: local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
82: // suppress unused var warning
83: (void) DUMMY_VAR__;
84: static constexpr const char* function__ =
85: "model3f25c6155950bf__namespace::log_prob";
86: // suppress unused var warning
87: (void) function__;
88: try {
89: local_scalar_t__ y = DUMMY_VAR__;
90: current_statement__ = 1;
91: y = in__.template read<local_scalar_t__>();
92: {
93: current_statement__ = 2;
94: lp_accum__.add(stan::math::normal_lpdf<propto__>(y, y_mean, 1));
95: }
96: } catch (const std::exception& e) {
97: stan::lang::rethrow_located(e, locations_array__[current_statement__]);
98: }
99: lp_accum__.add(lp__);
100: return lp_accum__.sum();
101: }
102: template <typename RNG, typename VecR, typename VecI, typename VecVar,
103: stan::require_vector_like_vt<std::is_floating_point,
104: VecR>* = nullptr, stan::require_vector_like_vt<std::is_integral,
105: VecI>* = nullptr, stan::require_vector_vt<std::is_floating_point,
106: VecVar>* = nullptr>
107: inline void
108: write_array_impl(RNG& base_rng__, VecR& params_r__, VecI& params_i__,
109: VecVar& vars__, const bool
110: emit_transformed_parameters__ = true, const bool
111: emit_generated_quantities__ = true, std::ostream*
112: pstream__ = nullptr) const {
113: using local_scalar_t__ = double;
114: stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
115: stan::io::serializer<local_scalar_t__> out__(vars__);
116: static constexpr bool propto__ = true;
117: // suppress unused var warning
118: (void) propto__;
119: double lp__ = 0.0;
120: // suppress unused var warning
121: (void) lp__;
122: int current_statement__ = 0;
123: stan::math::accumulator<double> lp_accum__;
124: local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
125: // suppress unused var warning
126: (void) DUMMY_VAR__;
127: constexpr bool jacobian__ = false;
128: static constexpr const char* function__ =
129: "model3f25c6155950bf__namespace::write_array";
130: // suppress unused var warning
131: (void) function__;
132: try {
133: double y = std::numeric_limits<double>::quiet_NaN();
134: current_statement__ = 1;
135: y = in__.template read<local_scalar_t__>();
136: out__.write(y);
137: if (stan::math::logical_negation(
138: (stan::math::primitive_value(emit_transformed_parameters__) ||
139: stan::math::primitive_value(emit_generated_quantities__)))) {
140: return ;
141: }
142: if (stan::math::logical_negation(emit_generated_quantities__)) {
143: return ;
144: }
145: } catch (const std::exception& e) {
146: stan::lang::rethrow_located(e, locations_array__[current_statement__]);
147: }
148: }
149: template <typename VecVar, typename VecI,
150: stan::require_vector_t<VecVar>* = nullptr,
151: stan::require_vector_like_vt<std::is_integral, VecI>* = nullptr>
152: inline void
153: unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i__,
154: VecVar& vars__, std::ostream* pstream__ = nullptr) const {
155: using local_scalar_t__ = double;
156: stan::io::deserializer<local_scalar_t__> in__(params_r__, params_i__);
157: stan::io::serializer<local_scalar_t__> out__(vars__);
158: int current_statement__ = 0;
159: local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
160: // suppress unused var warning
161: (void) DUMMY_VAR__;
162: try {
163: int pos__ = std::numeric_limits<int>::min();
164: pos__ = 1;
165: local_scalar_t__ y = DUMMY_VAR__;
166: current_statement__ = 1;
167: y = in__.read<local_scalar_t__>();
168: out__.write(y);
169: } catch (const std::exception& e) {
170: stan::lang::rethrow_located(e, locations_array__[current_statement__]);
171: }
172: }
173: template <typename VecVar, stan::require_vector_t<VecVar>* = nullptr>
174: inline void
175: transform_inits_impl(const stan::io::var_context& context__, VecVar&
176: vars__, std::ostream* pstream__ = nullptr) const {
177: using local_scalar_t__ = double;
178: stan::io::serializer<local_scalar_t__> out__(vars__);
179: int current_statement__ = 0;
180: local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
181: // suppress unused var warning
182: (void) DUMMY_VAR__;
183: try {
184: current_statement__ = 1;
185: context__.validate_dims("parameter initialization", "y", "double",
186: std::vector<size_t>{});
187: int pos__ = std::numeric_limits<int>::min();
188: pos__ = 1;
189: local_scalar_t__ y = DUMMY_VAR__;
190: current_statement__ = 1;
191: y = context__.vals_r("y")[(1 - 1)];
192: out__.write(y);
193: } catch (const std::exception& e) {
194: stan::lang::rethrow_located(e, locations_array__[current_statement__]);
195: }
196: }
197: inline void
198: get_param_names(std::vector<std::string>& names__, const bool
199: emit_transformed_parameters__ = true, const bool
200: emit_generated_quantities__ = true) const {
201: names__ = std::vector<std::string>{"y"};
202: if (emit_transformed_parameters__) {}
203: if (emit_generated_quantities__) {}
204: }
205: inline void
206: get_dims(std::vector<std::vector<size_t>>& dimss__, const bool
207: emit_transformed_parameters__ = true, const bool
208: emit_generated_quantities__ = true) const {
209: dimss__ = std::vector<std::vector<size_t>>{std::vector<size_t>{}};
210: if (emit_transformed_parameters__) {}
211: if (emit_generated_quantities__) {}
212: }
213: inline void
214: constrained_param_names(std::vector<std::string>& param_names__, bool
215: emit_transformed_parameters__ = true, bool
216: emit_generated_quantities__ = true) const final {
217: param_names__.emplace_back(std::string() + "y");
218: if (emit_transformed_parameters__) {}
219: if (emit_generated_quantities__) {}
220: }
221: inline void
222: unconstrained_param_names(std::vector<std::string>& param_names__, bool
223: emit_transformed_parameters__ = true, bool
224: emit_generated_quantities__ = true) const final {
225: param_names__.emplace_back(std::string() + "y");
226: if (emit_transformed_parameters__) {}
227: if (emit_generated_quantities__) {}
228: }
229: inline std::string get_constrained_sizedtypes() const {
230: return std::string("[{\"name\":\"y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]");
231: }
232: inline std::string get_unconstrained_sizedtypes() const {
233: return std::string("[{\"name\":\"y\",\"type\":{\"name\":\"real\"},\"block\":\"parameters\"}]");
234: }
235: // Begin method overload boilerplate
236: template <typename RNG> inline void
237: write_array(RNG& base_rng, Eigen::Matrix<double,-1,1>& params_r,
238: Eigen::Matrix<double,-1,1>& vars, const bool
239: emit_transformed_parameters = true, const bool
240: emit_generated_quantities = true, std::ostream*
241: pstream = nullptr) const {
242: const size_t num_params__ = 1;
243: const size_t num_transformed = emit_transformed_parameters * (0);
244: const size_t num_gen_quantities = emit_generated_quantities * (0);
245: const size_t num_to_write = num_params__ + num_transformed +
246: num_gen_quantities;
247: std::vector<int> params_i;
248: vars = Eigen::Matrix<double,-1,1>::Constant(num_to_write,
249: std::numeric_limits<double>::quiet_NaN());
250: write_array_impl(base_rng, params_r, params_i, vars,
251: emit_transformed_parameters, emit_generated_quantities, pstream);
252: }
253: template <typename RNG> inline void
254: write_array(RNG& base_rng, std::vector<double>& params_r, std::vector<int>&
255: params_i, std::vector<double>& vars, bool
256: emit_transformed_parameters = true, bool
257: emit_generated_quantities = true, std::ostream*
258: pstream = nullptr) const {
259: const size_t num_params__ = 1;
260: const size_t num_transformed = emit_transformed_parameters * (0);
261: const size_t num_gen_quantities = emit_generated_quantities * (0);
262: const size_t num_to_write = num_params__ + num_transformed +
263: num_gen_quantities;
264: vars = std::vector<double>(num_to_write,
265: std::numeric_limits<double>::quiet_NaN());
266: write_array_impl(base_rng, params_r, params_i, vars,
267: emit_transformed_parameters, emit_generated_quantities, pstream);
268: }
269: template <bool propto__, bool jacobian__, typename T_> inline T_
270: log_prob(Eigen::Matrix<T_,-1,1>& params_r, std::ostream* pstream = nullptr) const {
271: Eigen::Matrix<int,-1,1> params_i;
272: return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
273: }
274: template <bool propto__, bool jacobian__, typename T_> inline T_
275: log_prob(std::vector<T_>& params_r, std::vector<int>& params_i,
276: std::ostream* pstream = nullptr) const {
277: return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
278: }
279: inline void
280: transform_inits(const stan::io::var_context& context,
281: Eigen::Matrix<double,-1,1>& params_r, std::ostream*
282: pstream = nullptr) const final {
283: std::vector<double> params_r_vec(params_r.size());
284: std::vector<int> params_i;
285: transform_inits(context, params_i, params_r_vec, pstream);
286: params_r = Eigen::Map<Eigen::Matrix<double,-1,1>>(params_r_vec.data(),
287: params_r_vec.size());
288: }
289: inline void
290: transform_inits(const stan::io::var_context& context, std::vector<int>&
291: params_i, std::vector<double>& vars, std::ostream*
292: pstream__ = nullptr) const {
293: vars.resize(num_params_r__);
294: transform_inits_impl(context, vars, pstream__);
295: }
296: inline void
297: unconstrain_array(const std::vector<double>& params_constrained,
298: std::vector<double>& params_unconstrained, std::ostream*
299: pstream = nullptr) const {
300: const std::vector<int> params_i;
301: params_unconstrained = std::vector<double>(num_params_r__,
302: std::numeric_limits<double>::quiet_NaN());
303: unconstrain_array_impl(params_constrained, params_i,
304: params_unconstrained, pstream);
305: }
306: inline void
307: unconstrain_array(const Eigen::Matrix<double,-1,1>& params_constrained,
308: Eigen::Matrix<double,-1,1>& params_unconstrained,
309: std::ostream* pstream = nullptr) const {
310: const std::vector<int> params_i;
311: params_unconstrained = Eigen::Matrix<double,-1,1>::Constant(num_params_r__,
312: std::numeric_limits<double>::quiet_NaN());
313: unconstrain_array_impl(params_constrained, params_i,
314: params_unconstrained, pstream);
315: }
316: };
317: }
318: using stan_model = model3f25c6155950bf__namespace::model3f25c6155950bf_;
319: #ifndef USING_R
320: // Boilerplate
321: stan::model::model_base&
322: new_model(stan::io::var_context& data_context, unsigned int seed,
323: std::ostream* msg_stream) {
324: stan_model* m = new stan_model(data_context, seed, msg_stream);
325: return *m;
326: }
327: stan::math::profile_map& get_stan_profile_data() {
328: return model3f25c6155950bf__namespace::profiles__;
329: }
330: #endif
331: #endif
332:
333: RCPP_MODULE(stan_fit4model3f25c6155950bf__mod) {
334: class_<rstan::stan_fit<stan_model, boost::random::ecuyer1988> >(
335: "stan_fit4model3f25c6155950bf_")
336:
337: .constructor<SEXP, SEXP, SEXP>()
338:
339: .method(
340: "call_sampler",
341: &rstan::stan_fit<stan_model, boost::random::ecuyer1988>::call_sampler)
342: .method(
343: "param_names",
344: &rstan::stan_fit<stan_model, boost::random::ecuyer1988>::param_names)
345: .method("param_names_oi",
346: &rstan::stan_fit<stan_model,
347: boost::random::ecuyer1988>::param_names_oi)
348: .method("param_fnames_oi",
349: &rstan::stan_fit<stan_model,
350: boost::random::ecuyer1988>::param_fnames_oi)
351: .method(
352: "param_dims",
353: &rstan::stan_fit<stan_model, boost::random::ecuyer1988>::param_dims)
354: .method("param_dims_oi",
355: &rstan::stan_fit<stan_model,
356: boost::random::ecuyer1988>::param_dims_oi)
357: .method("update_param_oi",
358: &rstan::stan_fit<stan_model,
359: boost::random::ecuyer1988>::update_param_oi)
360: .method("param_oi_tidx",
361: &rstan::stan_fit<stan_model,
362: boost::random::ecuyer1988>::param_oi_tidx)
363: .method("grad_log_prob",
364: &rstan::stan_fit<stan_model,
365: boost::random::ecuyer1988>::grad_log_prob)
366: .method("log_prob",
367: &rstan::stan_fit<stan_model, boost::random::ecuyer1988>::log_prob)
368: .method("unconstrain_pars",
369: &rstan::stan_fit<stan_model,
370: boost::random::ecuyer1988>::unconstrain_pars)
371: .method("constrain_pars",
372: &rstan::stan_fit<stan_model,
373: boost::random::ecuyer1988>::constrain_pars)
374: .method(
375: "num_pars_unconstrained",
376: &rstan::stan_fit<stan_model,
377: boost::random::ecuyer1988>::num_pars_unconstrained)
378: .method(
379: "unconstrained_param_names",
380: &rstan::stan_fit<
381: stan_model, boost::random::ecuyer1988>::unconstrained_param_names)
382: .method(
383: "constrained_param_names",
384: &rstan::stan_fit<stan_model,
385: boost::random::ecuyer1988>::constrained_param_names)
386: .method("standalone_gqs",
387: &rstan::stan_fit<stan_model,
388: boost::random::ecuyer1988>::standalone_gqs);
389: }
390:
391:
392: // declarations
393: extern "C" {
394: SEXP file3f25c62f46217c( ) ;
395: }
396:
397: // definition
398: SEXP file3f25c62f46217c() {
399: return Rcpp::wrap("anon_model");
400: }
I also tried to run:
example(cxxfunction, package = "inline", run.dontrun = TRUE)
I then got an error message saying:
Error in requireNamespace(RcppArmadillo) :
object 'RcppArmadillo' not found
But I have installed this package …
I wonder whether anyone could suggest what I should do next? Thanks!!