Skip to content

Commit

Permalink
unmerged changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hussain-jafari committed Nov 13, 2024
1 parent a889790 commit 02d12be
Show file tree
Hide file tree
Showing 55 changed files with 205 additions and 289 deletions.
4 changes: 2 additions & 2 deletions docs/source/concepts/results.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ to the existing number of people who have died from previous time steps.

.. testcode::

from typing import Any, Optional
from typing import Any

import pandas as pd

Expand All @@ -84,7 +84,7 @@ to the existing number of people who have died from previous time steps.
}

@property
def columns_required(self) -> Optional[list[str]]:
def columns_required(self) -> list[str] | None:
return ["age", "alive"]

def register_observations(self, builder: Builder) -> None:
Expand Down
36 changes: 16 additions & 20 deletions src/vivarium/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
simulations.
"""
from __future__ import annotations

import re
import warnings
from abc import ABC
from collections.abc import Sequence
from collections.abc import Callable, Sequence
from datetime import datetime, timedelta
from importlib import import_module
from inspect import signature
from numbers import Number
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Any

import pandas as pd
from layered_config_tree import ConfigurationError, LayeredConfigTree
Expand Down Expand Up @@ -88,7 +86,7 @@ class Component(ABC):
"""

CONFIGURATION_DEFAULTS: Dict[str, Any] = {}
CONFIGURATION_DEFAULTS: dict[str, Any] = {}
"""A dictionary containing the defaults for any configurations managed by this
component. An empty dictionary indicates no managed configurations.
"""
Expand Down Expand Up @@ -188,7 +186,7 @@ def population_view(self) -> PopulationView:
return self._population_view

@property
def sub_components(self) -> List["Component"]:
def sub_components(self) -> list["Component"]:
"""Provide components managed by this component.
Returns
Expand All @@ -199,7 +197,7 @@ def sub_components(self) -> List["Component"]:
return self._sub_components

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
"""Provides a dictionary containing the defaults for any configurations
managed by this component.
Expand All @@ -214,7 +212,7 @@ def configuration_defaults(self) -> Dict[str, Any]:
return self.CONFIGURATION_DEFAULTS

@property
def columns_created(self) -> List[str]:
def columns_created(self) -> list[str]:
"""Provides names of columns created by the component.
Returns
Expand All @@ -225,7 +223,7 @@ def columns_created(self) -> List[str]:
return []

@property
def columns_required(self) -> Optional[List[str]]:
def columns_required(self) -> list[str] | None:
"""Provides names of columns required by the component.
Returns
Expand All @@ -245,7 +243,7 @@ def initialization_requirements(
return []

@property
def population_view_query(self) -> Optional[str]:
def population_view_query(self) -> str | None:
"""Provides a query to use when filtering the component's `PopulationView`.
Returns
Expand Down Expand Up @@ -335,14 +333,12 @@ def __init__(self) -> None:
"""
self._repr: str = ""
self._name: str = ""
self._sub_components: List["Component"] = []
self.logger: Optional[Logger] = None
self.get_value_columns: Optional[
Callable[[Union[str, pd.DataFrame]], List[str]]
] = None
self.configuration: Optional[LayeredConfigTree] = None
self._population_view: Optional[PopulationView] = None
self.lookup_tables: Dict[str, LookupTable] = {}
self._sub_components: list["Component"] = []
self.logger: Logger | None = None
self.get_value_columns: Callable[[str | pd.DataFrame], list[str]] | None = None
self.configuration: LayeredConfigTree | None = None
self._population_view: PopulationView | None = None
self.lookup_tables: dict[str, LookupTable] = {}

def setup_component(self, builder: "Builder") -> None:
"""Sets up the component for a Vivarium simulation.
Expand Down Expand Up @@ -502,7 +498,7 @@ def on_simulation_end(self, event: Event) -> None:
# Helper methods #
##################

def get_initialization_parameters(self) -> Dict[str, Any]:
def get_initialization_parameters(self) -> dict[str, Any]:
"""Retrieves the values of all parameters specified in the `__init__` that
have an attribute with the same name.
Expand All @@ -522,7 +518,7 @@ def get_initialization_parameters(self) -> Dict[str, Any]:
if hasattr(self, parameter_name)
}

def get_configuration(self, builder: "Builder") -> Optional[LayeredConfigTree]:
def get_configuration(self, builder: "Builder") -> LayeredConfigTree | None:
"""Retrieves the configuration for this component from the builder.
This method retrieves the configuration for this component from the
Expand Down
4 changes: 2 additions & 2 deletions src/vivarium/examples/boids/forces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mypy: ignore-errors
from abc import ABC, abstractmethod
from typing import Any, Dict
from typing import Any

import numpy as np
import pandas as pd
Expand All @@ -14,7 +14,7 @@ class Force(Component, ABC):
# Properties #
##############
@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
return {
self.__class__.__name__.lower(): {
"max_force": 0.03,
Expand Down
2 changes: 0 additions & 2 deletions src/vivarium/examples/disease_model/disease.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# mypy: ignore-errors
from __future__ import annotations

import pandas as pd

from vivarium import Component
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/examples/disease_model/intervention.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: ignore-errors
from typing import Any, Dict
from typing import Any

import pandas as pd

Expand All @@ -8,7 +8,7 @@


class TreatmentIntervention(Component):
CONFIGURATION_DEFAULTS: Dict[str, Any] = {
CONFIGURATION_DEFAULTS: dict[str, Any] = {
"intervention": {
"effect_size": 0.5,
}
Expand All @@ -19,7 +19,7 @@ class TreatmentIntervention(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
return {self.intervention: self.CONFIGURATION_DEFAULTS["intervention"]}

#####################
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/examples/disease_model/mortality.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: ignore-errors
from typing import Any, Dict, List, Optional
from typing import Any

import numpy as np
import pandas as pd
Expand All @@ -15,7 +15,7 @@ class Mortality(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
"""A set of default configuration values for this component.
These can be overwritten in the simulation model specification or by
Expand All @@ -28,7 +28,7 @@ def configuration_defaults(self) -> Dict[str, Any]:
}

@property
def columns_required(self) -> Optional[List[str]]:
def columns_required(self) -> list[str] | None:
return ["tracked", "alive"]

#####################
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/examples/disease_model/observer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any

import pandas as pd

Expand All @@ -14,7 +14,7 @@ class DeathsObserver(Observer):
##############

@property
def columns_required(self) -> Optional[list[str]]:
def columns_required(self) -> list[str] | None:
return ["alive"]

#################
Expand All @@ -39,7 +39,7 @@ class YllsObserver(Observer):
##############

@property
def columns_required(self) -> Optional[list[str]]:
def columns_required(self) -> list[str] | None:
return ["age", "alive"]

@property
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/examples/disease_model/population.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: ignore-errors
from typing import Any, Dict, List
from typing import Any

import pandas as pd

Expand All @@ -17,7 +17,7 @@ class BasePopulation(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
"""A set of default configuration values for this component.
These can be overwritten in the simulation model specification or by
Expand All @@ -33,7 +33,7 @@ def configuration_defaults(self) -> Dict[str, Any]:
}

@property
def columns_created(self) -> List[str]:
def columns_created(self) -> list[str]:
return ["age", "sex", "alive", "entrance_time"]

#####################
Expand Down
10 changes: 4 additions & 6 deletions src/vivarium/examples/disease_model/risk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# mypy: ignore-errors
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List
from typing import TYPE_CHECKING, Any

import pandas as pd

Expand All @@ -25,11 +23,11 @@ class Risk(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
return {self.risk: self.CONFIGURATION_DEFAULTS["risk"]}

@property
def columns_created(self) -> List[str]:
def columns_created(self) -> list[str]:
return [self.propensity_column]

@property
Expand Down Expand Up @@ -92,7 +90,7 @@ class RiskEffect(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
return {self.risk: self.CONFIGURATION_DEFAULTS["risk_effect"]}

#####################
Expand Down
2 changes: 0 additions & 2 deletions src/vivarium/framework/artifact/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
archive file for convenient access and inspection.
"""
from __future__ import annotations

import re
import warnings
from collections import defaultdict
Expand Down
Loading

0 comments on commit 02d12be

Please sign in to comment.