Skip to content

Template for Model Run

Tim Hallett edited this page Oct 12, 2021 · 12 revisions
from pathlib import Path

from tlo import Date, Simulation
from tlo.analysis.utils import parse_log_file
from tlo.methods import (
    chronicsyndrome,
    contraception,
    demography,
    enhanced_lifestyle,
    healthburden,
    healthseekingbehaviour,
    healthsystem,
    mockitis,
    symptommanager,
)


# The Resource files [NB. Working directory must be set to the root of TLO: TLOmodel]
resourcefilepath = Path('./resources')

# Establish the simulation object
start_date = Date(year=2010, month=1, day=1)
end_date = Date(year=2010, month=12, day=31)
popsize = 2000
log_config = {'filename': 'LogFile'}

sim = Simulation(start_date=start_date, seed=0, log_config=log_config, show_progress_bar=True)

# Register the appropriate 'core' modules and do not let healthsystem constraints operate
sim.register(
    # Core Modules
    demography.Demography(resourcefilepath=resourcefilepath),
    simplifiedBirths.SimplifiedBirths(resourcefilepath=resourcefilepath),
    enhanced_lifestyle.Lifestyle(resourcefilepath=resourcefilepath),
    symptommanager.SymptomManager(resourcefilepath=resourcefilepath),
    healthseekingbehaviour.HealthSeekingBehaviour(resourcefilepath=resourcefilepath),
    healthburden.HealthBurden(resourcefilepath=resourcefilepath),

    # The HealthSystem
    healthsystem.HealthSystem(resourcefilepath=resourcefilepath, disable=True),

    # Register disease modules of interest
    # ....
)

# Run the simulation
sim.make_initial_population(n=popsize)
sim.simulate(end_date=end_date)

# Read the results
output = parse_log_file(sim.log_filepath)