UT-Covid / episimlab

Framework for development of epidemiological models
https://ut-covid.github.io/episimlab/
BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

WIP: add `partition.py` #9

Closed kellypierce closed 3 years ago

kellypierce commented 3 years ago

There are a couple of redundant methods and testing bugs to sort out; opening a PR to facilitate review and resolution of those issues.

This PR adds module partition.py, which contains class Partitioning as an updated implementation of probabilistic contact partitioning for a single time point given travel and contact rate data.

There is some duplication between methods in this class and methods in SetupPhiWithPartitioning in from_travel.py that should be resolved during review. Method SetupPhiWithPartitioning._partition_contacts() and SetupPhiWithPartitioning._contact_matrix() are redundant with methods of the corresponding names in Partitioning. Code review should resolve the organization that makes the most sense.

Methods in Partitioning were tested with the addition of class TestPartitioning to test_partition.py. These tests cover legacy test cases and add one new test case (index 8) with a more complicated contact structure. Relevant tests passed at commit c587223 but are broken after merging main into this branch.

kellypierce commented 3 years ago

Checks pass here, but locally I have an error collecting tests:

ERROR collecting tests/test_partition.py 
ImportError while importing test module '/Users/kpierce/episimlab/tests/test_partition.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
esl-venv/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_partition.py:12: in <module>
    from episimlab.partition import toy, from_travel, partition
episimlab/partition/toy.py:12: in <module>
    from ..utils import get_var_dims, get_int_per_day
episimlab/utils/__init__.py:1: in <module>
    from .discrete_time_approx import *
episimlab/utils/discrete_time_approx.py:2: in <module>
    from ..cy_utils.cy_utils import discrete_time_approx_wrapper as cy_dta
E   ModuleNotFoundError: No module named 'episimlab.cy_utils.cy_utils'

... could be a local environment problem; but noting in case this is not covered by the tox checks and needs some attention.

ethho commented 3 years ago

E ModuleNotFoundError: No module named 'episimlab.cy_utils.cy_utils'



... could be a local environment problem; but noting in case this is not covered by the tox checks and needs some attention.

2 is suspect, where module was moved via git mv -r src/episimlab .. Re-building Cython modules should fix this locally:

python setup.py build_ext --inplace

Might need to specify a C compiler with -fopenmp support, e.g. if below error is raised:

# clang: error: unsupported option '-fopenmp'

# Set env to compiler that supports this flag
CC='gcc-11' python setup.py build_ext --inplace

Similarly, running tests with tox should always pass:

C='gcc-10' tox