Ubuntu 18.04, R 3.5.0, библиотека TMB, предупреждения об установке и фатальные ошибки во время выполнения - PullRequest
0 голосов
/ 25 июня 2018

свежая новая установка Ubuntu 18.04.-> ok

R 3.5.0, установленный из этого репозитория:

deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/

с добавленным ключом безопасного доступа:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

R установлен правильно и работает даже после запускаот rstudio.Попытка установить библиотеку TMB, команду установки с консоли R или терминала R в режиме суперпользователя с помощью этой команды (пробовала обе и удалила одну перед попыткой второй, поэтому возможен конфликт между пользовательскими библиотеками и библиотеками R):

install.packages("TMB",type = "source")

установка начинается, она устанавливает зависимые пакеты (Rcpp, RcppEigen etcetera).

во время установки / компиляции именно RcppEigen консоль начинает пинать, как 10000 строк предупреждений (например, еслиотсутствует какая-либо ссылка компилятора) , это первая строка, которая отличается от обычной установки:

** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (Rcpp)
* installing *source* package ‘RcppEigen’ ...
** package ‘RcppEigen’ successfully unpacked and MD5 sums checked
** libs
g++  -I"/usr/share/R/include" -DNDEBUG  -I"/usr/local/lib/R/site-library/Rcpp/include"   -I../inst/include -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-O3QT2W/r-base-3.5.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RcppEigen.cpp -o RcppEigen.o
In file included from ../inst/include/Eigen/Core:388:0,
                 from ../inst/include/Eigen/Dense:1,
                 from ../inst/include/RcppEigenForward.h:30,
                 from ../inst/include/RcppEigen.h:25,
                 from RcppEigen.cpp:22:
../inst/include/Eigen/src/Core/arch/SSE/PacketMath.h:60:39: warning: ignoring attributes on template argument ‘__m128 {aka __vector(4) float}’ [-Wignored-attributes]
 template<> struct is_arithmetic<__m128>  { enum { value = true }; };
                                       ^
../inst/include/Eigen/src/Core/arch/SSE/PacketMath.h:61:40: warning: ignoring attributes on template argument ‘__m128i{aka __vector(2) long long int}’ [-Wignored-attributes]
 template<> struct is_arithmetic<__m128i> { enum { value = true }; };
                                        ^
../inst/include/Eigen/src/Core/arch/SSE/PacketMath.h:62:40: warning: ignoring attributes on template argument ‘__m128d{aka __vector(2) double}’ [-Wignored-attributes]
 template<> struct is_arithmetic<__m128d> { enum { value = true }; };
                                        ^
../inst/include/Eigen/src/Core/arch/SSE/PacketMath.h:161:43: warning: ignoring attributes on template argument ‘Eigen::internal::Packet4f {aka __vector(4) float}’ [-Wignored-attributes]
 template<> struct unpacket_traits<Packet4f> { typedef float  type; enum {size=4, alignment=Aligned16}; typedef Packet4f half; };

это последние строки команды install.package ("TMB"):

/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:55:30: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits<double>::type {aka __vector(4) double}’ [-Wignored-attributes]
                      >::type PacketReturnType;
                         ^~~~~~~~~~~~~~~~
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h: In instantiation of ‘class Eigen::DenseCoeffsBase<Eigen::Transpose<const Eigen::Block<const Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, -1, false>, 1, -1, false> >, 0>’:
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:478:7:   required from ‘class Eigen::DenseCoeffsBase<Eigen::Transpose<const Eigen::Block<const Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, -1, false>, 1, -1, false> >, 2>’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/DenseBase.h:41:34:   required from ‘class Eigen::DenseBase<Eigen::Transpose<const Eigen::Block<const Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, -1, false>, 1, -1, false> > >’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/MatrixBase.h:48:34:   required from ‘class Eigen::MatrixBase<Eigen::Transpose<const Eigen::Block<const Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, -1, false>, 1, -1, false> > >’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/Transpose.h:115:37:   required from ‘class Eigen::TransposeImpl<const Eigen::Block<const Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, -1, false>, 1, -1, false>, Eigen::Dense>’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/Transpose.h:52:37:   required from ‘class Eigen::Transpose<const Eigen::Block<const Eigen::Block<Eigen::Block<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<0, 0> >, -1, -1, false>, -1, -1, false>, 1, -1, false> >’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/ProductEvaluators.h:552:40:   [ skipping 22 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/PlainObjectBase.h:816:7:   required from ‘void Eigen::PlainObjectBase<Derived>::_init1(const Eigen::DenseBase<ElseDerived>&) [with T = Eigen::Inverse<Eigen::Matrix<double, -1, -1> >; OtherDerived = Eigen::Inverse<Eigen::Matrix<double, -1, -1> >; Derived = Eigen::Matrix<double, -1, -1>]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/Matrix.h:296:31:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = Eigen::Inverse<Eigen::Matrix<double, -1, -1> >; _Scalar = double; int _Rows = -1; int _Cols = -1; int _Options = 0; int _MaxRows = -1; int _MaxCols = -1]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/tmbutils/vector.hpp:93:22:   required from ‘tmbutils::matrix<Type>::matrix(T1) [with T1 = Eigen::Inverse<Eigen::Matrix<double, -1, -1> >; Type = double]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/expm.hpp:36:14:   required from ‘atomic::Block<Type> atomic::Block<Type>::inverse() [with Type = double]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/expm.hpp:180:17:   required from ‘matrix_pade atomic::expm(matrix_pade) [with matrix_pade = atomic::nestedTriangle<0>]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/expm.hpp:192:52:   required from here`

последняя строка вывода из install.packages ("TMB", type = "source"):

g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o simple.so simple.o -L/usr/lib/R/lib -lR
Build time 16.121 seconds

* DONE (TMB)

установка завершается (консоль выдает * DOME (TMB), но выполнение базового примера TMB (линейная регрессия) приводит к фатальной ошибке сеанса R.

пример в коде R:

tmb_model <- "
// linear regression
#include <TMB.hpp>

template<class Type>
Type objective_function<Type>::operator() () {
// data:
DATA_VECTOR(x);
DATA_VECTOR(y);

// parameters:
PARAMETER(a); // intercept
PARAMETER(b); // slope
PARAMETER(log_sigma); // log(residual SD)
// we fit sigma on a log scale to keep it > 0

// procedures: (transformed parameters)
Type sigma = exp(log_sigma);

int n = y.size(); // get number of data points to loop over

Type nll = 0.0; // initialize negative log likelihood

for(int i = 0; i < n; i++){ // C++ starts loops at 0!
// get negative log likelihood (last argument is log = TRUE)
nll -= dnorm(y[i], a + b * x[i], sigma, true);
}

return nll;
}"
write(tmb_model, file = "regression.cpp")
library(TMB)
compile("regression.cpp")

с использованием TMB :: compile выдает массу предупреждений (это последний вывод строки + gcc):

/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:55:30: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits<double>::type {aka __vector(4) double}’ [-Wignored-attributes]
                      >::type PacketReturnType;
                              ^~~~~~~~~~~~~~~~
In file included from /home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/Core:436:0,
                 from /home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/Dense:1,
                 from /home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/TMB.hpp:53,
                 from regression.cpp:3:
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/CoreEvaluators.h: In instantiation of ‘struct Eigen::internal::evaluator<Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >, 1, -1, false> >’:
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/AssignEvaluator.h:730:20:   required from ‘void Eigen::internal::call_dense_assignment_loop(DstXprType&, const SrcXprType&, const Functor&) [with DstXprType = Eigen::Block<Eigen::Matrix<double, -1, -1>, 1, -1, false>; SrcXprType = Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >, 1, -1, false>; Functor = Eigen::internal::assign_op<double, double>]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/AssignEvaluator.h:879:31:   required from ‘static void Eigen::internal::Assignment<DstXprType, SrcXprType, Functor, Eigen::internal::Dense2Dense, Weak>::run(DstXprType&, const SrcXprType&, const Functor&) [with DstXprType = Eigen::Block<Eigen::Matrix<double, -1, -1>, 1, -1, false>; SrcXprType = Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >, 1, -1, false>; Functor = Eigen::internal::assign_op<double, double>; Weak = void]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/AssignEvaluator.h:836:49:   required from ‘void Eigen::internal::call_assignment_no_alias(Dst&, const Src&, const Func&) [with Dst = Eigen::Block<Eigen::Matrix<double, -1, -1>, 1, -1, false>; Src = Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >, 1, -1, false>; Func = Eigen::internal::assign_op<double, double>]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/AssignEvaluator.h:804:27:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&, const Func&, typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type) [with Dst = Eigen::Block<Eigen::Matrix<double, -1, -1>, 1, -1, false>; Src = Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >, 1, -1, false>; Func = Eigen::internal::assign_op<double, double>; typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type = void*]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/AssignEvaluator.h:782:18:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&) [with Dst = Eigen::Block<Eigen::Matrix<double, -1, -1>, 1, -1, false>; Src = Eigen::Block<const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >, 1, -1, false>]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/Assign.h:66:28:   [ skipping 26 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/PlainObjectBase.h:816:7:   required from ‘void Eigen::PlainObjectBase<Derived>::_init1(const Eigen::DenseBase<ElseDerived>&) [with T = Eigen::Inverse<Eigen::Matrix<double, -1, -1> >; OtherDerived = Eigen::Inverse<Eigen::Matrix<double, -1, -1> >; Derived = Eigen::Matrix<double, -1, -1>]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/Matrix.h:296:31:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = Eigen::Inverse<Eigen::Matrix<double, -1, -1> >; _Scalar = double; int _Rows = -1; int _Cols = -1; int _Options = 0; int _MaxRows = -1; int _MaxCols = -1]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/tmbutils/vector.hpp:93:22:   required from ‘tmbutils::matrix<Type>::matrix(T1) [with T1 = Eigen::Inverse<Eigen::Matrix<double, -1, -1> >; Type = double]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/expm.hpp:36:14:   required from ‘atomic::Block<Type> atomic::Block<Type>::inverse() [with Type = double]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/expm.hpp:180:17:   required from ‘matrix_pade atomic::expm(matrix_pade) [with matrix_pade = atomic::nestedTriangle<0>]’
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/TMB/include/expm.hpp:192:52:   required from here
/home/alberto/R/x86_64-pc-linux-gnu-library/3.5/RcppEigen/include/Eigen/src/Core/CoreEvaluators.h:960:8: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits<double>::type {aka __vector(4) double}’ [-Wignored-attributes]
   enum {
        ^
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o regression.so regression.o -L/usr/lib/R/lib -lR
[1] 0

Во время выполнения этого кода R он немедленно дает мне фатальную ошибку в rstudio (консоли R), точно взятую из примеров TMB:

set.seed(123)
x <- runif(20, 1, 10)
y <- rnorm(20, mean = 1.8 + 2.4 * x, sd = exp(0.3))
plot(x, y)
obj <- MakeADFun(
  data = list(x = x, y = y), 
  parameters = list(a = 0, b = 0, log_sigma = 0),
  DLL = "regression")
opt <- nlminb(start = obj$par, obj = obj$fn, gr = obj$gr)
rep <- sdreport(obj)

компилятор:

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-16ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --with-as=/usr/bin/x86_64-linux-gnu-as --with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)

~ .R / Makevars (что-то ранее затрагивалось для RcppArmadillo, возможно, это моя ошибка, и ошибка здесь на CXXFLAGS):

CFLAGS= -O -mtune=native
CXXFLAGS= -O2 -mtune=native -march=native -pthread -fopenmp $(BLAS_LIBS) $(LAPACK_LIBS)
FFLAGS=-g -O -mtune=native
FCFLAGS=-g -O -mtune=native

Edit (себя) Я пытаюсь пример RcppEigen по адресу: http://dirk.eddelbuettel.com/code/rcpp.eigen.html он работает нормально, выдавая много предупреждений (которые обычно не происходят с Rcpp), вызывая sourceCpp(file="input.cc"), он компилируется и выполняетсяправильно.

Я пытаюсь первый пример, найденный на TMB в https://github.com/nwfsc-assess/geostatistical_delta-GLMM/wiki/Steps-to-install-TMB, он дает мне:

0 regions found.
Using 8 threads
TMB has received an error from Eigen. The following condition was not met:
index >= 0 && index < size()
Please check your matrix-vector bounds etc., or run your program through a debugger.

до сбоя

Ответы [ 2 ]

0 голосов
/ 26 июня 2018

решена:

1) чтобы избежать вывода шумных предупреждений, добавьте флаг

-Wno-ignored-attributes

2), чтобы избежать ошибки времени выполнения при вызове adfun, уберите флаг

-fopenmp

перед компиляцией целевой функции IF модель (код C ++ objective_function<Type>::operator()) не использует openMP (пример #pragma omp что-то ).

источник (я спрашиваю здесь): https://github.com/kaskr/adcomp/issues/277

0 голосов
/ 25 июня 2018

похоже, что у вас может не быть установлен пакет Eigen dev (так как это свежая установка Ubuntu) Вы пробовали

sudo apt-get install libeigen3-dev 

похоже, что вы также можете установить скомпилированный двоичный пакет через

sudo apt-get install r-cran-rcppeigen

очевидно, что rcppeigen может потребовать много оперативной памяти для компиляции и не работает на некоторых машинах с небольшим оперативной памятью.

...