Skip to content

Commit

Permalink
Merge pull request #237 from pph-collective/develop
Browse files Browse the repository at this point in the history
v3.2.1
  • Loading branch information
s-bessey authored Jul 10, 2023
2 parents c821bc5 + 7ab6425 commit 21e0681
Show file tree
Hide file tree
Showing 19 changed files with 13,693 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8

- name: Set up Poetry
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ results/*/*.txt

profile.prof
site/

.DS_Store
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "titan-model"
version = "3.2.1"
version = "3.3.0"
description = "TITAN Agent Based Model"
license = "GPL-3.0-only"
authors = ["Sam Bessey <[email protected]>", "Mary McGrath <[email protected]>"]
Expand All @@ -12,11 +12,11 @@ classifiers = ["Operating System :: OS Independent"]
packages = [{ include = "titan" }]

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.6"
paraml= "^0.1"
networkx = "^2.4"
nanoid = "^2.0"
numpy = "^1.23"
numpy = "^1.18"
black = {version = "^23.1.0", optional = true}
flake8 = {version = "^3.8", optional = true}
mypy = {version = "^1.0.0", optional = true}
Expand Down
37 changes: 36 additions & 1 deletion tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ def test_agent_pop_stable_setting(tmpdir):
os.path.dirname(os.path.abspath(__file__)), "..", "titan", "settings"
)
):
if "__" not in item and item != "base":
if (
"__" not in item and item != "base" and item != "philly-gis"
): # bypass philly due to constraints
path = tmpdir.mkdir(item)
os.mkdir(os.path.join(path, "network"))
print(f"-----------Starting run for {item}-----------")
Expand Down Expand Up @@ -411,6 +413,39 @@ def test_static_network(make_model_integration, tmpdir):
assert rel in curr_rel_ids


@pytest.mark.integration_deterministic
def test_dissolution(params_integration, tmpdir):
model = TITAN(params_integration)
inj_r = 0
for rel in model.pop.relationships:
inj_r += 1
assert inj_r > 0
model.time = 1

model.params.partnership.dissolve.time = 1
model.params.partnership.dissolve.enabled = True

model.params.demographics.white.sex_type.MSM.drug_type.Inj.num_partners = (
model.params.demographics.black.sex_type.MSM.drug_type.Inj.num_partners
)
for agent in model.pop.all_agents:
agent.mean_num_partners["Inj"] = -1
agent.mean_num_partners["Sex"] = -1
agent.mean_num_partners["SexInj"] = -1
agent.mean_num_partners["Social"] = -1
model.pop.update_partner_targets()

model.step(tmpdir)

for rel in model.pop.relationships:
if rel.bond_type == "Inj":
print(rel.agent1.mean_num_partners)
print(rel.agent2.mean_num_partners)
print(rel.agent1.race, rel.agent1.sex_type, rel.agent1.drug_type)
print(rel.agent2.race, rel.agent2.sex_type, rel.agent2.drug_type)
assert rel.bond_type != "Inj"


@pytest.mark.integration_deterministic
def test_incar(params_integration, tmpdir):
# turn on incar - initi is set to 0, so for these purposes, just run time
Expand Down
19 changes: 18 additions & 1 deletion tests/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_model_init(params):


@pytest.mark.unit
def test_update_all_agents(make_model, make_agent):
def test_update_all_agents(make_model, make_agent, make_relationship):
# make agent 0
model = make_model()
assert model.params.agent_zero.interaction_type == "injection"
Expand All @@ -57,6 +57,23 @@ def test_update_all_agents(make_model, make_agent):

assert "No agent zero!" in str(excinfo)

# check that model dissolves relationships
model.params.features.agent_zero = False
model.params.partnership.dissolve.enabled = True
model.params.partnership.dissolve.time = 1
model.time = 1
a = make_agent()
p = make_agent()
r = make_relationship(a, p)
model.pop.add_relationship(r)
a.target_partners["Sex"] = 0
a.target_partners["SexInj"] = 0
a.target_partners["Inj"] = 0

assert a.has_partners() is True
model.update_all_agents()
assert a.has_partners() is False


@pytest.mark.unit
def test_death_none(make_model):
Expand Down
8 changes: 7 additions & 1 deletion titan/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@ def update_all_agents(self):
# If static network, ignore relationship progression
if not self.params.features.static_network:
for rel in copy(self.pop.relationships):
if rel.progress():
if (
self.params.partnership.dissolve.enabled
and self.time == self.params.partnership.dissolve.time
):
rel.progress(force=True)
self.pop.remove_relationship(rel)
elif rel.progress():
self.pop.remove_relationship(rel)

if self.params.features.exit_enter:
Expand Down
7 changes: 7 additions & 0 deletions titan/params/partnership.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,10 @@ partnership:
description: Probability that for a given partnering attempt, the agent tries to partner with only other agents in their component. Otherwise, the agent tries to partner with agents from any component. Network must be enabled.
min: 0
max: 1
dissolve:
time:
type: int
default: -9999
enabled:
type: bool
default: false
17 changes: 17 additions & 0 deletions titan/settings/philly-gis/assort_mix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
assort_mix:
assort_disadvantaged:
attribute: race
agent_value: disadvantaged
partner_attribute: location
partner_values:
__same__: 0.32
__neighbor__: 0.15
__other__: 0.53
assort_notdisadvantaged:
attribute: race
agent_value: notdisadvantaged
partner_attribute: location
partner_values:
__same__: 0.2
__neighbor__: 0.096
__other__: 0.704
6 changes: 6 additions & 0 deletions titan/settings/philly-gis/calibration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
calibration:
sex:
act: 1.0
partner: 1.0
acquisition: 1.0
mortality: 1.0
Loading

0 comments on commit 21e0681

Please sign in to comment.