Policies
A policy is written in the scenario file as a [[policies]] table. It changes a value that a plugin exposes, or opens, closes or upgrades places, at a date, without any change to the plugin's code.
A policy is what a scenario changes. It is written in the scenario file, one [[policies]] table per policy, and it never changes a plugin's code: it attaches to a value the plugin exposes, or acts on places. A scenario with no policy is the baseline.
There are two kinds of policy:
- a point policy multiplies or replaces the value of a modulation point, such as a hazard, for the people its filter selects, from a start date;
- a place policy opens, closes or upgrades places on a date, existing places or candidate sites.
Each policy's id is s:<scenario>#<name>, the scenario name lowercased. Every problem with a policy is reported with the scenario's other problems, located at its entry, and nothing runs. effective.toml lists the policies after the plugin tables, with every default written out, and provenance records them.
Point policies
The plugin that owns an event computes a base value and exposes it as a modulation point of its contract: a hazard per year, or a row of transition probabilities for one step. A point policy attaches to that point.
[[policies]]
name = "continuation-support"
kind = "transition_row"
point = "Contraception.discontinuation"
transition = "method_to_none"
factor = 0.8
filter = { sex = "female", age = [15, 24] }
start = 2027-01-01
end = 2030-01-01| Key | Value |
|---|---|
name | Lowercase ASCII letters, digits, - and _. Required. |
kind | "hazard" or "transition_row", the kind of the point, checked against it. Required. |
point | The point, "c:<ns>/<Contract>.<point>", "<ns>/<Contract>.<point>" or "<Contract>.<point>". Required. |
transition | On a transition_row point, the transition the policy changes; the point's stay entry absorbs the difference. Not for a hazard point. |
component | On a hazard point split into components (such as background and maternal deaths), the one component a factor multiplies. Default: every component. |
factor or override | Exactly one: a multiplier (at least 0), or the value that replaces the point's base value. |
filter | Who the policy applies to: sex, age (completed years, both bounds included), territory (units of the run's territory; a person matches when their unit or an ancestor is listed) and views (levels of categorical contract views). Clauses combine with AND. Default: everyone. |
start | The first day: the policy applies from the first step whose first day is on or after it. Required. |
end | The day it stops applying, excluded. Default: never. |
enabled | false keeps the policy in the file but applies it nowhere, so the run is the baseline run. Default: true. |
The example above is the one in the comments of docs/scenario.toml. A policy may only target a point of the scenario: a point an active plugin lists, or a point of an optional contract that has no provider, where the policy is checked and then kept neutral (warning W3011). Its point belongs to the planned official/Contraception contract, which no plugin of this release provides or requires, so in 0.1 it is refused with E3027. Neither test plugin of this release exposes a point.
How values combine
Only the plugin that owns a point evaluates it. The kernel combines the policies that apply at the step and whose filter matches the person, in a fixed order that never depends on the order of the file:
- on a hazard point, each component is its override if one is active, else its base value, times every factor, the factors multiplied in ascending policy id; the total is the sum of the components;
- on a transition row, each targeted transition is its override or base value times its factors; a probability above 1 is clamped to 1 and the clamp is journaled, then the stay entry restores the row's sum.
Two enabled overrides of one target whose windows overlap and whose filters may select the same people are refused before the run.
What the journal records
When a policy starts applying, the kernel journals Core.PolicyActivated; when its window ends inside the run, Core.PolicyEnded. A policy that never applies writes no row, so the journal equals the run without it. The events are listed on the official/Core contract page.
Place policies
A place policy acts on the places of a bound place table, by place_id:
[[policies]]
name = "two-csps-zone-z"
kind = "place"
action = "open"
places = [9, 10]
date = 2030-01-01| Key | Value |
|---|---|
name | As for a point policy. Required. |
kind | "place". Required. |
action | "open", "close" or "upgrade". Required. |
places | The place_ids. Required. |
date | The day it applies from: the first step on or after it. Required. |
capacity, attributes | For "upgrade" only: the new capacity, and new attribute values by name. |
enabled | As for a point policy. Default: true. |
"Two more health facilities in zone Z" is written this way: the data pipeline writes two candidate rows (candidate = true) in unit Z, the scenario binds that place table in [data.bindings], and the policy opens them on a date. The run journals one PlaceOpened event per place, with cause policy, at that step. A place_id that is not a bound place is refused once the rest of the file has no error, because the check needs the bound tables.
In 0.1 the test plugin test/clinics declares a collective type, clinic, for the health_centre places of a bound place.facility table, so place policies can be run with it; the engine's tests open two candidate clinics of one unit this way.
Policies and common random numbers
A baseline and a policy scenario run with the same seed share their random draws, because the scenario name never enters a seed and a policy changes what is done with a draw, not the draw. See common random numbers.