From d10ec305e1b454964fa395cb5d965f19f0a39d82 Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Wed, 7 Oct 2020 15:59:52 +0200 Subject: [PATCH 1/7] quick fix for zero division error --- strax/chunk.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/strax/chunk.py b/strax/chunk.py index 773880f8e..2c9aa59db 100644 --- a/strax/chunk.py +++ b/strax/chunk.py @@ -111,7 +111,12 @@ def duration(self): return self.end - self.start def _mbs(self): - return (self.nbytes / 1e6) / (self.duration / 1e9) + if self.duration: + return (self.nbytes / 1e6) / (self.duration / 1e9) + else: + # This is strange. We have a zero duration chunk. However, this is + # not the right place to raise an error message. + return -1 def split(self, t: ty.Union[int, None], From 58caeaa9077e14d8c87331abb35ba00f51f13e6a Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Wed, 7 Oct 2020 16:15:40 +0200 Subject: [PATCH 2/7] patch zerodivision-error --- strax/chunk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strax/chunk.py b/strax/chunk.py index 2c9aa59db..880f75a06 100644 --- a/strax/chunk.py +++ b/strax/chunk.py @@ -115,7 +115,7 @@ def _mbs(self): return (self.nbytes / 1e6) / (self.duration / 1e9) else: # This is strange. We have a zero duration chunk. However, this is - # not the right place to raise an error message. + # not the right place to raise an error message. Return -1 for now. return -1 def split(self, From 629f79e30a59f78b6e0c34c93f3efa3baa0dd92b Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Wed, 7 Oct 2020 16:23:08 +0200 Subject: [PATCH 3/7] whats up with travis --- strax/chunk.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/strax/chunk.py b/strax/chunk.py index 880f75a06..9e78f5037 100644 --- a/strax/chunk.py +++ b/strax/chunk.py @@ -111,12 +111,12 @@ def duration(self): return self.end - self.start def _mbs(self): - if self.duration: - return (self.nbytes / 1e6) / (self.duration / 1e9) - else: - # This is strange. We have a zero duration chunk. However, this is - # not the right place to raise an error message. Return -1 for now. - return -1 + # if self.duration: + return (self.nbytes / 1e6) / (self.duration / 1e9) + # else: + # # This is strange. We have a zero duration chunk. However, this is + # # not the right place to raise an error message. Return -1 for now. + # return -1 def split(self, t: ty.Union[int, None], From b1bf1e232ed4031525305cf1b7aa615d18940c4c Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Wed, 7 Oct 2020 17:56:53 +0200 Subject: [PATCH 4/7] print more info on Travis --- strax/chunk.py | 12 ++++++------ tests/test_mailbox.py | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/strax/chunk.py b/strax/chunk.py index 9e78f5037..880f75a06 100644 --- a/strax/chunk.py +++ b/strax/chunk.py @@ -111,12 +111,12 @@ def duration(self): return self.end - self.start def _mbs(self): - # if self.duration: - return (self.nbytes / 1e6) / (self.duration / 1e9) - # else: - # # This is strange. We have a zero duration chunk. However, this is - # # not the right place to raise an error message. Return -1 for now. - # return -1 + if self.duration: + return (self.nbytes / 1e6) / (self.duration / 1e9) + else: + # This is strange. We have a zero duration chunk. However, this is + # not the right place to raise an error message. Return -1 for now. + return -1 def split(self, t: ty.Union[int, None], diff --git a/tests/test_mailbox.py b/tests/test_mailbox.py index 331d7dffb..942c527a1 100644 --- a/tests/test_mailbox.py +++ b/tests/test_mailbox.py @@ -78,7 +78,10 @@ def test_reader(source): assert hasattr(test_reader, 'got') assert test_reader.got == list(range(10)) mb.cleanup() - assert len(threading.enumerate()) == 1, "Not all threads died" + threads = [f'{t.name} is dead: {True^t.is_alive()}' + for t in threading.enumerate()] + assert len(threads) == 1, (f"Not all threads died. \n Threads running" + f" are:{threads}") def test_result_timeout(): From 76bd98ca4c7075afa6d5ea19e419f8857fd280d1 Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Wed, 7 Oct 2020 18:16:28 +0200 Subject: [PATCH 5/7] add start count of number of threads in mailbox test --- tests/test_mailbox.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_mailbox.py b/tests/test_mailbox.py index 942c527a1..efd6058fe 100644 --- a/tests/test_mailbox.py +++ b/tests/test_mailbox.py @@ -62,6 +62,7 @@ def mailbox_tester(messages, def test_highlevel(): """Test highlevel mailbox API""" for lazy in [False, True]: + n_threads_start = len(threading.enumerate()) print(f"Lazy mode: {lazy}") mb = strax.Mailbox(lazy=lazy) @@ -80,8 +81,8 @@ def test_reader(source): mb.cleanup() threads = [f'{t.name} is dead: {True^t.is_alive()}' for t in threading.enumerate()] - assert len(threads) == 1, (f"Not all threads died. \n Threads running" - f" are:{threads}") + assert len(threads) == n_threads_start, ( + f"Not all threads died. \n Threads running are:{threads}") def test_result_timeout(): From dbc4bec3a2d1a9626b18f26d0c7c401c8ed25b08 Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Wed, 7 Oct 2020 20:17:48 +0200 Subject: [PATCH 6/7] add example and relax conditional entropy test --- tests/test_hitlet.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_hitlet.py b/tests/test_hitlet.py index 107376e23..067ff7f2a 100644 --- a/tests/test_hitlet.py +++ b/tests/test_hitlet.py @@ -2,7 +2,7 @@ import numpy as np import strax -from hypothesis import given, settings +from hypothesis import given, settings, example import hypothesis.extra.numpy as hnp import hypothesis.strategies as st from strax.testutils import fake_hits @@ -279,6 +279,12 @@ def test_hitlet_properties(hits_n_data): size_template_and_ind_max_template=st.lists(elements=st.integers(min_value=0, max_value=10), min_size=2, max_size=2).filter(lambda x: x[0] != x[1])) @settings(deadline=None) +# Example that failed once +@example( + data=np.array([7.9956017, 6.6565537, -7.7413940, -2.8149414, -2.8149414, + 9.9609370, -2.8149414, -2.8149414, -2.8149414, -2.8149414], + dtype=np.float32), + size_template_and_ind_max_template=[0, 1]) def test_conditional_entropy(data, size_template_and_ind_max_template): """ Test for conditional entropy. For the template larger int value defines @@ -305,7 +311,7 @@ def test_conditional_entropy(data, size_template_and_ind_max_template): template = template / np.sum(template) e2 = - np.sum(d[m] * np.log(d[m] / template)) - assert math.isclose(e1, e2, rel_tol=10**-4, abs_tol=10**-4), f"Test 1.: Entropy function: {e1}, entropy test: {e2}" + assert math.isclose(e1, e2, rel_tol=2*10**-4, abs_tol=10**-3), f"Test 1.: Entropy function: {e1}, entropy test: {e2}" # Test 2.: Arbitrary template: template = np.ones(size_template, dtype=np.float32) @@ -317,7 +323,7 @@ def test_conditional_entropy(data, size_template_and_ind_max_template): e2 = _align_compute_entropy(d, template) e1 = strax.conditional_entropy(hitlet, template)[0] - assert math.isclose(e1, e2, rel_tol=10**-4, abs_tol=10**-4), f"Test 2.: Entropy function: {e1}, entropy test: {e2}" + assert math.isclose(e1, e2, rel_tol=2*10**-4, abs_tol=5*10**-3), f"Test 2.: Entropy function: {e1}, entropy test: {e2}" # Test 3.: Squared waveform: # Same as before but this time we square the template and the From 0a58b5ebecd04dfd38c2274c650f35bd4858b5ea Mon Sep 17 00:00:00 2001 From: Joran Angevaare Date: Wed, 7 Oct 2020 20:48:30 +0200 Subject: [PATCH 7/7] only raise rel_tol --- tests/test_hitlet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_hitlet.py b/tests/test_hitlet.py index 067ff7f2a..3e657845f 100644 --- a/tests/test_hitlet.py +++ b/tests/test_hitlet.py @@ -311,7 +311,7 @@ def test_conditional_entropy(data, size_template_and_ind_max_template): template = template / np.sum(template) e2 = - np.sum(d[m] * np.log(d[m] / template)) - assert math.isclose(e1, e2, rel_tol=2*10**-4, abs_tol=10**-3), f"Test 1.: Entropy function: {e1}, entropy test: {e2}" + assert math.isclose(e1, e2, rel_tol=2*10**-4, abs_tol=10**-4), f"Test 1.: Entropy function: {e1}, entropy test: {e2}" # Test 2.: Arbitrary template: template = np.ones(size_template, dtype=np.float32) @@ -323,7 +323,7 @@ def test_conditional_entropy(data, size_template_and_ind_max_template): e2 = _align_compute_entropy(d, template) e1 = strax.conditional_entropy(hitlet, template)[0] - assert math.isclose(e1, e2, rel_tol=2*10**-4, abs_tol=5*10**-3), f"Test 2.: Entropy function: {e1}, entropy test: {e2}" + assert math.isclose(e1, e2, rel_tol=2*10**-4, abs_tol=10**-4), f"Test 2.: Entropy function: {e1}, entropy test: {e2}" # Test 3.: Squared waveform: # Same as before but this time we square the template and the