bioDS / beast-phylonco

A BEAST2 package for single-cell cancer evolution
GNU Lesser General Public License v2.1
6 stars 2 forks source link

Some tests are failing in ANT, but not in IDE #12

Closed J-Moravec closed 2 years ago

J-Moravec commented 2 years ago

TreeLikelihoodWithErrorFastTest and TreeLikelihoodWithErrorSlowTest are failing, but only with the ANT build, not in IDE.

image

Possible it is my computer only, because of some weird interaction and does not happen in a clean environment.

J-Moravec commented 2 years ago

Same with Gradle. Possible reason:

It seems that the when building in command line, Beagle library is used:

phylonco.beast.evolution.likelihood.TreeLikelihoodWithErrorSlowTest > testGT16ErrorLikelihoodCase1 FAILED
    junit.framework.AssertionFailedError: expected:<-5.107125869350904> but was:<-6.0096031993688195>
        at junit.framework.Assert.fail(Assert.java:57)
        at junit.framework.Assert.failNotEquals(Assert.java:329)
        at junit.framework.Assert.assertEquals(Assert.java:120)
        at junit.framework.Assert.assertEquals(Assert.java:129)
        at phylonco.beast.evolution.likelihood.TreeLikelihoodWithErrorSlowTest.testGT16ErrorLikelihoodCase1(TreeLikelihoodWithErrorSlowTest.java:529)

phylonco.beast.evolution.likelihood.TreeLikelihoodWithErrorSlowTest > testBinaryLikelihoodSmallNoError STANDARD_OUT
    a: 1 2
    b: 1 2
    Alignment(null)
      2 taxa
      1 site

      Using BEAGLE version: 3.2.0 (PRE-RELEASE) resource 0: CPU
        with instance flags:  PRECISION_DOUBLE COMPUTATION_SYNCH EIGEN_REAL SCALING_MANUAL SCALERS_RAW VECTOR_SSE THREADING_NONE PROCESSOR_CPU FRAMEWORK_CPU

While when build in IDE, Beagle is not used:

phylonco.beast.evolution.likelihood.TreeLikelihoodWithErrorSlowTest > testGT16ErrorLikelihoodCase1 STANDARD_OUT
    a: 1 16
    b: 1 16
    Alignment(null)
      2 taxa
      1 site

phylonco.beast.evolution.likelihood.TreeLikelihoodWithErrorSlowTest > testGT16ErrorLikelihoodCase1 STANDARD_ERROR
    Failed to load BEAGLE library: no hmsbeagle-jni in java.library.path: /usr/java/packages/lib:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
kche309 commented 2 years ago

@J-Moravec thanks for looking into this. I will be adding a fix to use the non-Beagle version by default.

The current version tries to use Beagle if it detects a Beagle on your system, but error model classes are not Beagle compatible. Starting Beast with the -java option will ensure the correct version is used, I've added a note in the readme for this step.

J-Moravec commented 2 years ago

@kche309 I think the issue is in the parent class's method initAndValidate: https://github.com/CompEvol/beast2/blob/518a0ed4178425251690365bd1379afd46719c17/src/beast/evolution/likelihood/TreeLikelihood.java#L144-L159

Beagle is initialized, even if the TreeLikelihoodWithError doesn't support it. Overriding this step could help it. Not sure how -java switch is managing to do that internally. Otherwise, exposing it (i.e., implementing some kind of switch, such as useBeagle=true set by default, with the child class) to the TreeLikelihood might be a better solution.

        beagle = null;
        beagle = new BeagleTreeLikelihood();
        try {
            beagle.initByName(
                    "data", dataInput.get(), "tree", treeInput.get(), "siteModel", siteModelInput.get(),
                    "branchRateModel", branchRateModelInput.get(), "useAmbiguities", m_useAmbiguities.get(), 
                    "useTipLikelihoods", m_useTipLikelihoods.get(),"scaling", scaling.get().toString());
            if (beagle.beagle != null) {
                //a Beagle instance was found, so we use it
                return;
            }
        } catch (Exception e) {
            // ignore
        }
        // No Beagle instance was found, so we use the good old java likelihood core
        beagle = null;
kche309 commented 2 years ago

@J-Moravec Yes, that's right. There's a system beagle flag I can set to achieve the same behaviour as the java flag. I will add this to both the TreeLikelihood error classes.

kche309 commented 2 years ago

The Beagle error message should be fixed for gradle2 by https://github.com/bioDS/beast-phylonco/commit/9416241fca73acd0b220167ee734bf64aad2328c