PoonLab / Kaphi

Kernel-embedded ABC-SMC for phylodynamic inference
GNU Affero General Public License v3.0
4 stars 2 forks source link

Look into dropping igraph submodule #126

Closed ArtPoon closed 5 years ago

ArtPoon commented 6 years ago

Are we still using @rmcclosk 's thread safe functionality?

ArtPoon commented 6 years ago

Examine diff of our current C-igraph and the most recent C-igraph to figure out what has been changed, and then insert print statements to determine whether the respective components are being called in Kaphi. If not, we can safely remove this submodule and reference C-igraph as a dependency.

0ldM4j0r commented 6 years ago

rmcclosk/igraph@f51100837fe86a51a651f086b470194b22d60dc7 rmcclosk/igraph@0838e71e863dc2f6cb3eac4fadc7fb3d60853b3f

are the only commits made by Rosemary in which C files were changed. The other commits deal with files relating to the compiling of igraph.

the first of the two commits above seems to be the one that we are concerned with, as it has IGRAPH_THREAD_LOCAL. I will start testing to see if the code from either commit is critical for Kaphi.

0ldM4j0r commented 6 years ago

I did a grep on the Kaphi repo to see if any of the cliquer functions are called in it, and there isn't any occurrences of said functions.

After that I added print statements in the cliquer functions, recompiled igraph, and ran the Yule model and SIRD model to see if any of the print statements got executed, and non-did.

Therefore, I believe we can drop the igraph submodule.

0ldM4j0r commented 6 years ago

Removed igraph submodule, and update INSTALL.md for Kaphi, and made INSTALL.md for clmp.

0ldM4j0r commented 6 years ago

@ArtPoon, I have reverted the changes I made to drop igraph, which are the commits e316e64add406e358607f795c5f64d9feedcdb9c, b8ce331f2968a7920e6ca431c813bfc02cfd2243, and 19b115eb463f265ee8793f0d39250f69dfab0bdf. I pushed the reverted code to Kaphi in the commits 70e21bf7652c84b4368d7f0739afdceeeb131989, 457840c1792e5c5d3f6938fdfb567502498996f4, ed63b13f39a29a5888782e2546e28cfd77550ade. After more testing with the removing of Rosemary's igraph yesterday I ran into a couple of problems.

The files under the directory /pkg/src/ in Kaphi include the header file igraph.h in different ways as follows:

./pkg/src/kernel.c:#include <igraph.h>
./pkg/src/newick_lexer.c:#include "igraph/include/igraph.h"
./pkg/src/newick_lexer.l:#include "igraph/include/igraph.h"
./pkg/src/newick_parser.c:#include "igraph/include/igraph.h"
./pkg/src/newick_parser.y:#include "igraph/include/igraph.h"
./pkg/src/tree.c:#include <igraph.h>
./pkg/src/tree.h:#include <igraph.h>
./pkg/src/treestats.c:#include <igraph.h>
./pkg/src/util.c:#include <igraph.h>
./pkg/src/util.h:#include <igraph.h>

The above works when using Rosemary's igraph.

However the way to include the header file igraph.h when using the normal igraph is like this: #include <igraph/igraph.h>, so when trying to install Kaphi with the normal igraph the header file igraph.h isn't detected since it isn't correctly referenced. The referencing isn't the only issue, as when is change all the includes to #include <igraph/igraph.h> I got the following errors:

ubuntu@ubuntu-xenial:~/Kaphi$ sudo R CMD INSTALL pkg
* installing to library ‘/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.4’
* installing *source* package ‘Kaphi’ ...
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG     -Iigraph/include -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c tree.c -o tree.o
tree.c:15:0: warning: "NDEBUG" redefined
 #define NDEBUG
 ^
<command-line>:0:0: note: this is the location of the previous definition
tree.c: In function ‘_permute_tree_attrs’:
tree.c:262:13: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
         inc = igraph_inclist_get(&inclist, i);
             ^
tree.c: In function ‘subsample_tips’:
tree.c:503:5: error: too many arguments to function ‘igraph_neighborhood’
     igraph_neighborhood(tree, &nbhd, igraph_vss_vector(&keep_tips), INT_MAX, IGRAPH_IN, 0);
     ^
In file included from /usr/include/igraph/igraph.h:65:0,
                 from tree.c:9:
/usr/include/igraph/igraph_neighborhood.h:42:5: note: declared here
 int igraph_neighborhood(const igraph_t *graph, igraph_vector_ptr_t *res,
     ^
tree.c: In function ‘subsample_tips_peerdriven’:
tree.c:583:5: error: too many arguments to function ‘igraph_neighborhood’
     igraph_neighborhood(tree, &nbhd, igraph_vss_vector(&keep_tips), INT_MAX, IGRAPH_IN, 0);
     ^
In file included from /usr/include/igraph/igraph.h:65:0,
                 from tree.c:9:
/usr/include/igraph/igraph_neighborhood.h:42:5: note: declared here
 int igraph_neighborhood(const igraph_t *graph, igraph_vector_ptr_t *res,
     ^
tree.c: In function ‘subsample’:
tree.c:676:21: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
                 inc = igraph_inclist_get(&inclist, v);
                     ^
tree.c:690:9: error: too many arguments to function ‘igraph_neighborhood’
         igraph_neighborhood(tree, &nbhd, igraph_vss_vector(&drop), INT_MAX, IGRAPH_OUT, 0);
         ^
In file included from /usr/include/igraph/igraph.h:65:0,
                 from tree.c:9:
/usr/include/igraph/igraph_neighborhood.h:42:5: note: declared here
 int igraph_neighborhood(const igraph_t *graph, igraph_vector_ptr_t *res,
     ^
/usr/lib/R/etc/Makeconf:159: recipe for target 'tree.o' failed
make: *** [tree.o] Error 1
ERROR: compilation failed for package ‘Kaphi’
* removing ‘/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.4/Kaphi’

The problem relates to the igraph_neighborhood function used in tree.c. Rosemary's igraph doesn't include the igraph_neighborhood function used in tree.c while the normal igraph does, if the function isn't important in tree.c stripping in out would allow the usage of the normal igraph.

When I wrote the installation instructions using Rosemary's igraph I tested said instructions on Ubuntu 16.04, 14.04, 12.04, and Mac Sierra. Therefore, I am confident that they work and in turn went back to them. However, if you would like me to strip the igraph_neighborhood function from tree.c I can always go back to the instructions using the normal igraph as they are already logged.

I haven't faced any problems with clmp when using the normal igraph so the installation instructions for clmp use the normal igraph.

ArtPoon commented 6 years ago
gtng92 commented 6 years ago

I've removed the igraph submodule, and was in the process of reinstalling Kaphi on the Lenovo laptop to test. I followed the instructions in INSTALL.md from commit b8ce331 and encounter the following error:

tng92@Clamps:~/git/Kaphi$ R CMD INSTALL pkg
* installing to library ‘/home/tng92/R/x86_64-pc-linux-gnu-library/3.2’
* installing *source* package ‘Kaphi’ ...
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG     -Iigraph/include -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c kernel.c -o kernel.o
kernel.c:18:20: fatal error: igraph.h: No such file or directory
compilation terminated.
/usr/lib/R/etc/Makeconf:134: recipe for target 'kernel.o' failed
make: *** [kernel.o] Error 1
ERROR: compilation failed for package ‘Kaphi’
* removing ‘/home/tng92/R/x86_64-pc-linux-gnu-library/3.2/Kaphi’

Currently doesn't detect igraph dependency, installed through commands sudo apt-get install libigraph0v5 and sudo apt-get install libigraph0-dev after the installation of bison, flex, and judy.

ArtPoon commented 6 years ago

I think you need to change this bit:

 -Iigraph/include

which directs the compiler to a folder within the package directory, to wherever igraph was installed (probably /usr/local/include)

gtng92 commented 6 years ago

Thanks, I switched it to /usr/include/igraph in the Makevars file, as well as files newick_lexer.c, newick_lexer.l, newick_parser.c, and newick_parser.y because they included the full path name.

Note: this works for the Lenovo. May be different on Mac and Linux workstations.

gtng92 commented 6 years ago

Some compiling errors that pop up relating igraph to tree statistics:

tng92@Clamps:~/git/Kaphi$ R CMD INSTALL pkg
* installing to library ‘/home/tng92/R/x86_64-pc-linux-gnu-library/3.2’
* installing *source* package ‘Kaphi’ ...
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG     -I /usr/include/igraph -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c newick_lexer.c -o newick_lexer.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG     -I /usr/include/igraph -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c newick_parser.c -o newick_parser.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG     -I /usr/include/igraph -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c tree.c -o tree.o
tree.c:15:0: warning: "NDEBUG" redefined
 #define NDEBUG
 ^
<command-line>:0:0: note: this is the location of the previous definition
tree.c: In function ‘_permute_tree_attrs’:
tree.c:262:13: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
         inc = igraph_inclist_get(&inclist, i);
             ^
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG     -I /usr/include/igraph -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c treekernel.c -o treekernel.o
treekernel.c: In function ‘get_options’:
treekernel.c:96:21: warning: implicit declaration of function ‘strcmp’ [-Wimplicit-function-declaration]
                 if (strcmp(optarg, "mean") == 0) {
                     ^
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG     -I /usr/include/igraph -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c treestats.c -o treestats.o
treestats.c:17:0: warning: "NDEBUG" redefined
 #define NDEBUG
 ^
<command-line>:0:0: note: this is the location of the previous definition
treestats.c: In function ‘nLTT’:
treestats.c:238:29: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘double’ [-Wformat=]
             fprintf(stdout, "%d\t%d\t%d\t%f\t%f\n", itree, i, buf[node_order[i]], x[itree][i], y[itree][i]);
                             ^
treestats.c: In function ‘width’:
treestats.c:349:5: error: too many arguments to function ‘igraph_neighborhood_size’
     igraph_neighborhood_size(tree, &nbhd, vs, i, IGRAPH_OUT, 0);
     ^
In file included from /usr/include/igraph/igraph.h:65:0,
                 from treestats.c:11:
/usr/include/igraph/igraph_neighborhood.h:39:5: note: declared here
 int igraph_neighborhood_size(const igraph_t *graph, igraph_vector_t *res,
     ^
treestats.c:354:9: error: too many arguments to function ‘igraph_neighborhood_size’
         igraph_neighborhood_size(tree, &nbhd, vs, i, IGRAPH_OUT, 0);
         ^
In file included from /usr/include/igraph/igraph.h:65:0,
                 from treestats.c:11:
/usr/include/igraph/igraph_neighborhood.h:39:5: note: declared here
 int igraph_neighborhood_size(const igraph_t *graph, igraph_vector_t *res,
     ^
treestats.c: In function ‘max_delta_width’:
treestats.c:371:5: error: too many arguments to function ‘igraph_neighborhood_size’
     igraph_neighborhood_size(tree, &nbhd, vs, i, IGRAPH_OUT, 0);
     ^
In file included from /usr/include/igraph/igraph.h:65:0,
                 from treestats.c:11:
/usr/include/igraph/igraph_neighborhood.h:39:5: note: declared here
 int igraph_neighborhood_size(const igraph_t *graph, igraph_vector_t *res,
     ^
treestats.c:375:9: error: too many arguments to function ‘igraph_neighborhood_size’
         igraph_neighborhood_size(tree, &nbhd, vs, ++i, IGRAPH_OUT, 0);
         ^
In file included from /usr/include/igraph/igraph.h:65:0,
                 from treestats.c:11:
/usr/include/igraph/igraph_neighborhood.h:39:5: note: declared here
 int igraph_neighborhood_size(const igraph_t *graph, igraph_vector_t *res,
     ^
treestats.c: In function ‘branch_lengths’:
treestats.c:866:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
         edge = igraph_inclist_get(&il, i);
              ^
/usr/lib/R/etc/Makeconf:134: recipe for target 'treestats.o' failed
make: *** [treestats.o] Error 1
ERROR: compilation failed for package ‘Kaphi’
* removing ‘/home/tng92/R/x86_64-pc-linux-gnu-library/3.2/Kaphi’
gtng92 commented 6 years ago

In igraph the function igraph_neighborhood_size is defined as:

int igraph_neighborhood_size(const igraph_t *graph, igraph_vector_t *res,
                 igraph_vs_t vids, igraph_integer_t order, 
                 igraph_neimode_t mode);

Compiling finds an additional argument in tree statistic functions width and max_delta_width

treestats.c:354:9: error: too many arguments to function ‘igraph_neighborhood_size’
         igraph_neighborhood_size(tree, &nbhd, vs, i, IGRAPH_OUT, 0);
gtng92 commented 6 years ago

I removed the final argument 0 from all function calls of igraph_neighborhood_size in pkg/src/tree.c.

Attempted re-installing Kaphi pkg, eliminated the 4 previous errors, encountered 1 new error:

g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o Kaphi.so blank.o dQAL-6.3.o kernel.o newick_lexer.o newick_parser.o tree.o treekernel.o treestats.o util.o -Ligraph/src/.libs -ligraph -L/usr/local/lib -lgsl -lJudy -lgmp -L/usr/lib/R/lib -lR
/usr/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status

Used command sudo apt-get install libgmp-dev to install GMP library. Re-installation of Kaphi package now successful on laptop Clamps.

Now updating INSTALL.md, then running some test-simulations.

gtng92 commented 6 years ago

Running the test suite and I get a segfault:

Executing test function test.speciation.model  ... 
 *** caught segfault ***
address 0x2046ed630, cause 'memory not mapped'

Traceback:
 1: .Call("R_Kaphi_kernel", nwk1, nwk2, lambda, sigma, as.double(rho),     use.label, gamma, normalize, PACKAGE = "Kaphi")
 2: tree.kernel(tree, tree, lambda = config$decay.factor, sigma = config$rbf.variance,     rho = config$sst.control, normalize = 0)
 3: .preprocess.tree(obs.tree, config)
 4: parse.input.tree(st, config)
 5: FUN(X[[i]], ...)
 6: lapply(trees1, function(st) parse.input.tree(st, config))
 7: func()
 8: system.time(func())
 9: doTryCatch(return(expr), name, parentenv, handler)
10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
11: tryCatchList(expr, classes, parentenv, handlers)
12: tryCatch(expr, error = function(e) {    call <- conditionCall(e)    if (!is.null(call)) {        if (identical(call[[1L]], quote(doTryCatch)))             call <- sys.call(-4L)        dcall <- deparse(call)[1L]        prefix <- paste("Error in", dcall, ": ")        LONG <- 75L        msg <- conditionMessage(e)        sm <- strsplit(msg, "\n")[[1L]]        w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w")        if (is.na(w))             w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L],                 type = "b")        if (w > LONG)             prefix <- paste0(prefix, "\n  ")    }    else prefix <- "Error : "    msg <- paste0(prefix, conditionMessage(e), "\n")    .Internal(seterrmessage(msg[1L]))    if (!silent && identical(getOption("show.error.messages"),         TRUE)) {        cat(msg, file = stderr())        .Internal(printDeferredWarnings())    }    invisible(structure(msg, class = "try-error", condition = e))})
13: try(system.time(func()))
14: .executeTestCase(funcName, envir = sandbox, setUpFunc = .setUp,     tearDownFunc = .tearDown)
15: .sourceTestFile(testFile, testSuite$testFuncRegexp)
16: runTestSuite(testsuite.Kaphi)
aborting ...
Segmentation fault (core dumped)
ArtPoon commented 6 years ago

Make a separate branch please

gtng92 commented 6 years ago

Note that if you checkout branch issue126 and re-install the Kaphi pkg, then switch back to master branch, you will need to re-install igraph to fully restore master.

ArtPoon commented 6 years ago
ArtPoon commented 6 years ago

At meeting with @gtng92 we determined that the culprit behind the crash is somewhere in this section of code in src/treestats.c:

    for (i = 0; i < igraph_vcount(tree); ++i)
    {
        fprintf (stdout, "%d\n", i);

        edge = igraph_inclist_get(&il, i);
        if (igraph_vector_int_size(edge) > 0)
        {
            branch_lengths[2*i] = EAN(tree, "length", VECTOR(*edge)[0]);
            branch_lengths[2*i+1] = EAN(tree, "length", VECTOR(*edge)[1]);
        }
    }
gtng92 commented 6 years ago
if (igraph_vector_int_size(edge) > 0)
{
    branch_lengths[2*i] = EAN(tree, "length", VECTOR(*edge)[0]);    //successful
    branch_lengths[2*i+1] = EAN(tree, "length", VECTOR(*edge)[1]);   //breaks
}

Breaking it down further:

fprintf (stdout, "%d\n", branch_lengths[2*i+1] );       //successful
fprintf (stdout, "%d\n", VECTOR(*edge)[1]);             //successful
fprintf (stdout, "%d\n", EAN(tree, "length", VECTOR(*edge)[1]));   //breaks

Looking at Rosemary's changes, there's no alterations with the EAN() function in igraph

ArtPoon commented 6 years ago

Is this a clue from Faisal's earlier post?:

treestats.c: In function ‘branch_lengths’:
treestats.c:866:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
         edge = igraph_inclist_get(&il, i);
ArtPoon commented 6 years ago

EAN is shorthand for igraph_cattribute_EAN, which is declared in igraph/cattributes.c

ArtPoon commented 6 years ago

A couple things to try:

  1. Try calling EAN within R_Kaphi_parse_newick where edge attributes are being assigned, to see if we can simplify this case to reproduce the crash.
  2. Try running R within Valgrind to get more information about the segmentation fault error.
gtng92 commented 6 years ago

I was unable to reproduce the crash by placing EAN in R_Kaphi_parse_newick

I looked into the loop below, and I noticed that on the final iteration, the if statement is not satisfied so there is no EAN being set for the final i.

for (int i = 0; i < igraph_vector_size(&size); ++i)
    {
        igraph_incident(tree, &edge, i, IGRAPH_IN);
        if (igraph_vector_size(&edge) > 0) {
            SETEAN(tree, "length", (int) VECTOR(edge)[0], VECTOR(branch_length)[i]);
        }

        SETVAS(tree, "id", i, STR(label,i));  // assign node label to vertex
    }

The if statement relies on the &edge initialized vector_t object from the igraph_incident call above.

gtng92 commented 6 years ago
R -d valgrind --vanilla < igraphsegfault.R

Using valgrind confirmed that the script breaks at function igraph_cattribute_EAN:

==20338== Invalid read of size 8
==20338==    at 0x16226CA3: igraph_cattribute_EAN (in /usr/lib/x86_64-linux-gnu/libigraph.so.0.0.0)
==20338==    by 0x15EE85E1: branch_lengths (treestats.c:896)
==20338==    by 0x15EE879F: kernel (treestats.c:64)
==20338==    by 0x15EE1838: R_Kaphi_kernel (kernel.c:119)
==20338==    by 0x4F0C7A9: ??? (in /usr/lib/R/lib/libR.so)
==20338==    by 0x4F0CC9B: ??? (in /usr/lib/R/lib/libR.so)
==20338==    by 0x4F4A0AC: Rf_eval (in /usr/lib/R/lib/libR.so)
==20338==    by 0x4F4DCB5: ??? (in /usr/lib/R/lib/libR.so)
==20338==    by 0x4F49E8B: Rf_eval (in /usr/lib/R/lib/libR.so)
==20338==    by 0x4F4CB4D: ??? (in /usr/lib/R/lib/libR.so)
==20338==    by 0x4F49E8B: Rf_eval (in /usr/lib/R/lib/libR.so)
==20338==    by 0x4F4BEAE: ??? (in /usr/lib/R/lib/libR.so)
==20338==  Address 0x209390140 is not stack'd, malloc'd or (recently) free'd
==20338== 

 *** caught segfault ***
address 0x209390140, cause 'memory not mapped'
gtng92 commented 6 years ago
R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < igraphsegfault.R 

Confirmed the above error, plus an additional error in yy_scan_buffer (newick_lexer.c:1520):

==20386== HEAP SUMMARY:
==20386==     in use at exit: 60,083,300 bytes in 29,566 blocks
==20386==   total heap usage: 102,169 allocs, 72,603 frees, 165,337,960 bytes allocated
==20386== 
==20386== 90 (72 direct, 18 indirect) bytes in 1 blocks are definitely lost in loss record 189 of 3,086
==20386==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20386==    by 0x15EE24FC: yy_scan_buffer (newick_lexer.c:1520)
==20386==    by 0x15EE25BC: yy_scan_bytes (newick_lexer.c:1577)
==20386==    by 0x15EE13F3: R_Kaphi_parse_newick (kernel.c:50)
==20386==    by 0x15EE168C: R_Kaphi_kernel (kernel.c:102)
==20386==    by 0x4F0C7A9: ??? (in /usr/lib/R/lib/libR.so)
==20386==    by 0x4F0CC9B: ??? (in /usr/lib/R/lib/libR.so)
==20386==    by 0x4F4A0AC: Rf_eval (in /usr/lib/R/lib/libR.so)
==20386==    by 0x4F4DCB5: ??? (in /usr/lib/R/lib/libR.so)
==20386==    by 0x4F49E8B: Rf_eval (in /usr/lib/R/lib/libR.so)
==20386==    by 0x4F4CB4D: ??? (in /usr/lib/R/lib/libR.so)
==20386==    by 0x4F49E8B: Rf_eval (in /usr/lib/R/lib/libR.so)
ArtPoon commented 6 years ago

👍

ArtPoon commented 6 years ago

I'm contacting @rmcclosk for help, might also be a good idea to post to the C-igraph mailing list but we should have a minimal reproducible example outside of Kaphi.

ArtPoon commented 6 years ago

@gtng92 can you please post the text of igraphsegfault.R here if it's short?

ArtPoon commented 6 years ago

Running tests/runIssue126.R, which comprises the following:

require(Kaphi, quietly=TRUE)
require(RUnit, quietly=TRUE)
source('tests/fixtures/simple-trees.R')

test.issue126 <- function() {
    result <- tree.kernel(t2, t2, lambda=0.1, sigma=2.0, rho=1.0, normalize=1)
    # this is crashing with branch issue126 (vanilla igraph)
}

where t2 is tree with three tips: ((A:0.1,B:0.2):0.1,C:0.3):0; produces the following output:

vcount: 5
0
1
2
i 2 left 0.200000

 *** caught segfault ***
address 0x203be2790, cause 'memory not mapped'

where vcount is the number of vertices in the igraph object tree. igraph_vcount(tree) returns 5, so the vector branch_lengths should have length 10*sizeof(double). The problematic line is:

branch_lengths[2*i+1] = EAN(tree, "length", VECTOR(*edge)[1]);
ArtPoon commented 6 years ago

EAN(graph,n,e) is defined in igraph/include/igraph_attributes.h as a shorthand for igraph_cattribute_EAN((graph), (n), (e)). This in turn is defined in igraph/src/cattributes.c:

/**
 * \function igraph_cattribute_EAN
 * Query a numeric edge attribute.
 * 
 * The attribute must exist, otherwise an error is triggered.
 * \param graph The input graph.
 * \param name The name of the attribute.
 * \param eid The id of the queried edge.
 * \return The value of the attribute.
 * 
 * \sa \ref EAN for an easier interface.
 *
 * Time complexity: O(Ae), the number of edge attributes.
 */
igraph_real_t igraph_cattribute_EAN(const igraph_t *graph, const char *name,
                      igraph_integer_t eid) {
  igraph_i_cattributes_t *attr=graph->attr;
  igraph_vector_ptr_t *eal=&attr->eal;
  long int j;
  igraph_attribute_record_t *rec;
  igraph_vector_t *num;
  igraph_bool_t l=igraph_i_cattribute_find(eal, name, &j);

  if (!l) {
    igraph_error("Unknown attribute", __FILE__, __LINE__, IGRAPH_EINVAL);
    return 0;
  }

  rec=VECTOR(*eal)[j];
  num=(igraph_vector_t*)rec->value;
  return VECTOR(*num)[(long int)eid];
}
ArtPoon commented 6 years ago

Possible clue in compiler warnings:

treestats.c: In function ‘branch_lengths’:
treestats.c:889:14: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
         edge = igraph_inclist_get(&il, i);

In branch_lengths, we declared edge to be a pointer of type igraph_vector_int_t *. In src/igraph/include/igraph_adjlist.h, the declaration seems to fit:

 * Returns a pointer to an <type>igraph_vector_int_t</type> object from an
 * incidence list containing edge ids. The vector can be modified,
 * resized, etc. as desired.
ArtPoon commented 6 years ago

FWIW, Ubuntu 16.04 apt installs libigraph0-dev version 0.7.1-2.1. Rosemary's branch was at 0.8.0-pre+96cd36b according to the VERSION file.

ArtPoon commented 6 years ago

Yeah, something obviously weird here:

vcount: 5
0
igraph_vector_int_size(edge)=0
1
igraph_vector_int_size(edge)=0
2
igraph_vector_int_size(edge)=4
VECTOR(*edge)[0]=0
i 2 left 0.200000
VECTOR(*edge)[1]=1072693248

 *** caught segfault ***
address 0x204874640, cause 'memory not mapped'
ArtPoon commented 6 years ago

I'm giving up on this and porting the tree kernel function into R. This affects issues #12, #13, #126, and #138. I will close these issues when I have a basic implementation of the kernel function in treekernel.R.

ArtPoon commented 5 years ago

Basic implementation written. Opening a new issue to report a bug but closing this one.