aldro61 / mmit

Regression trees for interval censored output data
https://aldro61.github.io/mmit/
GNU General Public License v3.0
7 stars 7 forks source link

R package compiles #1

Closed tdhock closed 7 years ago

tdhock commented 7 years ago

@aldro61 these changes were required to make the new code compile on my computer... however now I am getting a segfault when I run the R package tests...

tdhock commented 7 years ago

on master I got the following compilation errors

thocking@silene:~/projects/mmit(master*)$ python setup.py install --prefix=$HOMErunning install
running bdist_egg
running egg_info
writing mmit.egg-info/PKG-INFO
writing top-level names to mmit.egg-info/top_level.txt
writing dependency_links to mmit.egg-info/dependency_links.txt
reading manifest file 'mmit.egg-info/SOURCES.txt'
writing manifest file 'mmit.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/mmit
copying mmit/__init__.py -> build/lib.linux-x86_64-2.7/mmit
creating build/lib.linux-x86_64-2.7/mmit/core
copying mmit/core/__init__.py -> build/lib.linux-x86_64-2.7/mmit/core
creating build/lib.linux-x86_64-2.7/mmit/tests
copying mmit/tests/trivial_tests.py -> build/lib.linux-x86_64-2.7/mmit/tests
copying mmit/tests/__init__.py -> build/lib.linux-x86_64-2.7/mmit/tests
running build_ext
building 'mmit.core.solver' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/mmit
creating build/temp.linux-x86_64-2.7/mmit/core
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -I/usr/local/lib/python2.7/dist-packages/numpy/core/include -c mmit/core/solver_python_bindings.cpp -o build/temp.linux-x86_64-2.7/mmit/core/solver_python_bindings.o -std=c++0x
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
In file included from mmit/core/piecewise_function.h:22:0,
                 from mmit/core/solver.h:19,
                 from mmit/core/solver_python_bindings.cpp:6:
mmit/core/coefficients.h:21:24: sorry, unimplemented: non-static data member initializers
mmit/core/coefficients.h:21:24: error: ‘constexpr’ needed for in-class initialization of static data member ‘quadratic’ of non-integral type
mmit/core/coefficients.h:22:21: sorry, unimplemented: non-static data member initializers
mmit/core/coefficients.h:22:21: error: ‘constexpr’ needed for in-class initialization of static data member ‘linear’ of non-integral type
mmit/core/coefficients.h:23:23: sorry, unimplemented: non-static data member initializers
mmit/core/coefficients.h:23:23: error: ‘constexpr’ needed for in-class initialization of static data member ‘constant’ of non-integral type
mmit/core/coefficients.h: In constructor ‘Coefficients::Coefficients()’:
mmit/core/coefficients.h:25:26: error: ‘class Coefficients’ has no member named ‘quadratic’
mmit/core/coefficients.h:25:47: error: ‘class Coefficients’ has no member named ‘linear’
mmit/core/coefficients.h:25:65: error: ‘class Coefficients’ has no member named ‘constant’
mmit/core/coefficients.h: In constructor ‘Coefficients::Coefficients(double, double, double)’:
mmit/core/coefficients.h:26:54: error: ‘class Coefficients’ has no member named ‘quadratic’
mmit/core/coefficients.h:26:75: error: ‘class Coefficients’ has no member named ‘linear’
mmit/core/coefficients.h:26:93: error: ‘class Coefficients’ has no member named ‘constant’
In file included from mmit/core/solver.h:19:0,
                 from mmit/core/solver_python_bindings.cpp:6:
mmit/core/piecewise_function.h: At global scope:
mmit/core/piecewise_function.h:37:36: error: invalid use of non-static data member ‘PiecewiseFunction::breakpoint_coefficients’
mmit/core/piecewise_function.h:41:56: error: from this location
mmit/core/piecewise_function.h:41:84: sorry, unimplemented: non-static data member initializers
mmit/core/piecewise_function.h:41:84: error: in-class initialization of static data member ‘min_ptr’ of non-literal type
error: command 'gcc' failed with exit status 1
thocking@silene:~/projects/mmit(master*)$ 
tdhock commented 7 years ago

I got the following when I ran the R package tests using the code on this branch

bash R_CMD_build_check.sh 
Warning: invalid uid value replaced by that for user 'nobody'

* using log directory ‘/home/thocking/projects/mmit/MMIT.Rcheck’
* using R version 3.3.3 (2017-03-06)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘MMIT/DESCRIPTION’ ... OK
* this is package ‘MMIT’ version ‘2017.03.15’
* checking package namespace information ... OK
* checking package dependencies ... 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 ‘MMIT’ can be installed ... OK
* checking installed package size ... OK
* checking package 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 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 C/C++/Fortran sources/headers ... OK
* 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 compiled code ... NOTE
File ‘MMIT/libs/MMIT.so’:
  Found ‘_ZSt4cout’, possibly from ‘std::cout’ (C++)
    Object: ‘piecewise_function.o’

Compiled code should not call entry points which might terminate R nor
write to stdout/stderr instead of to the console, nor the system RNG.

See ‘Writing portable packages’ in the ‘Writing R Extensions’ manual.
* checking examples ... ERROR
Running examples in ‘MMIT-Ex.R’ failed
The error most likely occurred in:

> ### Name: compute_optimal_costs
> ### Title: compute optimal costs
> ### Aliases: compute_optimal_costs
> 
> ### ** Examples
> 
> library(MMIT)
> target.mat <- rbind(
+   c(-1, Inf),
+   c(-2, 3),
+   c(-Inf, 1))
> input.vec <- c(-2.2, 3, 10)
> compute_optimal_costs(input.vec, target.mat, 0)

INSERTION COMPLETED
----------------------------
N pointer moves: 0

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: .C("compute_optimal_costs_interface", n_data = length(feature.vec),     feature_vec = as.double(feature.vec), lower_vec = as.double(lower.vec),     upper_vec = as.double(upper.vec), margin = as.double(margin),     loss = as.integer(fun.vec[[loss]]), moves_vec = as.integer(neg.vec),     pred_vec = as.double(inf.vec), cost_vec = as.double(inf.vec),     NAOK = TRUE, PACKAGE = "MMIT")
 2: compute_optimal_costs(input.vec, target.mat, 0)
An irrecoverable exception occurred. R is aborting now ...
Segmentation fault (core dumped)
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
  Running ‘testthat.R’
 ERROR
Running the tests in ‘tests/testthat.R’ failed.
Last 13 lines of output:
   4: eval(exprs, env)
   5: source_file(path, new.env(parent = env), chdir = TRUE)
   6: force(code)
   7: with_reporter(reporter = reporter, start_end_reporter = start_end_reporter,     {        lister$start_file(basename(path))        source_file(path, new.env(parent = env), chdir = TRUE)        end_context()    })
   8: FUN(X[[i]], ...)
   9: lapply(paths, test_file, env = env, reporter = current_reporter,     start_end_reporter = FALSE, load_helpers = FALSE)
  10: force(code)
  11: with_reporter(reporter = current_reporter, results <- lapply(paths,     test_file, env = env, reporter = current_reporter, start_end_reporter = FALSE,     load_helpers = FALSE))
  12: test_files(paths, reporter = reporter, env = env, ...)
  13: test_dir(test_path, reporter = reporter, env = env, filter = filter,     ...)
  14: with_top_env(env, {    test_dir(test_path, reporter = reporter, env = env, filter = filter,         ...)})
  15: run_tests(package, test_path, filter, reporter, ...)
  16: test_check("MMIT")
  An irrecoverable exception occurred. R is aborting now ...
  Segmentation fault (core dumped)
* checking PDF version of manual ... OK
* DONE

Status: 2 ERRORs, 1 NOTE
See
  ‘/home/thocking/projects/mmit/MMIT.Rcheck/00check.log’
for details.

make: *** [Rpackage.check] Error 1
aldro61 commented 7 years ago

I deleted my previously compiled version and trie to recompile with the new code (this branch) and I'm also getting a segfault. Don't know whats wrong. I'll investigate.

aldro61 commented 7 years ago

I found a clue. The first time insert_point is called, the following condition is false, but it should be true (and is true with the code on master):

this->min_ptr == this->breakpoint_coefficients.end()

Also, if I verify this condition inside the constructor of PiecewiseFunction, it is true. It's as if the value was changing before we first call insert_point.

tdhock commented 7 years ago

I added some code for automatic testing using https://travis-ci.org/ -- can you please log in to travis and turn it on for this repository?

tdhock commented 7 years ago

not sure what the problem is, but you may want to use a typedef to clarify what is going on here

    // Insert the new breakpoint
    std::pair<std::map<double, Coefficients>::iterator, bool> insert = this->breakpoint_coefficients.insert(std::pair<double, Coefficients>(breakpoint_position, new_breakpoint_coefficients));
aldro61 commented 7 years ago

I fixed the segfault (see this commit). It turns out that calling the constructor from within the more simple constructor was messing up the initialization of min_ptr.

tdhock commented 7 years ago

is it OK with you to stop with an error when the features are not sorted? (otherwise I guess the features are not used at all and we could just not pass them at all to the C++ code?)

Before merging this branch with master, maybe we should add some tests with tied features?

tdhock commented 7 years ago

actually, whether or not there are ties in the features won't affect the solver, right? I'm thinking that we should probably just not pass the features at all to the C++ code. What do you think?

aldro61 commented 7 years ago

I think that features could simply not be passed to the solver. What the code is really doing is adding one point at a time. The outputted values also correspond to each point.

Update: yup, I agree.

I found a new test that fails. I’ll fix it and add it to the tests.

tdhock commented 7 years ago

ok great I will remove that new test then

tdhock commented 7 years ago

ok I removed the feature_vec argument from the C++ solver function

aldro61 commented 7 years ago

We should add a test that checks that the total cost/prediction (last value of the returned arrays) are the same for different shufflings of points.