Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9144729
Start to analysis filters
dwhswenson May 15, 2021
61d2570
Add shooting points; misc updates to filters
dwhswenson May 17, 2021
0b8aa53
updates to analysis filters
dwhswenson Jun 9, 2021
9527d4b
Add start to tests
dwhswenson Jun 17, 2021
3ce4a88
cleanup of STAGES; several new filters
dwhswenson Jul 5, 2021
b91cb2e
snake_case
dwhswenson Jul 5, 2021
766d81f
add canonical_movers extractor; cleanup
dwhswenson Jul 6, 2021
d17a04a
Add start to docs on extractors and filters
dwhswenson Jul 6, 2021
8ab5a21
get rid of f-strings
dwhswenson Jul 6, 2021
31df2f2
outline tests we need to do
dwhswenson Aug 9, 2021
0ef0885
Merge branch 'master' of github.com:openpathsampling/openpathsampling…
dwhswenson Aug 14, 2021
68ab949
start on test fixtures
dwhswenson Aug 18, 2021
a9456ea
Merge remote-tracking branch 'upstream/master' into analysis_filters
dwhswenson Sep 9, 2021
9a3cb08
split off testing structure (separate PR)
dwhswenson Sep 9, 2021
d8bd07e
Merge branch 'test-analysis-utils' into tmp_test_analysis_filters
dwhswenson Sep 12, 2021
376b876
tests for step filter
dwhswenson Sep 12, 2021
4108ecd
steps toward testing
dwhswenson Sep 19, 2021
6ecd22b
Merge branch 'master' of github.com:openpathsampling/openpathsampling…
dwhswenson Dec 13, 2021
cefb597
Merge branch 'tmp_test_analysis_filters' into analysis_filters
dwhswenson Dec 13, 2021
0fca990
update test_filters for better analysis test utils
dwhswenson Dec 13, 2021
298f73b
fix Py2, more tests
dwhswenson Dec 13, 2021
ec7cb4b
tests for bad input to canonical_mover
dwhswenson Dec 14, 2021
8aaa92a
test_extractor
dwhswenson Jan 14, 2022
96495a3
Merge remote-tracking branch 'upstream/master' into analysis_filters
dwhswenson Mar 25, 2022
20d12f8
steps toward better docs
dwhswenson May 20, 2022
80bffc4
starting on tests for shooting analysis
dwhswenson Jul 30, 2022
a6c9cf5
Parts of testing for filters
dwhswenson Oct 16, 2022
a31b017
steps toward tests
dwhswenson Dec 26, 2022
a2bd212
Merge remote-tracking branch 'upstream/master' into analysis_filters
dwhswenson Dec 26, 2022
999bea2
Merge remote-tracking branch 'upstream/master' into analysis_filters
dwhswenson Dec 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
steps toward testing
  • Loading branch information
dwhswenson committed Sep 19, 2021
commit 4108ecd180a735d31f0fa2871a8e4bb98a8bf6a5
59 changes: 2 additions & 57 deletions openpathsampling/analysis/filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import openpathsampling as paths
import enum

def _default_repr(obj):
def _default_repr(obj): # pragma: no cover
return obj.name if obj.name is not None \
else super(obj.__class__, obj).__repr__()

Expand Down Expand Up @@ -41,7 +41,7 @@ def __init__(self, filt):
self.filter = filt

def condition(self, inp):
return not self.filter(inp)
return not self.filter.condition(inp)

def __repr__(self):
return "~" + repr(self.filter)
Expand Down Expand Up @@ -283,61 +283,6 @@ def __call__(self, steps, flatten=None):
for result in finalized:
yield result

# For the time being, leaving all this combination-related code commented
# out. It's enough typing to keep it around in case we decide we want it,
# but I have the feeling right now that it would be overly complicated from
# a user standpoint.
#
# def __and__(self, other):
# return _AndExtractorFilter(self, other)
#
# def __or__(self, other):
# return _OrExtractorFilter(self, other)
#
# def __invert__(self):
# return _NegationExtractorFilter(self)
#
# def _test_compatibility(self, other):
# value_err_str = ("Can not combine ExtractorFilters that do not "
# "have the same {attr}: {self_attr} != "
# "{other_attr}")
# if self.extractor != other.extractor:
# raise ValueError(value_err_str.format(
# attr='extractor',
# self_attr=self.extractor,
# other_attr=other.extractor
# ))
# if self.secondary_filter != other.secondary_filter:
# raise ValueError(value_err_str.format(
# attr='secondary filter',
# self_attr=self.secondary_filter,
# other_attr=other.secondary_filter
# ))
#
#class _AndExtractorFilter(ExtractorFilter):
# def __init__(self, ef1, ef2):
# ef1._test_compatibility(ef2)
# step_filter = ef1.step_filter & ef2.step_filter
# self._default_secondary = ef1._default_secondary
# super(_AndExtractorFilter, self).__init__(step_filter,
# ef1.extractor)
#
#class _OrExtractorFilter(ExtractorFilter):
# def __init__(self, ef1, ef2):
# ef1._test_compatibility(ef2)
# step_filter = ef1.step_filter | ef2.step_filter
# self._default_secondary = ef1._default_secondary
# super(_OrExtractorFilter, self).__init__(step_filter,
# ef1.extractor)
#
#class _NegationExtractorFilter(ExtractorFilter):
# def __init__(self, ef):
# self._default_secondary = ef._default_secondary
# super(_NegationExtractorFilter, self).__init__(~ef.step_filter,
# ef.extractor)
# self.with_filter(ef.secondary_filter)


class SampleExtractorFilter(ExtractorFilter):
_default_secondary = all_samples

Expand Down
83 changes: 68 additions & 15 deletions openpathsampling/tests/analysis/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,62 @@ def seven_steps_no_dynamics(scheme):
]
return run_moves(init_conds, moves)

@pytest.fixture
def seven_steps_trial_samples(seven_steps_no_dynamics):
return sum([step.change.canonical.trials
for step in seven_steps_no_dynamics], [])

### TESTS ##################################################################

##### generic filter logic #################################################

class StringFilter(GenericFilter):
FILTER_TYPE = str

@pytest.fixture
def strings():
return ['foo', 'bar', 'baz', 'qux', 'quux']

def test_filter_condition(strings):
has_a = StringFilter(condition=lambda s: 'a' in s, name='has_a')
assert list(has_a(strings)) == ['bar', 'baz']

def test_or_filter_condition(strings):
has_a = StringFilter(condition=lambda s: 'a' in s, name='has_a')
len_4 = StringFilter(condition=lambda s: len(s) == 4, name='len_4')
filt = has_a | len_4
assert list(filt(strings)) == ['bar', 'baz', 'quux']

def test_and_filter_condition(strings):
has_q = StringFilter(condition=lambda s: 'q' in s, name='has_q')
len_4 = StringFilter(condition=lambda s: len(s) == 4, name='len_4')
filt = has_q & len_4
assert list(filt(strings)) == ['quux']

def test_invert_filter_condition(strings):
has_q = StringFilter(condition=lambda s: 'q' in s, name='has_q')
filt = ~has_q
assert list(filt(strings)) == ['foo', 'bar', 'baz']

def test_sub_filter_condition(strings):
len_3 = StringFilter(condition=lambda s: len(s) == 3, name='len_3')
has_b = StringFilter(condition=lambda s: 'b' in s, name='has_b')
filt = len_3 - has_b
assert list(filt(strings)) == ['foo', 'qux']

def test_xor_filter_condition(strings):
len_3 = StringFilter(condition=lambda s: len(s) == 3, name='len_3')
has_q = StringFilter(condition=lambda s: 'q' in s, name='has_q')
filt = len_3 ^ has_q
assert list(filt(strings)) == ['foo', 'bar', 'baz', 'quux']


def test_extractor(strings):
pytest.skip()

def test_extractor_using(strings):
pytest.skip()

##### step filters #########################################################

@pytest.mark.parametrize('input_type', ['mover', 'class_name', 'class'])
Expand Down Expand Up @@ -82,43 +136,42 @@ def test_all_steps_filter(seven_steps_no_dynamics):
assert len(filtered_steps) == 7
assert [s.mccycle for s in filtered_steps] == list(range(7))


##### sample filters #######################################################

def test_all_samples_filter():
def test_all_samples_filter(seven_steps_trial_samples):
pytest.skip()

def test_ensemble_sample_filter():
pass
def test_ensemble_sample_filter(scheme, seven_steps_trial_samples):
pytest.skip()

def test_replica_sample_filter():
pass
def test_replica_sample_filter(seven_steps_trial_samples):
pytest.skip()

def test_minus_ensemble_sample_filter():
pass
pytest.skip()

def test_ms_outer_ensemble_sample_filter():
pass
pytest.skip()

def test_sampling_ensemble_sample_filter():
pass
pytest.skip()

##### extractors ###########################################################

def test_active_samples_extractor():
pass
pytest.skip()

def test_trial_samples_extractor():
pass
pytest.skip()

def test_shooting_steps_filter():
pass
pytest.skip()

def test_shooting_points_extractor():
pass
pytest.skip()

def test_modified_shooting_points_extractor():
pass
pytest.skip()

def test_canonical_movers_extractor():
pass
pytest.skip()