astamm / nloptr

nloptr provides an R interface to NLopt, a free/open-source library for nonlinear optimization providing a common interface to a number of different optimization routines which can handle nonlinear constraints and lower and upper bounds for the controls.
https://astamm.github.io/nloptr/
Other
106 stars 34 forks source link

test nloptr failed #79

Closed Tom-python0121 closed 3 years ago

Tom-python0121 commented 3 years ago

test nloptr failed.

Steps to reproduce the issue

[root@localhost tests]# Rscript test-all.R
Loading required package: nloptr

ERROR(s) during compilation: source code errors or compiler configuration errors!
make cmd is
  make -f '/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/etc/Makeconf' -f '/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/share/make/shlib.mk' SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB='file1e2e1526407eae.so' OBJECTS='file1e2e1526407eae.o'

make would use
/usr/bin/g++ -std=gnu++11 -I"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/include" -DNDEBUG   -I/usr/local/include   -I/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/nlopt-2.6.1-dkwymuffherlgnhvowx24pqsa6fcaa46/include  -fpic  -g -O2  -c file1e2e1526407eae.cpp -o file1e2e1526407eae.o
if test  "zfile1e2e1526407eae.o" != "z"; then \
  echo /usr/bin/g++ -std=gnu++11 -shared -L"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib" -L/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib -Wl,-rpath,/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib -o file1e2e1526407eae.so file1e2e1526407eae.o  -L/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/nlopt-2.6.1-dkwymuffherlgnhvowx24pqsa6fcaa46/lib -lnlopt   -L"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib" -lR; \
  /usr/bin/g++ -std=gnu++11 -shared -L"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib" -L/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib -Wl,-rpath,/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib -o file1e2e1526407eae.so file1e2e1526407eae.o  -L/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/nlopt-2.6.1-dkwymuffherlgnhvowx24pqsa6fcaa46/lib -lnlopt   -L"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib" -lR; \
fi

Program source:
  1: #include <R.h>
  2: #include <Rdefines.h>
  3: #include <R_ext/Error.h>
  4:
  5: #include "nloptrAPI.h"
  6:
  7: extern "C" {
  8:   SEXP file1e2e1526407eae (  );
  9: }
 10:
 11: SEXP file1e2e1526407eae (  ) {
 12:
 13:       // get version of NLopt
 14:       int major, minor, bugfix;
 15:       nlopt_version(&major, &minor, &bugfix);
 16:
 17:       SEXP retvec = PROTECT(allocVector(INTSXP, 3));
 18:       INTEGER(retvec)[0] = major;
 19:       INTEGER(retvec)[1] = minor;
 20:       INTEGER(retvec)[2] = bugfix;
 21:
 22:       UNPROTECT(1);
 23:       return retvec;
 24:   warning("your C program does not return anything!");
 25:   return R_NilValue;
 26: }

Compilation ERROR, function(s)/method(s) not created!

ERROR(s) during compilation: source code errors or compiler configuration errors!
make cmd is
  make -f '/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/etc/Makeconf' -f '/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/share/make/shlib.mk' SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB='file1e2e15188f35ba.so' OBJECTS='file1e2e15188f35ba.o'

make would use
/usr/bin/g++ -std=gnu++11 -I"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/include" -DNDEBUG   -I/usr/local/include   -I/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/nlopt-2.6.1-dkwymuffherlgnhvowx24pqsa6fcaa46/include  -fpic  -g -O2  -c file1e2e15188f35ba.cpp -o file1e2e15188f35ba.o
if test  "zfile1e2e15188f35ba.o" != "z"; then \
  echo /usr/bin/g++ -std=gnu++11 -shared -L"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib" -L/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib -Wl,-rpath,/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib -o file1e2e15188f35ba.so file1e2e15188f35ba.o  -L/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/nlopt-2.6.1-dkwymuffherlgnhvowx24pqsa6fcaa46/lib -lnlopt   -L"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib" -lR; \
  /usr/bin/g++ -std=gnu++11 -shared -L"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib" -L/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib -Wl,-rpath,/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib -o file1e2e15188f35ba.so file1e2e15188f35ba.o  -L/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/nlopt-2.6.1-dkwymuffherlgnhvowx24pqsa6fcaa46/lib -lnlopt   -L"/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/lib" -lR; \
fi

Program source:
  1: #include <R.h>
  2: #include <Rdefines.h>
  3: #include <R_ext/Error.h>
  4:
  5:
  6: #include <math.h>
  7: #include "nloptrAPI.h"
  8:
  9: double myfunc(unsigned n, const double *x, double *grad, void *my_func_data)
 10: {
 11:     if (grad) {
 12:         grad[0] = 0.0;
 13:         grad[1] = 0.5 / sqrt(x[1]);
 14:     }
 15:     return sqrt(x[1]);
 16: }
 17:
 18: typedef struct {
 19:     double a, b;
 20: } my_constraint_data;
 21:
 22: double myconstraint(unsigned n, const double *x, double *grad, void *data)
 23: {
 24:     my_constraint_data *d = (my_constraint_data *) data;
 25:     double a = d->a, b = d->b;
 26:     if (grad) {
 27:         grad[0] = 3 * a * (a*x[0] + b) * (a*x[0] + b);
 28:         grad[1] = -1.0;
 29:     }
 30:     return ((a*x[0] + b) * (a*x[0] + b) * (a*x[0] + b) - x[1]);
 31: }
 32:
 33:
 34: extern "C" {
 35:   SEXP file1e2e15188f35ba (  );
 36: }
 37:
 38: SEXP file1e2e15188f35ba (  ) {
 39:
 40: double lb[2] = { -HUGE_VAL, 0 }; /* lower bounds */
 41: nlopt_opt opt;
 42:
 43: opt = nlopt_create(NLOPT_LD_MMA, 2); /* algorithm and dimensionality */
 44: nlopt_set_lower_bounds(opt, lb);
 45: nlopt_set_min_objective(opt, myfunc, NULL);
 46:
 47: my_constraint_data data[2] = { {2,0}, {-1,1} };
 48:
 49: nlopt_add_inequality_constraint(opt, myconstraint, &data[0], 1e-8);
 50: nlopt_add_inequality_constraint(opt, myconstraint, &data[1], 1e-8);
 51:
 52: nlopt_set_xtol_rel(opt, 1e-4);
 53:
 54: double x[2] = { 1.234, 5.678 };  /* some initial guess */
 55: double minf; /* the minimum objective value, upon return */
 56: if (nlopt_optimize(opt, x, &minf) < 0) {
 57:     //Rprintf("nlopt failed!\n");
 58: }
 59: else {
 60:     //Rprintf("found minimum at f(%g,%g) = %0.10g\n", x[0], x[1], minf);
 61: }
 62:
 63: nlopt_destroy(opt);
 64:
 65: // Convert result to SEXP.
 66: SEXP result = PROTECT(allocVector(REALSXP, 2));
 67: REAL(result)[0] = x[0];
 68: REAL(result)[1] = x[1];
 69: UNPROTECT(1);
 70:
 71: return result;
 72:   warning("your C program does not return anything!");
 73:   return R_NilValue;
 74: }

Compilation ERROR, function(s)/method(s) not created!
══ Failed tests ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
── Error (test-C-api.R:43:5): Test exposing NLopt C function nlopt_version. ───────────────────────────
Error in `compileCode(f, code, language, verbose)`: file1e2e1526407eae.cpp:5:10: fatal error: nloptrAPI.h: No such file or directory #include "nloptrAPI.h"          ^~~~~~~~~~~~~compilation terminated.make: *** [/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/etc/Makeconf:181: file1e2e1526407eae.o] Error 1
Backtrace:
    █
 1. └─inline::cfunction(...) test-C-api.R:43:4
 2.   └─inline:::compileCode(f, code, language, verbose)
── Error (test-C-api.R:126:5): Test exposed NLopt C code using example from NLopt tutorial. ───────────────────────────
Error in `compileCode(f, code, language, verbose)`: file1e2e15188f35ba.cpp:7:10: fatal error: nloptrAPI.h: No such file or directory #include "nloptrAPI.h"          ^~~~~~~~~~~~~compilation terminated.make: *** [/home/all_spack_env/spack/opt/spack/linux-centos8-aarch64/gcc-8.4.1/r-4.0.4-prs4254xn47h5pg4e3fo6xtm7gsskx3m/rlib/R/etc/Makeconf:181: file1e2e15188f35ba.o] Error 1
Backtrace:
    █
 1. └─inline::cfunction(...) test-C-api.R:126:4
 2.   └─inline:::compileCode(f, code, language, verbose)
── Failure (test-hs071.R:96:5): Test HS071. ────────────────────────────────────
`x` not equal to `expected`.
3/4 mismatches (average diff: 5.54e-06)
[2] 4.74 - 4.74 ==  6.69e-06
[3] 3.82 - 3.82 == -8.73e-06
[4] 1.38 - 1.38 ==  1.21e-06
Backtrace:
    █
 1. └─testthat::expect_that(res$solution, equals(solution.opt, tolerance = 1e-06)) test-hs071.R:96:4
 2.   └─testthat:::condition(object)
 3.     └─testthat::expect_equal(x, expected, ..., expected.label = label)

[ FAIL 3 | WARN 10 | SKIP 0 | PASS 43 ]
Error: Test failures
Execution halted

can you tell me why?

eddelbuettel commented 3 years ago

Sorry, I am confused. Are you saying you are worried that Rscript test-all.R fails?

Have you tried the standard way to test a package that is documented, (more or less) required, and also used by CRAN where it clearly passes on all test systems (ignore the fact that there are two versions, a new one just arrived with a minute, unrelated configure update) ? You are supposed to run

  R CMD build .                  # when in the source directory, above use the source-dir name as arg
  R CMD check nloptr_*.tar.gz    # the resulting source tar ball

Please try that as it is the usual way to test.

Tom-python0121 commented 3 years ago

@eddelbuettel ,I have done that,but it have failed:

[root@localhost spack-stage-r-nloptr-1.2.1-s4wmhuj3djfft6a67xbdlfdlyrvyvorl]# ls
nloptr_1.2.1.tar.gz  spack-build-env.txt  spack-build-out.txt  spack-configure-args.txt  spack-src
[root@localhost spack-stage-r-nloptr-1.2.1-s4wmhuj3djfft6a67xbdlfdlyrvyvorl]# R CMD check nloptr_1.2.1.tar.gz
* using log directory '/home/all_spack_env/spack_stage/root/spack-stage-r-nloptr-1.2.1-s4wmhuj3djfft6a67xbdlfdlyrvyvorl/nloptr.Rcheck'
* using R version 4.0.4 (2021-02-15)
* using platform: aarch64-unknown-linux-gnu (64-bit)
* using session charset: ASCII
* checking for file 'nloptr/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'nloptr' version '1.2.1'
* checking package namespace information ... OK
* checking package dependencies ...Warning: unable to access index for repository https://CRAN.R-project.org/src/contrib:
  Line starting '<!DOCTYPE html ...' is malformed!
 OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether package 'nloptr' can be installed ... WARNING
Found the following significant warnings:
  'config' variable 'CPP' is deprecated
  'config' variable 'CXXCPP' is deprecated
See '/home/all_spack_env/spack_stage/root/spack-stage-r-nloptr-1.2.1-s4wmhuj3djfft6a67xbdlfdlyrvyvorl/nloptr.Rcheck/00install.out' for details.
* checking installed package size ... OK
* checking package directory ... OK
* checking 'build' directory ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking loading without being on the library search path ... OK
* checking dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking line endings in shell scripts ... OK
* checking line endings in C/C++/Fortran sources/headers ... NOTE
Found the following sources/headers with CR or CRLF line endings:
  inst/include/nloptrAPI.h
Some Unix compilers require LF line endings.
* checking line endings in Makefiles ... OK
* checking compilation flags in Makevars ... OK
* checking for GNU extensions in Makefiles ... OK
* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK
* checking use of PKG_*FLAGS in Makefiles ... OK
* checking include directives in Makefiles ... OK
* checking compiled code ... OK
* checking installed files from 'inst/doc' ... OK
* checking files in 'vignettes' ... OK
* checking examples ... OK
* checking for unstated dependencies in 'tests' ... OK
* checking tests ...
  Running 'test-all.R'
 ERROR
Running the tests in 'tests/test-all.R' failed.
Last 13 lines of output:
  -- Failure (test-hs071.R:96:5): Test HS071. ------------------------------------
  `x` not equal to `expected`.
  3/4 mismatches (average diff: 5.54e-06)
  [2] 4.74 - 4.74 ==  6.69e-06
  [3] 3.82 - 3.82 == -8.73e-06
  [4] 1.38 - 1.38 ==  1.21e-06
  Backtrace:
      x
   1. \-testthat::expect_that(res$solution, equals(solution.opt, tolerance = 1e-06)) test-hs071.R:96:4
   2.   \-testthat:::condition(object)
   3.     \-testthat::expect_equal(x, expected, ..., expected.label = label)

  [ FAIL 3 | WARN 10 | SKIP 0 | PASS 43 ]
  Error: Test failures
  Execution halted
* checking for unstated dependencies in vignettes ... OK
* checking package vignettes in 'inst/doc' ... OK
* checking running R code from vignettes ...
  'nloptr.Rmd' using 'UTF-8'... OK
 NONE
* checking re-building of vignette outputs ... OK
* checking PDF version of manual ... OK
* DONE

Status: 1 ERROR, 1 WARNING, 1 NOTE
eddelbuettel commented 3 years ago

Well

using platform: aarch64-unknown-linux-gnu (64-bit)

and

-- Failure (test-hs071.R:96:5): Test HS071. ------------------------------------
  `x` not equal to `expected`.
  3/4 mismatches (average diff: 5.54e-06)
  [2] 4.74 - 4.74 ==  6.69e-06
  [3] 3.82 - 3.82 == -8.73e-06
  [4] 1.38 - 1.38 ==  1.21e-06

may go hand-in-hand? Maybe some things are different on that platform? I did point you to the CRAN page at https://cran.r-project.org/web/checks/check_results_nloptr.html which looks pretty good for the current version. You may have to put on the hard hat and get down into the mine if you're porting to a new / less supported platform. "It works over here for me" is sadly all I can say on x86_64.

Tom-python0121 commented 3 years ago

@eddelbuettel You are correct, it did pass the test on x86_64 and may produce error values on the aarch64 platform, which does seem to need to dig deeper. Thank you for letting me know that at least this bug is not caused by the software itself, but by a difference in the platform system. Now that I've confirmed this, I'm going to turn off this issuse.