Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unpickling of temporal count #244

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
129 changes: 63 additions & 66 deletions execution_engine/util/cohort_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,28 +506,27 @@ def __new__(
self.interval_type = interval_type
return self

# glichtner: this should now be handled by the base class using get_instance_variables()
# def __reduce__(self) -> tuple[Callable, tuple]:
# """
# Reduce the expression to its arguments and category.
#
# Required for pickling (e.g. when using multiprocessing).
#
# :return: Tuple of the class, arguments, and category.
# """
# return (
# self._recreate,
# (
# self.args,
# {
# "category": self.category,
# "threshold": self.count_min,
# "start_time": self.start_time,
# "end_time": self.end_time,
# "interval_type": self.interval_type,
# },
# ),
# )
def __reduce__(self) -> tuple[Callable, tuple]:
"""
Reduce the expression to its arguments and category.

Required for pickling (e.g. when using multiprocessing).

:return: Tuple of the class, arguments, and category.
"""
return (
self._recreate,
(
self.args,
{
"category": self.category,
"threshold": self.count_min,
"start_time": self.start_time,
"end_time": self.end_time,
"interval_type": self.interval_type,
},
),
)

def __repr__(self) -> str:
"""
Expand Down Expand Up @@ -568,28 +567,27 @@ def __new__(
self.interval_type = interval_type
return self

# glichtner: this should now be handled by the base class using get_instance_variables()
# def __reduce__(self) -> tuple[Callable, tuple]:
# """
# Reduce the expression to its arguments and category.
#
# Required for pickling (e.g. when using multiprocessing).
#
# :return: Tuple of the class, arguments, and category.
# """
# return (
# self._recreate,
# (
# self.args,
# {
# "category": self.category,
# "threshold": self.count_max,
# "start_time": self.start_time,
# "end_time": self.end_time,
# "interval_type": self.interval_type,
# },
# ),
# )
def __reduce__(self) -> tuple[Callable, tuple]:
"""
Reduce the expression to its arguments and category.

Required for pickling (e.g. when using multiprocessing).

:return: Tuple of the class, arguments, and category.
"""
return (
self._recreate,
(
self.args,
{
"category": self.category,
"threshold": self.count_max,
"start_time": self.start_time,
"end_time": self.end_time,
"interval_type": self.interval_type,
},
),
)

def __repr__(self) -> str:
"""
Expand Down Expand Up @@ -631,28 +629,27 @@ def __new__(
self.interval_type = interval_type
return self

# glichtner: this should now be handled by the base class using get_instance_variables()
# def __reduce__(self) -> tuple[Callable, tuple]:
# """
# Reduce the expression to its arguments and category.
#
# Required for pickling (e.g. when using multiprocessing).
#
# :return: Tuple of the class, arguments, and category.
# """
# return (
# self._recreate,
# (
# self.args,
# {
# "category": self.category,
# "threshold": self.count_min,
# "start_time": self.start_time,
# "end_time": self.end_time,
# "interval_type": self.interval_type,
# },
# ),
# )
def __reduce__(self) -> tuple[Callable, tuple]:
"""
Reduce the expression to its arguments and category.

Required for pickling (e.g. when using multiprocessing).

:return: Tuple of the class, arguments, and category.
"""
return (
self._recreate,
(
self.args,
{
"category": self.category,
"threshold": self.count_min,
"start_time": self.start_time,
"end_time": self.end_time,
"interval_type": self.interval_type,
},
),
)

def __repr__(self) -> str:
"""
Expand Down
34 changes: 34 additions & 0 deletions tests/execution_engine/util/test_cohort_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from execution_engine.constants import CohortCategory
from execution_engine.omop.criterion.combination.temporal import TimeIntervalType
from execution_engine.util.cohort_logic import (
AllOrNone,
And,
Expand All @@ -19,6 +20,9 @@
Not,
Or,
Symbol,
TemporalExactCount,
TemporalMaxCount,
TemporalMinCount,
)
from tests.mocks.criterion import MockCriterion

Expand Down Expand Up @@ -224,6 +228,36 @@ class TestSymbolMultiprocessing:
NoDataPreservingAnd(1, 2, 3, category=CohortCategory.POPULATION),
NoDataPreservingOr(1, 2, 3, category=CohortCategory.POPULATION),
LeftDependentToggle(left=1, right=2, category=CohortCategory.POPULATION),
TemporalMinCount(
1,
2,
3,
threshold=2,
start_time=None,
end_time=None,
interval_type=TimeIntervalType.DAY,
category=CohortCategory.POPULATION,
),
TemporalMaxCount(
1,
2,
3,
threshold=3,
start_time=None,
end_time=None,
interval_type=TimeIntervalType.MORNING_SHIFT,
category=CohortCategory.POPULATION,
),
TemporalExactCount(
1,
2,
3,
threshold=2,
start_time=None,
end_time=None,
interval_type=TimeIntervalType.NIGHT_SHIFT,
category=CohortCategory.POPULATION,
),
],
ids=lambda expr: expr.__class__.__name__,
)
Expand Down
Loading