matsengrp / gapml

GNU General Public License v3.0
11 stars 4 forks source link

Failing unit tests #174

Closed seidels closed 4 years ago

seidels commented 4 years ago

After installation of the virtual environment and other necessary packages, 8 unit tests fail and 16 return an error.

python -m unittest ss2020-01-31 14:26:50.258873: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA 2020-01-31 14:26:50.259173: I tensorflow/core/common_runtime/process_util.cc:69] Creating new thread pool with default inter op setting: 8. Tune using inter_op_parallelism_threads for best performance. [[ 1. 0.3] [ 1. 0.1] [ 2. -1. ] [ 1. -0.2]] FssEEEEE/.../anaconda3/envs/gestaltamania/lib/python3.6/site-packages/tensorflow/python/client/session.py:1714: UserWarning: An interactive session is already active. This can cause out-of-memory errors in some cases. You must explicitly callInteractiveSession.close()` to release resources held by the other session(s). warnings.warn('An interactive session is already active. This can ' EEEEEEFFFFFFFEEEE........E..................

ERROR: test_basic (tests.test_birth_death_simulator.BirthDeathSimulatorTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_birth_death_simulator.py", line 12, in setUp death_rate=0.1) TypeError: init() got an unexpected keyword argument 'birth_rate'

====================================================================== ERROR: test_process_birth (tests.test_birth_death_simulator.BirthDeathSimulatorTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_birth_death_simulator.py", line 12, in setUp death_rate=0.1) TypeError: init() got an unexpected keyword argument 'birth_rate'

====================================================================== ERROR: test_process_death (tests.test_birth_death_simulator.BirthDeathSimulatorTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_birth_death_simulator.py", line 12, in setUp death_rate=0.1) TypeError: init() got an unexpected keyword argument 'birth_rate'

====================================================================== ERROR: test_process_end (tests.test_birth_death_simulator.BirthDeathSimulatorTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_birth_death_simulator.py", line 12, in setUp death_rate=0.1) TypeError: init() got an unexpected keyword argument 'birth_rate'

====================================================================== ERROR: tests.test_bounded_poisson (unittest.loader._FailedTest)

ImportError: Failed to import test module: tests.test_bounded_poisson Traceback (most recent call last): File ".../anaconda3/envs/gestaltamania/lib/python3.6/unittest/loader.py", line 428, in _find_test_path module = self._get_module_from_name(name) File ".../anaconda3/envs/gestaltamania/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name import(name) File ".../gestaltamania-master/gestalt/tests/test_bounded_poisson.py", line 4, in from bounded_poisson import PaddedBoundedPoisson, ZeroInflatedBoundedPoisson ModuleNotFoundError: No module named 'bounded_poisson'

====================================================================== ERROR: test_branch_likelihood (tests.test_clt_likelihood_calc.LikelihoodCalculationTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 404, in test_branch_likelihood model = self._create_bifurc_model(topology, self.bcode_metadata, branch_len) File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 65, in _create_bifurc_model tot_time = tot_time) TypeError: init() got an unexpected keyword argument 'trim_short_poissons'

====================================================================== ERROR: test_branch_likelihood_big_intertarget_del (tests.test_clt_likelihood_calc.LikelihoodCalculationTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 461, in test_branch_likelihood_big_intertarget_del double_cut_weight = double_cut_weight) File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 65, in _create_bifurc_model tot_time = tot_time) TypeError: init() got an unexpected keyword argument 'trim_short_poissons'

====================================================================== ERROR: test_branch_likelihood_no_events (tests.test_clt_likelihood_calc.LikelihoodCalculationTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 372, in test_branch_likelihood_no_events model = self._create_bifurc_model(topology, self.bcode_metadata, branch_len) File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 65, in _create_bifurc_model tot_time = tot_time) TypeError: init() got an unexpected keyword argument 'trim_short_poissons'

====================================================================== ERROR: test_multifurc_vs_bifurc (tests.test_clt_likelihood_calc.LikelihoodCalculationTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 304, in test_multifurc_vs_bifurc target_lams=target_lams) File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 65, in _create_bifurc_model tot_time = tot_time) TypeError: init() got an unexpected keyword argument 'trim_short_poissons'

====================================================================== ERROR: test_multifurcation_resolution (tests.test_clt_likelihood_calc.LikelihoodCalculationTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 142, in test_multifurcation_resolution tot_time = tot_time) File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 99, in _create_multifurc_model tot_time = tot_time) TypeError: init() got an unexpected keyword argument 'trim_short_poissons'

====================================================================== ERROR: test_two_branch_likelihood_big_intertarget_del (tests.test_clt_likelihood_calc.LikelihoodCalculationTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 531, in test_two_branch_likelihood_big_intertarget_del double_cut_weight = double_cut_weight) File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_calc.py", line 65, in _create_bifurc_model tot_time = tot_time) TypeError: init() got an unexpected keyword argument 'trim_short_poissons'

====================================================================== ERROR: test_get_intertarg_trim_probs (tests.test_clt_likelihood_trim.CLTTrimProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_trim.py", line 40, in setUp insert_zero_prob = self.insert_zero_prob) TypeError: init() got an unexpected keyword argument 'trim_short_poiss'

====================================================================== ERROR: test_get_long_trim_probs (tests.test_clt_likelihood_trim.CLTTrimProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_trim.py", line 40, in setUp insert_zero_prob = self.insert_zero_prob) TypeError: init() got an unexpected keyword argument 'trim_short_poiss'

====================================================================== ERROR: test_get_short_trim_probs_leftmost_targ (tests.test_clt_likelihood_trim.CLTTrimProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_trim.py", line 40, in setUp insert_zero_prob = self.insert_zero_prob) TypeError: init() got an unexpected keyword argument 'trim_short_poiss'

====================================================================== ERROR: test_get_short_trim_probs_rightmost_targ (tests.test_clt_likelihood_trim.CLTTrimProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_trim.py", line 40, in setUp insert_zero_prob = self.insert_zero_prob) TypeError: init() got an unexpected keyword argument 'trim_short_poiss'

====================================================================== ERROR: test_get_all_transitions (tests.test_target_status.CollapsedTreeTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_target_status.py", line 98, in test_get_all_transitions self.assertEqual(len(all_transitions.keys()), 8) AttributeError: 'tuple' object has no attribute 'keys'

====================================================================== FAIL: test_neg_beta_right_del_focal (tests.test_allele_simulator.AlleleSimulatorTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_allele_simulator.py", line 189, in test_neg_beta_right_del_focal use_poisson = False) File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 112, in init assert trim_short_params.size == self.num_trim_short_types * (1 if use_poisson else 2) AssertionError

====================================================================== FAIL: test_create_transition_matrix (tests.test_clt_likelihood_model.CLTTransitionProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_model.py", line 29, in setUp double_cut_weight = [self.double_cut_weight]) File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 112, in init assert trim_short_params.size == self.num_trim_short_types * (1 if use_poisson else 2) AssertionError

====================================================================== FAIL: test_create_transition_matrix_away_simple (tests.test_clt_likelihood_model.CLTTransitionProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_model.py", line 29, in setUp double_cut_weight = [self.double_cut_weight]) File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 112, in init assert trim_short_params.size == self.num_trim_short_types * (1 if use_poisson else 2) AssertionError

====================================================================== FAIL: test_create_transition_matrix_away_two_targs (tests.test_clt_likelihood_model.CLTTransitionProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_model.py", line 29, in setUp double_cut_weight = [self.double_cut_weight]) File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 112, in init assert trim_short_params.size == self.num_trim_short_types * (1 if use_poisson else 2) AssertionError

====================================================================== FAIL: test_create_transition_matrix_mixed (tests.test_clt_likelihood_model.CLTTransitionProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_model.py", line 29, in setUp double_cut_weight = [self.double_cut_weight]) File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 112, in init assert trim_short_params.size == self.num_trim_short_types * (1 if use_poisson else 2) AssertionError

====================================================================== FAIL: test_create_transition_matrix_with_singletonwc (tests.test_clt_likelihood_model.CLTTransitionProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_model.py", line 29, in setUp double_cut_weight = [self.double_cut_weight]) File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 112, in init assert trim_short_params.size == self.num_trim_short_types * (1 if use_poisson else 2) AssertionError

====================================================================== FAIL: test_get_hazard (tests.test_clt_likelihood_model.CLTTransitionProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_model.py", line 29, in setUp double_cut_weight = [self.double_cut_weight]) File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 112, in init assert trim_short_params.size == self.num_trim_short_types * (1 if use_poisson else 2) AssertionError

====================================================================== FAIL: test_get_hazard_away (tests.test_clt_likelihood_model.CLTTransitionProbTestCase)

Traceback (most recent call last): File ".../gestaltamania-master/gestalt/tests/test_clt_likelihood_model.py", line 29, in setUp double_cut_weight = [self.double_cut_weight]) File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 112, in init assert trim_short_params.size == self.num_trim_short_types * (1 if use_poisson else 2) AssertionError


Ran 60 tests in 0.292s

FAILED (failures=8, errors=16, skipped=5)

jjfeng commented 4 years ago

Thanks for reporting this. Yes, a number of the unit tests are outdated. I'll fixing them shortly.

You should be able to still use the package.

seidels commented 4 years ago

Thanks for the quick reply. I tried running the gestalt pipeline. The first 3 scripts worked. When calling tune_topology, I got the following error:

.../gestaltamania-master/gestalt/clt_likelihood_model.py:568: RuntimeWarning: divide by zero encountered in log
  np.log(branch_len_inners[self.known_params.branch_len_inners_unknown] if self.known_params.branch_lens else branch_len_inners),
Traceback (most recent call last):
  File ".../gestaltamania-master/gestalt/parallel_worker.py", line 40, in run
    result = self.run_worker(shared_obj)
  File ".../gestaltamania-master/gestalt/likelihood_scorer.py", line 111, in run_worker
    return self.do_work_directly(sess)
  File ".../gestaltamania-master/gestalt/likelihood_scorer.py", line 239, in do_work_directly
    fit_params)
  File ".../gestaltamania-master/gestalt/likelihood_scorer.py", line 180, in _get_best_result
    fit_params)
  File ".../gestaltamania-master/gestalt/likelihood_scorer.py", line 150, in _fit_one_init
    res_model.get_fitted_bifurcating_tree(),
  File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 1615, in get_fitted_bifurcating_tree
    assert np.isclose(tot_time, leaf.get_distance(scratch_tree))
AssertionError

2020-02-03 09:35:18.179700: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2020-02-03 09:35:18.180030: I tensorflow/core/common_runtime/process_util.cc:69] Creating new thread pool with default inter op setting: 8. Tune using inter_op_parallelism_threads for best performance.
.../gestaltamania-master/gestalt/clt_likelihood_model.py:568: RuntimeWarning: divide by zero encountered in log
  np.log(branch_len_inners[self.known_params.branch_len_inners_unknown] if self.known_params.branch_lens else branch_len_inners),
Traceback (most recent call last):
  File ".../gestaltamania-master/gestalt/parallel_worker.py", line 40, in run
    result = self.run_worker(shared_obj)
  File ".../gestaltamania-master/gestalt/likelihood_scorer.py", line 111, in run_worker
    return self.do_work_directly(sess)
  File ".../gestaltamania-master/gestalt/likelihood_scorer.py", line 239, in do_work_directly
    fit_params)
  File ".../gestaltamania-master/gestalt/likelihood_scorer.py", line 180, in _get_best_result
    fit_params)
  File ".../gestaltamania-master/gestalt/likelihood_scorer.py", line 150, in _fit_one_init
    res_model.get_fitted_bifurcating_tree(),
  File ".../gestaltamania-master/gestalt/clt_likelihood_model.py", line 1615, in get_fitted_bifurcating_tree
    assert np.isclose(tot_time, leaf.get_distance(scratch_tree))
AssertionError

Traceback (most recent call last):
  File "tune_topology.py", line 574, in <module>
    main()
  File "tune_topology.py", line 511, in main
    assessor,
  File ".../gestaltamania-master/gestalt/hanging_chad_finder.py", line 765, in tune
    assert len(worker_results) > 0
AssertionError
jjfeng commented 4 years ago

Hm, what data are you feeding into it? I just downloaded the package from scratch and ran the following with no problems:

python generate_data.py
python restrict_observed_barcodes.py
python get_parsimony_topologies.py
python tune_topology.py
seidels commented 4 years ago

These are exactly the commands I run. Seems, that the problem should then be in the setup of my environment. Do you use the packages and their versions as specified in the dockerfiles/Dockerfile ?

jjfeng commented 4 years ago

Here is a dump of my requirements.txt. It probably contains extra packages you don't actually need, but maybe it can help you pinpoint where our packages/versions differ.

absl-py==0.1.13
appdirs==1.4.3
astor==0.6.2
astroid==2.0.4
backcall==0.1.0
bayesian-optimization==0.6.0
biopython==1.72
bleach==1.5.0
boto3==1.7.70
botocore==1.10.70
Click==7.0
cycler==0.10.0
decorator==4.3.0
docutils==0.14
ete3==3.1.1
flake8==3.5.0
gast==0.2.0
GEOparse==1.1.0
grpcio==1.10.0
h5py==2.8.0
html5lib==0.9999999
ipython==6.3.1
ipython-genutils==0.2.0
isort==4.3.4
jedi==0.12.0
jmespath==0.9.3
Keras==2.2.4
Keras-Applications==1.0.6
Keras-Preprocessing==1.0.5
kiwisolver==1.0.1
lazy-object-proxy==1.3.1
line-profiler==2.1.2
Markdown==2.6.11
matplotlib==2.2.2
mccabe==0.6.1
mhcflurry==1.2.2
mhcnames==0.4.8
nestly==0.6.1
numpy==1.14.2
pandas==0.22.0
parso==0.2.0
patsy==0.5.0
pexpect==4.5.0
pickleshare==0.7.4
prompt-toolkit==1.0.15
protobuf==3.6.1
ptyprocess==0.5.2
pycodestyle==2.3.1
pyflakes==1.6.0
Pygments==2.2.0
pylint==2.1.1
pyparsing==2.2.0
python-dateutil==2.7.2
pytz==2018.3
PyYAML==3.13
s3transfer==0.1.13
scikit-learn==0.19.2
scipy==1.0.1
seaborn==0.9.0
simplegeneric==0.8.1
six==1.11.0
sklearn==0.0
statsmodels==0.9.0
tensorboard==1.12.0
tensorflow==1.12.0
tensorflow-probability==0.5.0
termcolor==1.1.0
tqdm==4.28.1
traitlets==4.3.2
typed-ast==1.1.0
typing==3.6.4
wcwidth==0.1.7
Werkzeug==0.14.1
wgetter==0.7
wrapt==1.10.11
seidels commented 4 years ago

Great, thank you! The scripts now run without throwing any errors.

Which one is the inferred tree? Is it gestalt/_output/parsimony_tree0.pkl ?

jjfeng commented 4 years ago

gestalt/_output/parsimony_tree0.pkl was the initial tree topology that tune_topology.py uses to begin the tree search at.

The actual model output is gestalt/_output/tune_topology_fitted.pkl. It is a dictionary object with final_fit, which contains the actual result (in the form of the class LikelihoodScorerResult in likelihood_scorer.py). It also contains tuning_history which stores the entire history of the tree search in case you are curious.

seidels commented 4 years ago

I see. Is there a way to export the final tree to Newick or NEXUS format?

jjfeng commented 4 years ago

Yes! Let me update the code for you in that case.

jjfeng commented 4 years ago

@so-phi -- see the newly added convert_to_newick.py. It outputs 1) a newick file with leaf labels "leaf_{ID}" and 2) a json file that maps each leaf label to the observed events on that leaf.

hope this helps!

seidels commented 4 years ago

Thank's a lot for implementing that functionality!

I checked the generate_data.py and realised, that it simulates data samples. Now, if I wanted to run the tree inference on the experimental gestalt data, would I read I have to provide the following input: obs_data_dict = { "bcode_meta": bcode_meta, "obs_leaves": obs_leaves, "time": args.time, }

Could you outline what those input variables should contain/ what data format I would have to provide?

jjfeng commented 4 years ago

To perform tree inference on the gestalt data, I recommend using read_gestalt_data.py. This script was used for all the gestalt analyses in the paper.