Skip to content

Commit 4fa9815

Browse files
authored
Albrja/mic-5621/observer-get-configuration (#523)
Albrja/mic-5621/observer-get-configuration Overrides get_configuration in observers to use super class method - *Category*: Feature - *JIRA issue*: https://jira.ihme.washington.edu/browse/MIC-5621 Changes and notes -override get_configuration for observer classes -DOES NOT update method for disease and risk observers due to their configuration via self.cause and self.risk and not the observer component name ### Testing <!-- Details on how code was verified, any unit tests local for the repo, regression testing, etc. At a minimum, this should include an integration test for a framework change. Consider: plots, images, (small) csv file. -->
1 parent a0524d8 commit 4fa9815

File tree

7 files changed

+10
-83
lines changed

7 files changed

+10
-83
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**4.1.1 - 05/23/25**
2+
3+
- Feature: Update Observer to use super class get_configuration method
4+
15
**4.1.0 - 05/20/25**
26

37
- Feature: Update RateTransition to have configuration key for rate conversion type

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
long_description = f.read()
4343

4444
install_requirements = [
45-
"vivarium>=3.4.0",
45+
"vivarium>=3.4.3",
4646
"layered_config_tree>=1.0.1",
4747
"loguru",
4848
"numpy<2.0.0",

src/vivarium_public_health/results/disability.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DisabilityObserver(PublicHealthObserver):
3434
.. code-block:: yaml
3535
3636
configuration:
37-
observers:
37+
stratification:
3838
disability:
3939
exclude:
4040
- "sex"
@@ -128,20 +128,6 @@ def set_causes_of_disability(self, builder: Builder) -> None:
128128
cause for cause in causes_of_disability if cause.state_id not in excluded_causes
129129
]
130130

131-
def get_configuration(self, builder: Builder) -> LayeredConfigTree:
132-
"""Get the stratification configuration for this observer.
133-
134-
Parameters
135-
----------
136-
builder
137-
The builder object for the simulation.
138-
139-
Returns
140-
-------
141-
The stratification configuration for this observer.
142-
"""
143-
return builder.configuration.stratification.disability
144-
145131
def register_observations(self, builder: Builder) -> None:
146132
"""Register an observation for years lived with disability."""
147133
cause_pipelines = [

src/vivarium_public_health/results/disease.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,6 @@ class DiseaseObserver(PublicHealthObserver):
6666
# Properties #
6767
##############
6868

69-
@property
70-
def configuration_defaults(self) -> dict[str, Any]:
71-
"""A dictionary containing the defaults for any configurations managed by
72-
this component.
73-
"""
74-
return {
75-
"stratification": {
76-
self.disease: super().configuration_defaults["stratification"][
77-
self.get_configuration_name()
78-
]
79-
}
80-
}
81-
8269
@property
8370
def columns_created(self) -> list[str]:
8471
"""Columns created by this observer."""
@@ -122,19 +109,8 @@ def setup(self, builder: Builder) -> None:
122109
self.entity = self.disease_model.cause
123110
self.transition_stratification_name = f"transition_{self.disease}"
124111

125-
def get_configuration(self, builder: Builder) -> LayeredConfigTree:
126-
"""Get the stratification configuration for this observer.
127-
128-
Parameters
129-
----------
130-
builder
131-
The builder object for the simulation.
132-
133-
Returns
134-
-------
135-
The stratification configuration for this observer.
136-
"""
137-
return builder.configuration.stratification[self.disease]
112+
def get_configuration_name(self) -> str:
113+
return self.disease
138114

139115
def register_observations(self, builder: Builder) -> None:
140116
"""Register stratifications and observations.

src/vivarium_public_health/results/mortality.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,6 @@ def set_causes_of_death(self, builder: Builder) -> None:
136136
SimpleCause("other_causes", "other_causes", "cause"),
137137
]
138138

139-
def get_configuration(self, builder: Builder) -> LayeredConfigTree:
140-
"""Get the stratification configuration for this observer.
141-
142-
Parameters
143-
----------
144-
builder
145-
The builder object for the simulation.
146-
147-
Returns
148-
-------
149-
The stratification configuration for this observer.
150-
"""
151-
return builder.configuration.stratification[self.get_configuration_name()]
152-
153139
def register_observations(self, builder: Builder) -> None:
154140
"""Register stratifications and observations.
155141

src/vivarium_public_health/results/risk.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,6 @@ class CategoricalRiskObserver(PublicHealthObserver):
5858
# Properties #
5959
##############
6060

61-
@property
62-
def configuration_defaults(self) -> dict[str, Any]:
63-
"""A dictionary containing the defaults for any configurations managed by
64-
this component.
65-
"""
66-
return {
67-
"stratification": {
68-
f"{self.risk}": super().configuration_defaults["stratification"][
69-
self.get_configuration_name()
70-
]
71-
}
72-
}
73-
7461
@property
7562
def columns_required(self) -> list[str] | None:
7663
"""The columns required by this observer."""
@@ -101,19 +88,8 @@ def setup(self, builder: Builder) -> None:
10188
self.step_size = builder.time.step_size()
10289
self.categories = builder.data.load(f"risk_factor.{self.risk}.categories")
10390

104-
def get_configuration(self, builder: Builder) -> LayeredConfigTree:
105-
"""Get the stratification configuration for this observer.
106-
107-
Parameters
108-
----------
109-
builder
110-
The builder object for the simulation.
111-
112-
Returns
113-
-------
114-
The stratification configuration for this observer.
115-
"""
116-
return builder.configuration.stratification[self.risk]
91+
def get_configuration_name(self) -> str:
92+
return self.risk
11793

11894
def register_observations(self, builder: Builder) -> None:
11995
"""Register a stratification and observation.

tests/results/test_disability_observer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def test_disability_observer_setup(mocker):
3939
observer = DisabilityObserver_()
4040
builder = mocker.Mock()
4141
mocker.patch("vivarium.component.Component.build_all_lookup_tables")
42-
mocker.patch("vivarium.component.Component.get_configuration")
4342
builder.results.register_adding_observation = mocker.Mock()
4443
builder.configuration.time.step_size = 28
4544
builder.configuration.output_data.results_directory = "some/results/directory"

0 commit comments

Comments
 (0)