Skip to content

Commit

Permalink
Merge pull request #228 from pph-collective/develop
Browse files Browse the repository at this point in the history
v3.2.0
  • Loading branch information
s-bessey authored Sep 12, 2022
2 parents bdcc3e7 + dd307bb commit 0574cd9
Show file tree
Hide file tree
Showing 35 changed files with 1,030 additions and 42 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "titan-model"
version = "3.1.0"
version = "3.2.0"
description = "TITAN Agent Based Model"
license = "GPL-3.0-only"
authors = ["Sam Bessey <[email protected]>", "Mary McGrath <[email protected]>"]
Expand Down
135 changes: 135 additions & 0 deletions tests/exposures/monkeypox_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import pytest

from conftest import FakeRandom

from titan.exposures import MonkeyPox
from titan.agent import Relationship


@pytest.mark.unit
def test_monkeypox_expose(make_model, make_agent):
model = make_model()
model.run_random = FakeRandom(0.0) # always less than param
a = make_agent()
p = make_agent()
a.partners["Sex"] = set()
p.partners["Sex"] = set()
rel = Relationship(a, p, 10, bond_type="Sex")

MonkeyPox.expose(model, "sex", rel, 1)

assert a.monkeypox.active is False
assert p.monkeypox.active is False

a.monkeypox.active = True
a.monkeypox.time = model.time
p.monkeypox.active = True
a.monkeypox.time = model.time

# test nothing happens
MonkeyPox.expose(model, "sex", rel, 10)

assert a.monkeypox.active
assert p.monkeypox.active

p.monkeypox.active = False

# test conversion happens
MonkeyPox.expose(model, "sex", rel, 10)

assert a.monkeypox.active
assert p.monkeypox.active


@pytest.mark.unit
def test_monkeypox_init(make_population, make_agent):
pop = make_population()
pop.pop_random = FakeRandom(0.0)
a = make_agent()

time = pop.params.monkeypox.start_time - 1

a.monkeypox.init_agent(pop, time)
assert a.monkeypox.active is False

time = pop.params.monkeypox.start_time

a.monkeypox.init_agent(pop, time)

assert a.monkeypox.active
assert a.monkeypox.time == time - pop.params.monkeypox.max_init_time
assert a.monkeypox.dx
assert a.monkeypox.dx_time == a.monkeypox.time
assert a in MonkeyPox.agents
assert MonkeyPox.dx_counts[a.race][a.sex_type] == 1


@pytest.mark.unit
def test_monkeypox_convert(make_model, make_agent):
model = make_model()
a = make_agent()

model.run_random = FakeRandom(-0.1)

a.monkeypox.convert(model)

assert a.monkeypox.active
assert a.monkeypox.time == model.time
assert a in MonkeyPox.agents


# TODO talk with Ellen about why this is failing?
@pytest.mark.unit
def test_diagnose_monkeypox(make_model, make_agent):
model = make_model()
model.params.partner_tracing.prob = 1.0
model.time = 1
a = make_agent()
p = make_agent()
p.monkeypox.active = True
a.partners["Sex"].add(p)

model.run_random = FakeRandom(-0.1) # always less than param
a.monkeypox.diagnose(model)

assert a.monkeypox.dx
assert a.monkeypox.dx_time == model.time


@pytest.mark.unit
def test_get_transmission_probability(make_model, make_agent):
model = make_model()
a = make_agent(race="white", SO="MSM")
a.sex_role = "versatile"

p = make_agent(race="white", SO="MSM")
p.sex_role = "versatile"

# test versatile-versatile relationship
p_sex = model.params.partnership.sex.acquisition.MSM.versatile
scale = model.params.calibration.acquisition

# must be in acute phase
a.monkeypox.active = True
a.monkeypox.time = model.time

assert a.monkeypox.get_transmission_probability(model, "sex", p, 1) == p_sex * scale
# Not transmissable with injection
assert a.monkeypox.get_transmission_probability(model, "inj", p, 1) == 0.0

# test one vers, one receptive
a.sex_role = "receptive"
p_sex_ins = model.params.partnership.sex.acquisition.MSM.insertive
p_sex_rec = model.params.partnership.sex.acquisition.MSM.receptive

assert a.hiv.get_transmission_probability(model, "sex", p, 1) == p_sex_ins * scale
assert p.hiv.get_transmission_probability(model, "sex", a, 1) == p_sex_rec * scale


@pytest.mark.unit
def test_get_acute_status(make_agent, make_model):
model = make_model()
a = make_agent()
assert a.monkeypox.get_acute_status(model.time + 2) is False
a.monkeypox.convert(model)
assert a.monkeypox.get_acute_status(model.time + 2) is True
26 changes: 26 additions & 0 deletions tests/features/vaccine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,29 @@ def test_vaccine_cquisition_risk_multiplier(make_agent):
a.vaccine.vaccinate(0)

assert a.vaccine.get_acquisition_risk_multiplier(1, "sex") < 1.0


@pytest.mark.unit
def test_vaccine_HVTN(make_agent):
a = make_agent()
print(a.location.params.vaccine.type)
a.location.params.vaccine.type = "HVTN702"
assert a.vaccine.get_acquisition_risk_multiplier(0, "sex") == 1.0

a.vaccine.vaccinate(0)
assert a.vaccine.get_acquisition_risk_multiplier(1, "sex") < 1.0


@pytest.mark.unit
def test_vaccine_other(make_agent):
a = make_agent()
print(a.location.params.vaccine.type)
a.location.params.vaccine.type = "other"
assert a.vaccine.get_acquisition_risk_multiplier(0, "sex") == 1.0

a.vaccine.vaccinate(0)
# no risk multiplier
assert a.vaccine.get_acquisition_risk_multiplier(1, "sex") == 1.0

a.location.params.vaccine.efficacy = 0.5
assert a.vaccine.get_acquisition_risk_multiplier(1, "sex") == 0.5
1 change: 1 addition & 0 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_model_reproducible(tmpdir):
assert res_a[i]["pseed"] == res_b[i]["pseed"]
assert res_a[i]["agents"] == res_b[i]["agents"]
assert res_a[i]["hiv"] == res_b[i]["hiv"]
assert res_a[i]["monkeypox"] == res_b[i]["monkeypox"]
assert res_a[i]["prep"] == res_b[i]["prep"]
assert res_a[i]["death"] == res_b[i]["death"]
assert res_a[i]["hiv_aids"] == res_b[i]["hiv_aids"]
Expand Down
11 changes: 11 additions & 0 deletions tests/params/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ demographics:
prob: 0.1
aids:
init: 0.1
monkeypox:
init: 0.1
dx:
init: 0.1
prob: 0.1
haart:
init: 0.1
enroll: &haart_prob
Expand Down Expand Up @@ -75,6 +80,11 @@ demographics:
prob: 0.1
aids:
init: 0.1
monkeypox:
init: 0.1
dx:
init: 0.1
prob: 0.1
num_partners:
Sex:
dist_type: poisson
Expand Down Expand Up @@ -324,6 +334,7 @@ outputs:
exposures:
hiv: true
knowledge: true
monkeypox: true

haart:
use_reinit: true
Expand Down
11 changes: 11 additions & 0 deletions tests/params/basic_seeded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ demographics:
prob: 0.1
aids:
init: 0.1
monkeypox:
init: 0.1
dx:
init: 0.1
prob: 0.1
haart:
init: 0.1
enroll:
Expand All @@ -59,6 +64,11 @@ demographics:
prob: 0.1
aids:
init: 0.1
monkeypox:
init: 0.1
dx:
init: 0.1
prob: 0.1
num_partners:
Sex:
dist_type: poisson
Expand Down Expand Up @@ -296,6 +306,7 @@ outputs:

exposures:
hiv: true
monkeypox: true
knowledge: true

features:
Expand Down
3 changes: 3 additions & 0 deletions tests/population_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def test_add_remove_agent_to_pop(make_population):
agent.hiv.aids = True
agent.hiv.dx = True
agent.hiv.add_agent(agent)
agent.monkeypox.active = True
agent.monkeypox.dx = True
agent.monkeypox.add_agent(agent)

pop.add_agent(agent)

Expand Down
2 changes: 1 addition & 1 deletion titan/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __str__(self) -> str:
"""
return (
f"\t{self.id}\t{self.age}\t{self.sex_type}\t{self.drug_type}\t" # type: ignore[attr-defined]
f"{self.race}\t{self.hiv.active}" # type: ignore[attr-defined]
f"{self.race}\t{self.hiv.active}\t{self.prep.active}" # type: ignore[attr-defined]
)

def __repr__(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions titan/exposures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .base_exposure import *
from .hiv import *
from .knowledge import *
from .monkeypox import MonkeyPox
Loading

0 comments on commit 0574cd9

Please sign in to comment.