Kernel and plugins
The kernel owns population, time, randomness, the journal and provenance; every demographic behaviour is a plugin that attaches through a manifest and versioned contracts.
cohortix is organised as a kernel and plugins. The kernel owns the population state (people, the links between them, the territory), time, randomness, the event journal and provenance. It contains no demographic behaviour. Mortality, reproduction, contraception, union and every other behaviour is a plugin.
What the kernel does
- People. Each person has a stable id that is never reused, and kernel columns: birth date, sex, alive, date of death and whether the person is in the simulated domain or has emigrated. Plugins cannot write these columns. They change only when the kernel commits an
official/Mortality.Deathorofficial/Migration.Emigrationevent. - Time. A run advances in fixed steps of one calendar month or one calendar year. Every event of a step is stamped with the step's first day. Ages use one convention throughout: the completed age on the last day of the previous step.
- Phases. Each step runs the phases listed in
phases.order, in that order. Within a phase, plugin handlers run in an order the kernel resolves at start-up from the contract names and the plugins' before and after constraints, never from load order. - Randomness. Plugins draw uniforms only from the kernel, under a named decision type. See common random numbers.
- Writes. A plugin changes state only by emitting an event. The kernel checks that the plugin owns every column the event writes, then commits it and appends it to the journal.
Contracts
A contract is a versioned data file, contracts/<namespace>/<Name>/v<major>.toml, independent of any plugin. It names the events, requests, link types, modulation points and decision types that independently written plugins share. A plugin provides a contract or requires one; either side can be swapped without the other noticing.
The kernel has its own contract, official/Core: it creates people, voids events about people who died earlier in the same delivery, and records when a policy starts and stops applying.
Manifests
Each plugin embeds a plugin.toml manifest that declares what it provides, requires, owns, reads and emits. At start-up the kernel checks every manifest against the loaded contracts and reports every problem together before anything runs. The test plugin of 0.1:
[plugin]
name = "p:test/ticker"
version = "0.1.0"
tier = "sdk"
core = "^0.1"
sdk = "^0.1"
[[provides]]
contract = "c:test/Tick"
version = "1.0.0"
variant = "counter"core and sdk are the version ranges of the kernel and SDK the plugin works with. A range that excludes the running version is refused (E2004, E2005).
Variants
A plugin may provide several variants of one contract, and exactly one is active in a run. Decision types, events, journal partitions and policies are keyed on the contract, never on the variant. Two runs that differ only by the variant chosen therefore give every person the same draws: the variants differ only in what they do with them.
Policies are modulators
The plugin that owns an event computes a base value, such as a hazard, and exposes it as a modulation point. A policy attaches a factor or an override to that point, with a filter on sex and age and a time window. The kernel combines them in a fixed order, so the owner's code never changes when a policy is added. Writing policies in the scenario file ([[policies]]) is not supported yet in 0.1.
In this version
Version 0.1 links one test-only plugin, test/ticker. The official plugins (contraception, mortality, reproduction, union-exogenous) have reserved folders and are not written yet. See plugins.