-
Notifications
You must be signed in to change notification settings - Fork 16
Template for Model Run
import datetime import logging import os from pathlib import Path
from tlo import Date, Simulation from tlo.analysis.utils import parse_log_file from tlo.methods import ( chronicsyndrome, contraception, demography, dx_algorithm_child, enhanced_lifestyle, healthburden, healthseekingbehaviour, healthsystem, mockitis, symptommanager, )
outputpath = Path('./outputs')
resourcefilepath = Path('./resources')
start_date = Date(year=2010, month=1, day=1) end_date = Date(year=2010, month=12, day=31) popsize = 2000 sim = Simulation(start_date=start_date)
datestamp = datetime.date.today().strftime("__%Y_%m_%d")
logfile = outputpath + 'LogFile' + datestamp + '.log'
if os.path.exists(logfile): os.remove(logfile) fh = logging.FileHandler(logfile) fr = logging.Formatter("%(levelname)s|%(name)s|%(message)s") fh.setFormatter(fr) logging.getLogger().addHandler(fh)
service_availability = ['*']
sim.register(demography.Demography(resourcefilepath=resourcefilepath)) sim.register(contraception.Contraception(resourcefilepath=resourcefilepath)) sim.register(enhanced_lifestyle.Lifestyle(resourcefilepath=resourcefilepath)) sim.register(healthsystem.HealthSystem(resourcefilepath=resourcefilepath, service_availability=service_availability, mode_appt_constraints=2, capabilities_coefficient=1.0, ignore_cons_constraints=False, disable=False))
sim.register(symptommanager.SymptomManager(resourcefilepath=resourcefilepath)) sim.register(healthseekingbehaviour.HealthSeekingBehaviour(resourcefilepath=resourcefilepath)) sim.register(dx_algorithm_child.DxAlgorithmChild(resourcefilepath=resourcefilepath)) sim.register(healthburden.HealthBurden(resourcefilepath=resourcefilepath))
sim.seed_rngs(0) sim.make_initial_population(n=popsize) sim.simulate(end_date=end_date) fh.flush()
output = parse_log_file(logfile)
TLO Model Wiki