Basic workflow¶
This page demonstrates how to perform basic operations in Atomica. First, we will set up the notebook environment - the commands below are typically not required in user scripts:
[1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
import sys
sys.path.append('..')
To start with, import Atomica itself. It is often also useful to import numpy and matplotlib
[2]:
import atomica as at
import numpy as np
import matplotlib.pyplot as plt
Starting an application¶
The first step in starting a new application is to write a Framework file. This can be done by copying one of the templates in the atomica/library folder (either framework_template.xlsx or framework_template_advanced.xlsx) and implementing your model. Further guidance on this is provided separately in the framework documentation.
After writing the Framework, the next step is to generate a databook. This is performed in three steps
Load the framework into a
ProjectFrameworkPython instanceUse the framework to make a new
ProjectDatainstanceSave the
ProjectDatainstance to a spreadsheet
In this example, we will load an existing framework from the library. You can use at.LIBRARY_PATH to refer to the folder containing the library Excel files shipped with Atomica:
[3]:
F = at.ProjectFramework(at.LIBRARY_PATH / 'tb_framework.xlsx') # Load the Framework
D = at.ProjectData.new(F,pops=2, tvec=np.arange(2000,2018), transfers=0)
D.save('new_databook.xlsx')
Object saved to /home/runner/work/atomica/atomica/docs/examples/new_databook.xlsx.
The ProjectData class in Python can be thought of as an equivalent representation of the databook - you can edit the databook in Excel, which will result in changes to the ProjectData variable when the spreadsheet is loaded, and you can modify the ProjectData in Python and then write a modified spreadsheet. ProjectData has a number of methods that you can use to modify the databook, to do things like
Add or remove populations
Change the time span of the databook
To perform these operations, you can load in a databook using ProjectData.from_spreadsheet(). This lets you load in a databook given a particular framework. It is not required that the databook be completed prior to loading - you only need to complete the databook in its entirity if you want to use the databook in a project. So for example, to add an additional population and a transfer to this newly created databook, we could use:
[4]:
D = at.ProjectData.from_spreadsheet('new_databook.xlsx', framework=F)
D.add_pop('pris','Prisoners')
D.add_transfer('aging','Aging')
D.save('new_databook_2.xlsx')
Object saved to /home/runner/work/atomica/atomica/docs/examples/new_databook_2.xlsx.
Creating a project¶
Once you have completed the framework file and databook, you can create a project that can be used to run simulations and analyses. To do this, simply create a Project instance, passing in the file names for the framework and databook. Here we will use a pre-filled databook from the library:
[5]:
P = at.Project(framework=at.LIBRARY_PATH / 'tb_framework.xlsx', databook=at.LIBRARY_PATH / 'tb_databook.xlsx')
Elapsed time for running "default": 0.256s
When you create a project, a default simulation is automatically run. You can subsequently run simulations using P.run_sim()
[6]:
res = P.run_sim(parset='default', result_name='Default parset')
P.results.keys()
Elapsed time for running "default": 0.257s
[6]:
['parset_default']
When you run a simulation, by default it is automatically copied into the project, as well as being returned. Specifying the result name is optional, but recommended because it helps to keep track of the simulations when comparing and plotting them. We can now plot the result to show the compartment sizes:
[7]:
d = at.PlotData(res,pops='0-4',project=P)
at.plot_series(d,plot_type='stacked', data=P.data, legend_mode='separate');
For full details on plotting, please refer to the full plotting documentation here.
Calibrating the model¶
Model calibration can be performed in one of two ways - either manually, or automatically
Manual calibration¶
Manual calibration of the model proceeds in three steps
Make a new ParameterSet (e.g., by copying an existing one)
Modify the calibration scale factors in that ParameterSet
Run a simulation using the new parameter set
The commands to do this are shown below, for an example where the force of infection has been decreased:
[8]:
new_parset = P.parsets.copy('default','manually_calibrated')
new_parset.pars['foi_out'].meta_y_factor = 0.8 # Decrease infectiousness of all populations
new_parset.pars['foi_in'].y_factor['0-4'] = 2.0 # Increase susceptibility of young children
res_manually_calibrated = P.run_sim(parset='manually_calibrated', result_name='Manually calibrated')
d = at.PlotData([res,res_manually_calibrated],outputs='ac_inf',project=P)
at.plot_series(d, axis='results');
Elapsed time for running "default": 0.257s
Automatic calibration¶
To perform an automatic calibration, simply use P.calibrate() specifying the amount of time to run the calibration for, and the name of the new calibrated parset to create.
[9]:
P.calibrate(max_time=10, parset='default', new_name="auto_calibrated", save_to_project=True);
ASD: Launching with random seed None
Elapsed time for running "default": 0.162s
Elapsed time for running "default": 0.323s
step=1 choice=14, par=14, pm=0.0, origval=1.0, newval=1.1
step 1 (0.3 s) ++ (orig:10.14 | best:10.14 | new:10.10 | diff:-0.03783)
Elapsed time for running "default": 0.162s
step=2 choice=116, par=116, pm=0.0, origval=1.0, newval=1.1
step 2 (0.5 s) -- (orig:10.14 | best:10.10 | new:10.15 | diff:0.04885)
Elapsed time for running "default": 0.162s
step=3 choice=193, par=63, pm=1.0, origval=1.0, newval=0.9
step 3 (0.7 s) -- (orig:10.14 | best:10.10 | new:10.10 | diff:0)
Elapsed time for running "default": 0.158s
step=4 choice=30, par=30, pm=0.0, origval=1.0, newval=1.1
step 4 (0.8 s) ++ (orig:10.14 | best:10.10 | new:10.04 | diff:-0.06015)
Elapsed time for running "default": 0.168s
step=5 choice=112, par=112, pm=0.0, origval=1.0, newval=1.1
step 5 (1.0 s) -- (orig:10.14 | best:10.04 | new:10.26 | diff:0.2262)
Elapsed time for running "default": 0.168s
step=6 choice=212, par=82, pm=1.0, origval=1.0, newval=0.9
step 6 (1.2 s) ++ (orig:10.14 | best:10.04 | new:9.784 | diff:-0.2541)
Elapsed time for running "default": 0.163s
step=7 choice=161, par=31, pm=1.0, origval=1.0, newval=0.9
step 7 (1.3 s) -- (orig:10.14 | best:9.784 | new:9.797 | diff:0.01339)
Elapsed time for running "default": 0.162s
step=8 choice=99, par=99, pm=0.0, origval=1.0, newval=1.1
step 8 (1.5 s) ++ (orig:10.14 | best:9.784 | new:9.741 | diff:-0.04309)
Elapsed time for running "default": 0.168s
step=9 choice=203, par=73, pm=1.0, origval=1.0, newval=0.9
step 9 (1.7 s) ++ (orig:10.14 | best:9.741 | new:9.741 | diff:-0.00007722)
Elapsed time for running "default": 0.374s
step=10 choice=208, par=78, pm=1.0, origval=1.0, newval=0.9
step 10 (2.0 s) -- (orig:10.14 | best:9.741 | new:9.741 | diff:0)
Elapsed time for running "default": 0.166s
step=11 choice=101, par=101, pm=0.0, origval=1.0, newval=1.1
step 11 (2.2 s) -- (orig:10.14 | best:9.741 | new:9.741 | diff:0)
Elapsed time for running "default": 0.170s
step=12 choice=10, par=10, pm=0.0, origval=1.0, newval=1.1
step 12 (2.4 s) -- (orig:10.14 | best:9.741 | new:9.777 | diff:0.03641)
Elapsed time for running "default": 0.165s
step=13 choice=99, par=99, pm=0.0, origval=1.1, newval=1.25
step 13 (2.6 s) ++ (orig:10.14 | best:9.741 | new:9.690 | diff:-0.05124)
Elapsed time for running "default": 0.167s
step=14 choice=61, par=61, pm=0.0, origval=1.0, newval=1.1
step 14 (2.7 s) -- (orig:10.14 | best:9.690 | new:9.690 | diff:0.000000006667)
Elapsed time for running "default": 0.164s
step=15 choice=37, par=37, pm=0.0, origval=1.0, newval=1.1
step 15 (2.9 s) ++ (orig:10.14 | best:9.690 | new:9.690 | diff:-0.00008056)
Elapsed time for running "default": 0.163s
step=16 choice=72, par=72, pm=0.0, origval=1.0, newval=1.1
step 16 (3.1 s) -- (orig:10.14 | best:9.690 | new:9.690 | diff:0.0008872)
Elapsed time for running "default": 0.172s
step=17 choice=23, par=23, pm=0.0, origval=1.0, newval=1.1
step 17 (3.2 s) -- (orig:10.14 | best:9.690 | new:9.694 | diff:0.004157)
Elapsed time for running "default": 0.168s
step=18 choice=37, par=37, pm=0.0, origval=1.1, newval=1.25
step 18 (3.4 s) ++ (orig:10.14 | best:9.690 | new:9.689 | diff:-0.0001208)
Elapsed time for running "default": 0.160s
step=19 choice=131, par=1, pm=1.0, origval=1.0, newval=0.9
step 19 (3.6 s) ++ (orig:10.14 | best:9.689 | new:9.621 | diff:-0.06874)
Elapsed time for running "default": 0.404s
step=20 choice=73, par=73, pm=0.0, origval=0.9, newval=1.0
step 20 (4.0 s) -- (orig:10.14 | best:9.621 | new:9.621 | diff:0.00007725)
Elapsed time for running "default": 0.163s
step=21 choice=184, par=54, pm=1.0, origval=1.0, newval=0.9
step 21 (4.1 s) -- (orig:10.14 | best:9.621 | new:9.662 | diff:0.04099)
Elapsed time for running "default": 0.173s
step=22 choice=185, par=55, pm=1.0, origval=1.0, newval=0.9
step 22 (4.3 s) ++ (orig:10.14 | best:9.621 | new:9.621 | diff:-0.0001563)
Elapsed time for running "default": 0.167s
step=23 choice=183, par=53, pm=1.0, origval=1.0, newval=0.9
step 23 (4.5 s) ++ (orig:10.14 | best:9.621 | new:9.592 | diff:-0.02891)
Elapsed time for running "default": 0.169s
step=24 choice=61, par=61, pm=0.0, origval=1.0, newval=1.05
step 24 (4.7 s) -- (orig:10.14 | best:9.592 | new:9.592 | diff:0.000000002935)
Elapsed time for running "default": 0.164s
step=25 choice=216, par=86, pm=1.0, origval=1.0, newval=0.9
step 25 (4.8 s) ++ (orig:10.14 | best:9.592 | new:9.480 | diff:-0.1113)
Elapsed time for running "default": 0.164s
step=26 choice=86, par=86, pm=0.0, origval=0.9, newval=1.0
step 26 (5.0 s) -- (orig:10.14 | best:9.480 | new:9.592 | diff:0.1113)
Elapsed time for running "default": 0.163s
step=27 choice=202, par=72, pm=1.0, origval=1.0, newval=0.9
step 27 (5.2 s) ++ (orig:10.14 | best:9.480 | new:9.479 | diff:-0.0008788)
Elapsed time for running "default": 0.170s
step=28 choice=75, par=75, pm=0.0, origval=1.0, newval=1.1
step 28 (5.3 s) -- (orig:10.14 | best:9.479 | new:9.479 | diff:0.000000001829)
Elapsed time for running "default": 0.391s
step=29 choice=86, par=86, pm=0.0, origval=0.9, newval=0.9500000000000001
step 29 (5.7 s) -- (orig:10.14 | best:9.479 | new:9.535 | diff:0.05554)
Elapsed time for running "default": 0.165s
step=30 choice=140, par=10, pm=1.0, origval=1.0, newval=0.9
step 30 (5.9 s) ++ (orig:10.14 | best:9.479 | new:9.444 | diff:-0.03566)
Elapsed time for running "default": 0.182s
step=31 choice=225, par=95, pm=1.0, origval=1.0, newval=0.9
step 31 (6.1 s) -- (orig:10.14 | best:9.444 | new:9.526 | diff:0.08226)
Elapsed time for running "default": 0.169s
step=32 choice=29, par=29, pm=0.0, origval=1.0, newval=1.1
step 32 (6.3 s) ++ (orig:10.14 | best:9.444 | new:9.438 | diff:-0.005869)
Elapsed time for running "default": 0.163s
step=33 choice=16, par=16, pm=0.0, origval=1.0, newval=1.1
step 33 (6.4 s) -- (orig:10.14 | best:9.438 | new:9.438 | diff:0)
Elapsed time for running "default": 0.162s
step=34 choice=183, par=53, pm=1.0, origval=0.9, newval=0.75
step 34 (6.6 s) ++ (orig:10.14 | best:9.438 | new:9.395 | diff:-0.04321)
Elapsed time for running "default": 0.160s
step=35 choice=77, par=77, pm=0.0, origval=1.0, newval=1.1
step 35 (6.7 s) -- (orig:10.14 | best:9.395 | new:9.395 | diff:0.00000007362)
Elapsed time for running "default": 0.159s
step=36 choice=12, par=12, pm=0.0, origval=1.0, newval=1.1
step 36 (6.9 s) -- (orig:10.14 | best:9.395 | new:9.659 | diff:0.2640)
Elapsed time for running "default": 0.158s
step=37 choice=46, par=46, pm=0.0, origval=1.0, newval=1.1
step 37 (7.1 s) ++ (orig:10.14 | best:9.395 | new:9.392 | diff:-0.003034)
Elapsed time for running "default": 0.158s
step=38 choice=245, par=115, pm=1.0, origval=1.0, newval=0.9
step 38 (7.2 s) ++ (orig:10.14 | best:9.392 | new:9.368 | diff:-0.02340)
Elapsed time for running "default": 0.406s
step=39 choice=44, par=44, pm=0.0, origval=1.0, newval=1.1
step 39 (7.6 s) ++ (orig:10.14 | best:9.368 | new:9.241 | diff:-0.1274)
Elapsed time for running "default": 0.166s
step=40 choice=37, par=37, pm=0.0, origval=1.25, newval=1.475
step 40 (7.8 s) ++ (orig:10.14 | best:9.241 | new:9.241 | diff:-0.0001441)
Elapsed time for running "default": 0.169s
step=41 choice=222, par=92, pm=1.0, origval=1.0, newval=0.9
step 41 (8.0 s) -- (orig:10.14 | best:9.241 | new:9.241 | diff:0)
Elapsed time for running "default": 0.170s
step=42 choice=29, par=29, pm=0.0, origval=1.1, newval=1.25
step 42 (8.2 s) ++ (orig:10.14 | best:9.241 | new:9.232 | diff:-0.008977)
Elapsed time for running "default": 0.163s
step=43 choice=19, par=19, pm=0.0, origval=1.0, newval=1.1
step 43 (8.3 s) -- (orig:10.14 | best:9.232 | new:9.232 | diff:0)
Elapsed time for running "default": 0.171s
step=44 choice=89, par=89, pm=0.0, origval=1.0, newval=1.1
step 44 (8.5 s) ++ (orig:10.14 | best:9.232 | new:9.023 | diff:-0.2086)
Elapsed time for running "default": 0.159s
step=45 choice=201, par=71, pm=1.0, origval=1.0, newval=0.9
step 45 (8.7 s) ++ (orig:10.14 | best:9.023 | new:9.023 | diff:-0.00009253)
Elapsed time for running "default": 0.197s
step=46 choice=54, par=54, pm=0.0, origval=1.0, newval=1.1
step 46 (8.9 s) ++ (orig:10.14 | best:9.023 | new:9.023 | diff:-0.000001877)
Elapsed time for running "default": 0.198s
step=47 choice=223, par=93, pm=1.0, origval=1.0, newval=0.9
step 47 (9.1 s) -- (orig:10.14 | best:9.023 | new:9.023 | diff:0)
Elapsed time for running "default": 0.412s
step=48 choice=209, par=79, pm=1.0, origval=1.0, newval=0.9
step 48 (9.5 s) ++ (orig:10.14 | best:9.023 | new:9.023 | diff:-0.0000004815)
Elapsed time for running "default": 0.168s
step=49 choice=125, par=125, pm=0.0, origval=1.0, newval=1.1
step 49 (9.6 s) -- (orig:10.14 | best:9.023 | new:9.050 | diff:0.02731)
Elapsed time for running "default": 0.175s
step=50 choice=253, par=123, pm=1.0, origval=1.0, newval=0.9
step 50 (9.8 s) ++ (orig:10.14 | best:9.023 | new:8.919 | diff:-0.1044)
Elapsed time for running "default": 0.183s
step=51 choice=133, par=3, pm=1.0, origval=1.0, newval=0.9
step 51 (10.0 s) ++ (orig:10.14 | best:8.919 | new:8.875 | diff:-0.04393)
=== Time limit reached (10.01 > 10.00) (51 steps, orig: 10.14 | best: 8.875 | ratio: 1.1421331197416977) ===
You can then run a simulation with the calibrated parset by passing the name of the new parset to run_sim
[10]:
res_auto_calibrated = P.run_sim(parset='auto_calibrated',result_name='Automatically calibrated')
Elapsed time for running "default": 0.268s
Adding programs¶
The programs system allows parameter values to be overwritten based on spending on a set of programs. To get started, you will first need a program spreadsheet (progbook). The progbook is specific to a framework and a databook, because it refers to both the compartments and parameters of the model (from the framework) as well as the populations (from the databook).
You can make a new progbook using the .make_progbook() method of the project:
[11]:
P.make_progbook(progbook_path='example_progbook.xlsx', progs=4, data_start=2014, data_end=2018)
Object saved to /home/runner/work/atomica/atomica/docs/examples/example_progbook.xlsx.
[11]:
'/home/runner/work/atomica/atomica/docs/examples/example_progbook.xlsx'
After filling out the progbook, you can load it into the project using the .load_progbook() method. Here, we will load in a pre-filled progbook from the library:
[12]:
P.load_progbook(at.LIBRARY_PATH / 'tb_progbook.xlsx')
[12]:
<atomica.programs.ProgramSet at 0x7f81b09e3ed0>
[<class 'atomica.programs.ProgramSet'>, <class 'atomica.utils.NamedItem'>]
————————————————————————————————————————————————————————————————————————
Methods:
_get_code_name() add_pop() remove_par()
_normalize_inputs() add_program() remove_pop()
_read_effects() copy() remove_program()
_read_spending() from_spreadsheet() sample()
_read_targeting() get_alloc() save()
_write_effects() get_capacities() to_spreadsheet()
_write_spending() get_outcomes() to_workbook()
_write_targeting() get_prop_coverage() validate()
add_comp() new() add_par()
remove_comp()
————————————————————————————————————————————————————————————————————————
_book: None
_formats: None
_pop_types: ['default']
_references: None
comps: #0: 'initj': {'label': 'Initialization population size',
'type': 'de [...]
covouts: #0: ('v_num', '0-4'):
Parameter: v_num
Population: 0-4
Baseline [...]
created: datetime.datetime(2026, 9, 1, 1, 13, 21, 99869,
tzinfo=tzutc())
currency: '$'
gitinfo: {'branch': 'main', 'hash': '1edc42a', 'date':
'2026-09-01T11:11:19+10 [...]
modified: datetime.datetime(2026, 9, 1, 1, 13, 21, 797643,
tzinfo=tzutc())
name: 'default'
pars: #0: 'v_num': {'label': 'Number of vaccinations
administered', ' [...]
pops: #0: '0-4': {'label': 'Children 0-4', 'type':
'default'}
#1: '5- [...]
programs: #0: 'BCG':
<atomica.programs.Program at 0x7f81b6360510>
[<class 'atom [...]
tvec: array([2015., 2016., 2017.])
version: '1.32.4'
————————————————————————————————————————————————————————————————————————
Program set name: default
Programs: ['BCG', 'PCF', 'ACF', 'ACF-p', 'HospDS', 'HospMDR', 'HospXDR', 'AmbDS', 'AmbMDR', 'XDRnew', 'PrisDS', 'PrisDR']
Date created: 2026-Sep-01 01:13:21 UTC
Date modified: 2026-Sep-01 01:13:21 UTC
============================================================
This progbook has been added to the list of available progsets:
[13]:
P.progsets.keys()
[13]:
['default']
Running a simulation with programs requires one additional piece of information - a ProgramInstructions instance that specifies
What years the programs are active
Any overwrites to spending or coverage
In our case, we might just want to run a simulation with programs starting in 2018, so we can create a ProgramInstructions instance accordingly, and then use it to run the simulation:
[14]:
instructions = at.ProgramInstructions(start_year=2018)
res_progs = P.run_sim(parset='default',progset='default',progset_instructions=instructions)
Elapsed time for running "default": 0.368s
Reconciliation¶
Reconciliation is an operation that aims to change the properties of programs (such as their unit costs) such that the program-calculated parameter values optimally match the databook parameter values in the year the programs become active (or some other specified year). The reconciliation operation can therefore be treated as a mapping from one progset to another. To perform reconciliation, use the reconcile function directly, passing in:
the parameter set you want to match
the program set to modify
the reconciliation year
a specification of which aspects of the program set to modify (e.g. unit cost, program outcomes)
The reconcile function returns a new progset, which you can store in the project if desired, or otherwise work with independently:
[15]:
P.progsets['reconciled'] = at.reconcile(project=P, parset='default', progset='default', reconciliation_year=2018, unit_cost_bounds=0.05)[0]
WARNING {reconciliation.py:243} - Reconcilation when parameter is in number units not fully tested
Program set 'default' will be ignored while running project 'default' due to the absence of program set instructions
Elapsed time for running "default": 0.317s
Reconciling in 2018.00, evaluating from 2018.00 up to 2018.25
ASD: Launching with random seed None
step=1 choice=21, par=9, pm=1.0, origval=18000.0, newval=17100.0
step 1 (0.0 s) ++ (orig:61.58 | best:61.58 | new:61.57 | diff:-0.01364)
step=2 choice=1, par=1, pm=0.0, origval=1000.0, newval=1050.0
step 2 (0.0 s) -- (orig:61.58 | best:61.57 | new:61.57 | diff:0.004431)
step=3 choice=8, par=8, pm=0.0, origval=4500.0, newval=4725.0
step 3 (0.0 s) -- (orig:61.58 | best:61.57 | new:61.57 | diff:0)
step=4 choice=12, par=0, pm=1.0, origval=2.5, newval=2.375
step 4 (0.0 s) ++ (orig:61.58 | best:61.57 | new:61.57 | diff:-0.00002755)
step=5 choice=17, par=5, pm=1.0, origval=7500.0, newval=7125.0
step 5 (0.0 s) ++ (orig:61.58 | best:61.57 | new:61.49 | diff:-0.08149)
step=6 choice=7, par=7, pm=0.0, origval=2700.0, newval=2835.0
step 6 (0.0 s) -- (orig:61.58 | best:61.49 | new:61.49 | diff:0)
step=7 choice=7, par=7, pm=0.0, origval=2700.0, newval=2835.0
step 7 (0.0 s) -- (orig:61.58 | best:61.49 | new:61.49 | diff:0)
step=8 choice=22, par=10, pm=1.0, origval=5500.0, newval=5225.0
step 8 (0.0 s) -- (orig:61.58 | best:61.49 | new:61.49 | diff:0.003359)
step=9 choice=16, par=4, pm=1.0, origval=4900.0, newval=4655.0
step 9 (0.0 s) ++ (orig:61.58 | best:61.49 | new:61.42 | diff:-0.06943)
step=10 choice=8, par=8, pm=0.0, origval=4500.0, newval=4725.0
step 10 (0.0 s) -- (orig:61.58 | best:61.42 | new:61.42 | diff:0)
step=11 choice=2, par=2, pm=0.0, origval=4000.0, newval=4200.0
step 11 (0.0 s) -- (orig:61.58 | best:61.42 | new:61.42 | diff:0.00002363)
step=12 choice=20, par=8, pm=1.0, origval=4500.0, newval=4275.0
step 12 (0.0 s) -- (orig:61.58 | best:61.42 | new:61.42 | diff:0)
step=13 choice=0, par=0, pm=0.0, origval=2.375, newval=2.625
step 13 (0.0 s) -- (orig:61.58 | best:61.42 | new:61.42 | diff:0.00007308)
step=14 choice=13, par=1, pm=1.0, origval=1000.0, newval=950.0
step 14 (0.0 s) ++ (orig:61.58 | best:61.42 | new:61.41 | diff:-0.004674)
step=15 choice=10, par=10, pm=0.0, origval=5500.0, newval=5775.0
step 15 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.42 | diff:0.004171)
step=16 choice=14, par=2, pm=1.0, origval=4000.0, newval=3800.0
step 16 (0.0 s) ++ (orig:61.58 | best:61.41 | new:61.41 | diff:-0.00002487)
step=17 choice=6, par=6, pm=0.0, origval=10000.0, newval=10500.0
step 17 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.44 | diff:0.02744)
step=18 choice=5, par=5, pm=0.0, origval=7125.0, newval=7875.0
step 18 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.59 | diff:0.1803)
step=19 choice=5, par=5, pm=0.0, origval=7125.0, newval=7500.0
step 19 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.50 | diff:0.08149)
step=20 choice=20, par=8, pm=1.0, origval=4500.0, newval=4275.0
step 20 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.41 | diff:0)
step=21 choice=4, par=4, pm=0.0, origval=4655.0, newval=5145.0
step 21 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.56 | diff:0.1476)
step=22 choice=11, par=11, pm=0.0, origval=8000.0, newval=8400.0
step 22 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.41 | diff:0)
step=23 choice=11, par=11, pm=0.0, origval=8000.0, newval=8400.0
step 23 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.41 | diff:0)
step=24 choice=2, par=2, pm=0.0, origval=3800.0, newval=4000.0
step 24 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.41 | diff:0.00002487)
step=25 choice=23, par=11, pm=1.0, origval=8000.0, newval=7600.0
step 25 (0.0 s) -- (orig:61.58 | best:61.41 | new:61.41 | diff:0)
step=26 choice=18, par=6, pm=1.0, origval=10000.0, newval=9500.0
step 26 (0.0 s) ++ (orig:61.58 | best:61.41 | new:61.39 | diff:-0.02945)
step=27 choice=11, par=11, pm=0.0, origval=8000.0, newval=8200.0
step 27 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.39 | diff:0)
step=28 choice=22, par=10, pm=1.0, origval=5500.0, newval=5225.0
step 28 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.39 | diff:0.003359)
step=29 choice=5, par=5, pm=0.0, origval=7125.0, newval=7312.5
step 29 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.42 | diff:0.03816)
step=30 choice=4, par=4, pm=0.0, origval=4655.0, newval=4900.0
step 30 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.45 | diff:0.06943)
step=31 choice=10, par=10, pm=0.0, origval=5500.0, newval=5775.0
step 31 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.39 | diff:0.004171)
step=32 choice=9, par=9, pm=0.0, origval=17100.0, newval=18900.0
step 32 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.41 | diff:0.02538)
step=33 choice=19, par=7, pm=1.0, origval=2700.0, newval=2565.0
step 33 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.39 | diff:0)
step=34 choice=22, par=10, pm=1.0, origval=5500.0, newval=5362.5
step 34 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.39 | diff:0.001209)
step=35 choice=3, par=3, pm=0.0, origval=2500.0, newval=2625.0
step 35 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.39 | diff:0.005385)
step=36 choice=3, par=3, pm=0.0, origval=2500.0, newval=2625.0
step 36 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.39 | diff:0.005385)
step=37 choice=23, par=11, pm=1.0, origval=8000.0, newval=7600.0
step 37 (0.0 s) -- (orig:61.58 | best:61.39 | new:61.39 | diff:0)
step=38 choice=15, par=3, pm=1.0, origval=2500.0, newval=2375.0
step 38 (0.0 s) ++ (orig:61.58 | best:61.39 | new:61.38 | diff:-0.005951)
step=39 choice=9, par=9, pm=0.0, origval=17100.0, newval=18000.0
step 39 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.39 | diff:0.01325)
step=40 choice=8, par=8, pm=0.0, origval=4500.0, newval=4612.5
step 40 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=41 choice=8, par=8, pm=0.0, origval=4500.0, newval=4556.25
step 41 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=42 choice=1, par=1, pm=0.0, origval=950.0, newval=1000.0
step 42 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.004672)
step=43 choice=19, par=7, pm=1.0, origval=2700.0, newval=2565.0
step 43 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=44 choice=9, par=9, pm=0.0, origval=17100.0, newval=17550.0
step 44 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.39 | diff:0.006771)
step=45 choice=2, par=2, pm=0.0, origval=3800.0, newval=3900.0
step 45 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.00001275)
step=46 choice=4, par=4, pm=0.0, origval=4655.0, newval=4777.5
step 46 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.41 | diff:0.03338)
step=47 choice=9, par=9, pm=0.0, origval=17100.0, newval=17325.0
step 47 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.003424)
step=48 choice=6, par=6, pm=0.0, origval=9500.0, newval=10000.0
step 48 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.41 | diff:0.02945)
step=49 choice=3, par=3, pm=0.0, origval=2375.0, newval=2437.5
step 49 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.003052)
step=50 choice=6, par=6, pm=0.0, origval=9500.0, newval=9750.0
step 50 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.39 | diff:0.01499)
step=51 choice=7, par=7, pm=0.0, origval=2700.0, newval=2767.5
step 51 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=52 choice=1, par=1, pm=0.0, origval=950.0, newval=975.0
step 52 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.002367)
step=53 choice=2, par=2, pm=0.0, origval=3800.0, newval=3850.0
step 53 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000006460)
step=54 choice=23, par=11, pm=1.0, origval=8000.0, newval=7800.0
step 54 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=55 choice=0, par=0, pm=0.0, origval=2.375, newval=2.5
step 55 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.00002755)
step=56 choice=23, par=11, pm=1.0, origval=8000.0, newval=7900.0
step 56 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=57 choice=10, par=10, pm=0.0, origval=5500.0, newval=5637.5
step 57 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.001094)
step=58 choice=7, par=7, pm=0.0, origval=2700.0, newval=2733.75
step 58 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=59 choice=11, par=11, pm=0.0, origval=8000.0, newval=8100.0
step 59 (0.0 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=60 choice=1, par=1, pm=0.0, origval=950.0, newval=962.5
step 60 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.001191)
step=61 choice=19, par=7, pm=1.0, origval=2700.0, newval=2632.5
step 61 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=62 choice=20, par=8, pm=1.0, origval=4500.0, newval=4387.5
step 62 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=63 choice=9, par=9, pm=0.0, origval=17100.0, newval=17212.5
step 63 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.001722)
step=64 choice=5, par=5, pm=0.0, origval=7125.0, newval=7218.75
step 64 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.40 | diff:0.01837)
step=65 choice=23, par=11, pm=1.0, origval=8000.0, newval=7950.0
step 65 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=66 choice=4, par=4, pm=0.0, origval=4655.0, newval=4716.25
step 66 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.40 | diff:0.01632)
step=67 choice=0, par=0, pm=0.0, origval=2.375, newval=2.4375
step 67 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.00001114)
step=68 choice=10, par=10, pm=0.0, origval=5500.0, newval=5568.75
step 68 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0002804)
step=69 choice=19, par=7, pm=1.0, origval=2700.0, newval=2666.25
step 69 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=70 choice=3, par=3, pm=0.0, origval=2375.0, newval=2406.25
step 70 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.001546)
step=71 choice=20, par=8, pm=1.0, origval=4500.0, newval=4443.75
step 71 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=72 choice=2, par=2, pm=0.0, origval=3800.0, newval=3825.0
step 72 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000003251)
step=73 choice=10, par=10, pm=0.0, origval=5500.0, newval=5534.375
step 73 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.00007096)
step=74 choice=6, par=6, pm=0.0, origval=9500.0, newval=9625.0
step 74 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.39 | diff:0.007562)
step=75 choice=5, par=5, pm=0.0, origval=7125.0, newval=7171.875
step 75 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.39 | diff:0.009000)
step=76 choice=22, par=10, pm=1.0, origval=5500.0, newval=5431.25
step 76 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0002947)
step=77 choice=10, par=10, pm=0.0, origval=5500.0, newval=5517.1875
step 77 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.00001785)
step=78 choice=22, par=10, pm=1.0, origval=5500.0, newval=5465.625
step 78 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.00007276)
step=79 choice=22, par=10, pm=1.0, origval=5500.0, newval=5482.8125
step 79 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.00001808)
step=80 choice=1, par=1, pm=0.0, origval=950.0, newval=956.25
step 80 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0005974)
step=81 choice=19, par=7, pm=1.0, origval=2700.0, newval=2683.125
step 81 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=82 choice=7, par=7, pm=0.0, origval=2700.0, newval=2716.875
step 82 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=83 choice=6, par=6, pm=0.0, origval=9500.0, newval=9562.5
step 83 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.003798)
step=84 choice=0, par=0, pm=0.0, origval=2.375, newval=2.40625
step 84 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000004857)
step=85 choice=23, par=11, pm=1.0, origval=8000.0, newval=7975.0
step 85 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=86 choice=0, par=0, pm=0.0, origval=2.375, newval=2.390625
step 86 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000002243)
step=87 choice=8, par=8, pm=0.0, origval=4500.0, newval=4528.125
step 87 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=88 choice=7, par=7, pm=0.0, origval=2700.0, newval=2708.4375
step 88 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=89 choice=9, par=9, pm=0.0, origval=17100.0, newval=17156.25
step 89 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0008633)
step=90 choice=2, par=2, pm=0.0, origval=3800.0, newval=3812.5
step 90 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000001631)
step=91 choice=3, par=3, pm=0.0, origval=2375.0, newval=2390.625
step 91 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0007779)
step=92 choice=11, par=11, pm=0.0, origval=8000.0, newval=8050.0
step 92 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=93 choice=4, par=4, pm=0.0, origval=4655.0, newval=4685.625
step 93 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.39 | diff:0.008065)
step=94 choice=6, par=6, pm=0.0, origval=9500.0, newval=9531.25
step 94 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.001903)
step=95 choice=19, par=7, pm=1.0, origval=2700.0, newval=2691.5625
step 95 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=96 choice=5, par=5, pm=0.0, origval=7125.0, newval=7148.4375
step 96 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.004453)
step=97 choice=4, par=4, pm=0.0, origval=4655.0, newval=4670.3125
step 97 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.004008)
step=98 choice=22, par=10, pm=1.0, origval=5500.0, newval=5491.40625
step 98 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000004505)
step=99 choice=10, par=10, pm=0.0, origval=5500.0, newval=5508.59375
step 99 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000004477)
step=100 choice=21, par=9, pm=1.0, origval=17100.0, newval=17100.0
step 100 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=101 choice=19, par=7, pm=1.0, origval=2700.0, newval=2695.78125
step 101 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=102 choice=23, par=11, pm=1.0, origval=8000.0, newval=7987.5
step 102 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=103 choice=9, par=9, pm=0.0, origval=17100.0, newval=17128.125
step 103 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0004323)
step=104 choice=8, par=8, pm=0.0, origval=4500.0, newval=4514.0625
step 104 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=105 choice=2, par=2, pm=0.0, origval=3800.0, newval=3806.25
step 105 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0000008167)
step=106 choice=7, par=7, pm=0.0, origval=2700.0, newval=2704.21875
step 106 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=107 choice=20, par=8, pm=1.0, origval=4500.0, newval=4471.875
step 107 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=108 choice=20, par=8, pm=1.0, origval=4500.0, newval=4485.9375
step 108 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=109 choice=13, par=1, pm=1.0, origval=950.0, newval=950.0
step 109 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=110 choice=0, par=0, pm=0.0, origval=2.375, newval=2.3828125
step 110 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000001074)
step=111 choice=21, par=9, pm=1.0, origval=17100.0, newval=17100.0
step 111 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=112 choice=17, par=5, pm=1.0, origval=7125.0, newval=7125.0
step 112 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=113 choice=20, par=8, pm=1.0, origval=4500.0, newval=4492.96875
step 113 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=114 choice=6, par=6, pm=0.0, origval=9500.0, newval=9515.625
step 114 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0009528)
step=115 choice=18, par=6, pm=1.0, origval=9500.0, newval=9500.0
step 115 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=116 choice=8, par=8, pm=0.0, origval=4500.0, newval=4507.03125
step 116 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=117 choice=10, par=10, pm=0.0, origval=5500.0, newval=5504.296875
step 117 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000001121)
step=118 choice=16, par=4, pm=1.0, origval=4655.0, newval=4655.0
step 118 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=119 choice=0, par=0, pm=0.0, origval=2.375, newval=2.37890625
step 119 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0000005250)
step=120 choice=4, par=4, pm=0.0, origval=4655.0, newval=4662.65625
step 120 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.001998)
step=121 choice=9, par=9, pm=0.0, origval=17100.0, newval=17114.0625
step 121 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0002163)
step=122 choice=2, par=2, pm=0.0, origval=3800.0, newval=3803.125
step 122 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0000004087)
step=123 choice=14, par=2, pm=1.0, origval=3800.0, newval=3800.0
step 123 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=124 choice=12, par=0, pm=1.0, origval=2.375, newval=2.375
step 124 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=125 choice=22, par=10, pm=1.0, origval=5500.0, newval=5495.703125
step 125 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.000001124)
step=126 choice=5, par=5, pm=0.0, origval=7125.0, newval=7136.71875
step 126 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.002214)
step=127 choice=3, par=3, pm=0.0, origval=2375.0, newval=2382.8125
step 127 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0.0003902)
step=128 choice=8, par=8, pm=0.0, origval=4500.0, newval=4503.515625
step 128 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
step=129 choice=11, par=11, pm=0.0, origval=8000.0, newval=8025.0
step 129 (0.1 s) -- (orig:61.58 | best:61.38 | new:61.38 | diff:0)
=== Relative improvement too small (0.000005444 < 0.001000) (129 steps, orig: 61.58 | best: 61.38 | ratio: 1.0033347274753137) ===
You can then run simulations with the modified program set. You can also save the new programset to a progbook if you wish to edit it further in Excel:
[16]:
P.progsets['reconciled'].save('reconciled_progset.xlsx');
Object saved to /home/runner/work/atomica/atomica/docs/examples/reconciled_progset.xlsx.
Scenarios¶
A scenario involves overriding some aspect of the simulation that would otherwise be specified in the databook or progbook. There are three kinds of scenarios
Parameter scenarios, when you want to test the effect of a specific parameter value
Budget scenarios, when you want to examine the outcomes of specific spending values
Coverage scenarios, when you want to examine the effect of specific program coverages irrespective of spending
Examples of these scenarios are shown below:
Parameter scenarios¶
[17]:
scvalues = dict()
scvalues['b_rate'] = dict()
scvalues['b_rate']['0-4'] = dict()
scvalues['b_rate']['0-4']["t"] = [2015, 2020, 2035]
scvalues['b_rate']['0-4']["y"] = [270000, 220000, 220000]
scen = P.make_scenario(which='parameter', name="Reduced births", scenario_values=scvalues)
res_par_scen = scen.run(P, P.parsets["default"]);
# Plot the parameter and compare to scenario input values
d = at.PlotData(res_par_scen,outputs='b_rate',pops='0-4')
at.plot_series(d)
plt.scatter(scvalues['b_rate']['0-4']["t"],scvalues['b_rate']['0-4']["y"],color='r')
Elapsed time for running "default": 0.271s
[17]:
<matplotlib.collections.PathCollection at 0x7f81b521ea50>
Budget scenarios¶
To run a program-related scenario, such as a budget or coverage scenario, it is not necessary to construct a Scenario object. Instead, you can directly create and use the program instructions that define the scenario:
[18]:
alloc = P.progsets[0].get_alloc(2018)
doubled_budget = {x:v*2 for x,v in alloc.items()}
instructions = at.ProgramInstructions(start_year=2018,alloc=doubled_budget)
res_baseline = P.run_sim(parset='default',progset='default',progset_instructions=at.ProgramInstructions(start_year=2018),result_name='Baseline')
res_budget_scen = P.run_sim(parset='default',progset='default',progset_instructions=instructions,result_name='Doubled');
d = at.PlotData.programs([res_baseline,res_budget_scen]).interpolate(2018)
at.plot_bars(d,stack_outputs='all');
Elapsed time for running "default": 0.372s
Elapsed time for running "default": 0.361s
Alternatively, you can create a full scenario object by storing the instructions in a CombinedScenario. The CombinedScenario optionally allows you to mix parameter and program scenarios.
[19]:
scen = P.make_scenario(which='combined', name="Doubled (scen)", instructions=instructions)
res_combined_scen = scen.run(P, parset='default',progset='default')
d = at.PlotData.programs([res_baseline,res_budget_scen, res_combined_scen]).interpolate(2018)
at.plot_bars(d,stack_outputs='all');
Elapsed time for running "default": 0.368s
Coverage scenarios¶
With coverage scenarios, the program instructions override a program’s coverage. Therefore, the spending values and coverage values may not match up with what is entered in the program book. If running coverage scenarios, take care not to use the spending values for such results - typically this is not a problem, because if you did have a particular spending amount in mind, then it would be better to use a budget scenario.
[20]:
half_coverage = {x:0.5 for x in P.progsets[0].programs.keys()}
instructions = at.ProgramInstructions(start_year=2018,coverage=half_coverage)
scen = at.CombinedScenario(name='Reduced coverage',instructions=instructions)
res_cov_scen = scen.run(P,parset='default',progset='default');
Elapsed time for running "default": 0.348s
Optimization¶
The role of optimization is to produce a set of program spending overwrites that improves the model output in some way. It is thus an operation that maps one set of program instructions to another, where the optimized program instructions contain the optimized allocation. An optimization consists of three parts
adjustmentsthat specify what parts of the program instructions to change, and how to change themmeasurablesthat define optimality (e.g. reducing new infections, maximizing people alive)constraintsthat must be satisfied, such as fixed total spending
An Optimization object contains these three items, as well any additional parameters specific to the optimization algorithm (e.g. the optimization method, the maximum run time).
The optimize function uses the Optimization to modify a particular set of program instructions. It therefore takes in
A parset and progset to use
A program instructions instance to optimize
An optimization object, that specifies how to perform the optimization
[21]:
instructions = at.ProgramInstructions(alloc=P.progsets[0],start_year=2020) # Instructions for default spending
adjustments = [at.SpendingAdjustment(x,2020,'rel',0.,2.) for x in instructions.alloc.keys()]
measurables = at.MaximizeCascadeStage(None,2020)
constraints = at.TotalSpendConstraint() # Cap total spending in all years
optimization = at.Optimization(name='default', adjustments=adjustments, measurables=measurables,constraints=constraints,maxtime=10) # Evaluate from 2020 to end of simulation
optimized_instructions = at.optimize(P, optimization, parset=P.parsets["default"], progset=P.progsets['default'], instructions=instructions)
ASD: Launching with random seed None
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=1 choice=1, par=1, pm=0.0, origval=25568000.0, newval=28124800.0
step 1 (0.4 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=2 choice=12, par=0, pm=1.0, origval=345000.0, newval=310500.0
step 2 (0.8 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=3 choice=17, par=5, pm=1.0, origval=8205000.0, newval=7384500.0
step 3 (1.2 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=4 choice=2, par=2, pm=0.0, origval=25282133.33333333, newval=27810346.66666666
step 4 (1.6 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=5 choice=3, par=3, pm=0.0, origval=893333.3333333334, newval=982666.6666666667
step 5 (2.3 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=6 choice=18, par=6, pm=1.0, origval=1246000.0, newval=1121400.0
step 6 (2.6 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=7 choice=16, par=4, pm=1.0, origval=109461100.0, newval=98514990.0
step 7 (3.0 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=8 choice=4, par=4, pm=0.0, origval=109461100.0, newval=120407210.0
step 8 (3.4 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=9 choice=5, par=5, pm=0.0, origval=8205000.0, newval=9025500.0
step 9 (3.8 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=10 choice=23, par=11, pm=1.0, origval=240000.0, newval=216000.0
step 10 (4.1 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=11 choice=5, par=5, pm=0.0, origval=8205000.0, newval=8615250.0
step 11 (4.8 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=12 choice=2, par=2, pm=0.0, origval=25282133.33333333, newval=26546239.999999996
step 12 (5.2 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=13 choice=3, par=3, pm=0.0, origval=893333.3333333334, newval=938000.0
step 13 (5.5 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=14 choice=15, par=3, pm=1.0, origval=893333.3333333334, newval=804000.0
step 14 (5.9 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=15 choice=3, par=3, pm=0.0, origval=893333.3333333334, newval=915666.6666666667
step 15 (6.3 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=16 choice=0, par=0, pm=0.0, origval=345000.0, newval=379500.0
step 16 (6.7 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=17 choice=1, par=1, pm=0.0, origval=25568000.0, newval=26846400.0
step 17 (7.0 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=18 choice=13, par=1, pm=1.0, origval=25568000.0, newval=23011200.0
step 18 (7.7 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=19 choice=21, par=9, pm=1.0, origval=961200.0, newval=865080.0
step 19 (8.1 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=20 choice=21, par=9, pm=1.0, origval=961200.0, newval=913140.0
step 20 (8.4 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=21 choice=14, par=2, pm=1.0, origval=25282133.33333333, newval=22753919.999999996
step 21 (8.8 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=22 choice=6, par=6, pm=0.0, origval=1246000.0, newval=1370600.0
step 22 (9.2 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=23 choice=23, par=11, pm=1.0, origval=240000.0, newval=228000.0
step 23 (9.5 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
ASD: Warning, negative objective function starting value (-11728.9) could lead to unexpected behavior
step=24 choice=14, par=2, pm=1.0, origval=25282133.33333333, newval=24018026.66666666
step 24 (10.2 s) -- (orig:-11730 | best:-11730 | new:-11730 | diff:0)
=== Time limit reached (10.21 > 10.00) (24 steps, orig: -11730 | best: -11730 | ratio: 1.0) ===
The function returns a set of optimized instructions, that can then be used to run a simulation
[22]:
res_optimized = P.run_sim(parset='default',progset='default',progset_instructions=optimized_instructions)
Elapsed time for running "default": 0.368s
For more details on the optimization system, see the general documentation on optimization.