Simulate a seeded Bass adoption path
This tutorial simulates one finite-population Bass adoption path. It follows 100 agents while reporting a market level measured in 250 arbitrary units, making the distinction between adopter counts and scaled outcomes explicit. The seed fixes this synthetic realization for the tested runtime; it does not turn the path into an expected adoption curve.
Learning outcomes
Section titled “Learning outcomes”You will specify the model and execution engine separately, check monotone bounded counts, and convert those counts into level units. You will verify same-request replay, show that removing early observation times does not restart the process, and require an unsupported engine to fail visibly.
Prerequisites
Section titled “Prerequisites”Install the current native development package with its locked Python and Polars dependencies. Run the example from the same checkout used to build that package. It needs no observed dataset or network service.
| Input | Value in this example | Meaning |
|---|---|---|
| Model key | bass |
Selects the supported scientific model family |
| Operation and engine | simulate_model, kairos_des |
Runs the native discrete-event population process |
p, q |
0.2, 0.3 |
Innovation and imitation coefficients per numeric time unit |
m |
250 |
Market level in the chosen output units |
population |
100 |
Number of simulated agents, denoted N |
seed |
42 |
Fixes the random stream for this request and runtime |
ticks_per_unit |
1_000_000 |
Scheduler resolution within one numeric time unit |
The observation times are [0, 1, 5, 20]. Time is finite, nonnegative and
strictly increasing. The API does not infer dates or units from those numbers.
If the unit is a year, for example, p and q are per year and one tick is
one millionth of a year. No initial adopters are supplied, so the process starts
with zero.
-
Run the canonical example with the interpreter containing the native package:
Terminal window .venv-native/bin/python -I examples/native_kairos.py -
Confirm that the returned engine metadata is
kairos_desand compare the complete response with a second execution of the identical request. -
Follow the count bounds and independent count-to-level conversion. The resulting Polars table associates each query time with both quantities.
-
Request only the later query times, then test a zero-innovation limiting case and an unknown engine name.
"""Check a seeded Bass DES path, replay and its count-to-level interpretation.
The population has 100 agents, while market potential is 250 arbitrary units.One seeded path is a synthetic realization, not an expected adoption curve.Finite-population expectations with imitation need not equal deterministic Bass."""
import jsonimport mathfrom itertools import pairwise
import polars as pl
from innovate import NativeError, execute
def main() -> None: """Validate replay, sampling invariance, physical bounds and engine errors.""" times = [0.0, 1.0, 5.0, 20.0] parameters = {"p": 0.2, "q": 0.3, "m": 250.0} options = {"engine": "kairos_des", "seed": 42, "population": 100, "ticks_per_unit": 1_000_000} request = {"inputs": {"time": times}, "parameters": parameters, "simulation_options": options} response = execute("simulate_model", "bass", **request) replay_equal = response == execute("simulate_model", "bass", **request) assert replay_equal assert response["metadata"]["engine"] == "kairos_des"
result = response["result"] counts = result["counts"] assert len(counts) == len(times) assert all(type(count) is int and 0 <= count <= options["population"] for count in counts) assert counts[0] == 0 and counts[-1] > 0 assert all(left <= right for left, right in pairwise(counts))
# Independent unit conversion: each agent represents m / population units. expected_levels = [parameters["m"] * count / options["population"] for count in counts] assert all( math.isclose(actual, expected, rel_tol=1e-12, abs_tol=1e-12) for actual, expected in zip(result["values"], expected_levels, strict=True) ) trajectory = pl.DataFrame({"time": times, "adopters": counts, "level": result["values"]}) assert trajectory["time"].to_list() == times
# Merely asking for fewer observations must not restart the event process. sparse = execute("simulate_model", "bass", **{**request, "inputs": {"time": times[2:]}})["result"] sparse_grid_equal = sparse["counts"] == counts[2:] and sparse["values"] == result["values"][2:] assert sparse_grid_equal
# With no innovators and no initial adopters, imitation has no source. no_innovators = execute("simulate_model", "bass", **{**request, "parameters": {**parameters, "p": 0.0}})["result"] assert no_innovators["counts"] == [0] * len(times)
try: execute("simulate_model", "bass", **{**request, "simulation_options": {**options, "engine": "unknown"}}) except NativeError as error: unknown_engine_rejected = error.code == "invalid_request" else: unknown_engine_rejected = False assert unknown_engine_rejected, "An unsupported engine must fail instead of selecting a deterministic curve."
print( json.dumps( { "counts": trajectory["adopters"].to_list(), "levels": trajectory["level"].to_list(), "replay_equal": replay_equal, "sparse_grid_equal": sparse_grid_equal, "unknown_engine_rejected": unknown_engine_rejected, }, sort_keys=True, ) )
if __name__ == "__main__": main()The native simulation implementation
describes this as a finite-population pure-birth process. Kairos supplies clock,
dispatch and random-stream mechanisms. Selecting kairos_des is an explicit
execution choice within this supported model/operation combination; it is not
a global switch to a different host-language backend.
Expected results
Section titled “Expected results”The script prints this output after all assertions pass. The displayed value comes from the same manifest that checks executable example output.
{"counts": [0, 27, 82, 100], "levels": [0.0, 67.5, 205.0, 250.0], "replay_equal": true, "sparse_grid_equal": true, "unknown_engine_rejected": true}The adopter counts stay between zero and 100, are nondecreasing, and have one
entry per query time. replay_equal checks the repeated request in the same
runtime. sparse_grid_equal checks that querying only times 5 and 20 returns
the corresponding suffix of the original counts and levels.
Interpretation
Section titled “Interpretation”Distinguish the process, counts and level units
Section titled “Distinguish the process, counts and level units”When n of N agents have adopted, the total next-adoption hazard is
(p + q*n/N) * (N-n). The fraction n/N measures population adoption for
imitation; N-n counts the remaining susceptible agents. Each event adds one
adopter. This fixture has no departures or replacement, so its path cannot
decrease.
The returned counts are integer agents. The corresponding values use
m * count / population. Here one agent represents 250/100 = 2.5 level
units, so 27 adopters correspond to 67.5 units. A level of 250 means that all
100 agents have adopted; it does not mean that the simulation contains 250
agents. The independent conversion in the example checks each returned level
with relative and absolute tolerances of 1e-12.
The returned path is one realization of that event process. With imitation,
the hazard depends nonlinearly on the random adoption count. Averaging
finite-population paths therefore need not reproduce the deterministic Bass
curve exactly. A deterministic prediction and a stochastic path require their
own interpretations even when both use the model key bass.
Separate query times from simulation time
Section titled “Separate query times from simulation time”The process starts at its time origin, rather than at the first requested observation. Asking only for times 5 and 20 does not discard the events before time five or create a new initial state. The script checks this by comparing the later counts and levels with the original run. It does not claim that the complete responses are identical, since their requested output shapes differ.
The scheduler rounds sampled waits upward to at least one tick. Query times
sample events through floor(time * ticks_per_unit). Thus changing the query
grid and changing ticks_per_unit are different operations: the former changes
where this path is observed, while the latter can change quantization and the
path itself. The unequal gaps in [0, 1, 5, 20] are observation gaps, not
successive fixed integration steps.
With p=0 and no initial adopters, there is no innovation and no adopter to
supply imitation. The zero-count check tests this limiting case. The final
negative test requests engine unknown and requires NativeError with code
invalid_request; an unsupported engine must not silently select another
trajectory mechanism.
Check your understanding
Section titled “Check your understanding”- What level corresponds to 40 adopters in the original configuration?
- If
populationbecomes 200 whilemremains 250, how many level units does each agent represent? Does that change merely relabel an identical path? - Does omitting the observations at times zero and one mean the simulation starts with zero adopters at time five?
Compare your answers
250 * 40 / 100 = 100level units.- Each agent represents
250/200 = 1.25units. The population size also enters the stochastic hazard and changes the count process, so an identical path is not implied by this rescaling. - No. The process still evolves from its original initial condition. The sparse-grid assertion verifies the existing path’s later observations.
The changed-population case is an interpretation exercise; the canonical script runs the original 100-agent configuration and its stated validation cases.
Limitations
Section titled “Limitations”One seed checks a reproducible realization and bounded invariants. It does not estimate sampling variability, give prediction intervals, recover parameters or validate the model against an observed adoption series. Repeated simulations and a justified observation model would be needed for those different tasks.
Replay is qualified here for the identical request and installed runtime. Record the source revision, engine, parameters, population, seed, initial state and tick resolution with any result. The returned random-stream checkpoint is provenance; it is not by itself a complete simulation-resume artifact. This example does not exercise the separate event-boundary checkpoint interface or claim bitwise identity across future versions and platforms.
Continue with timed forcing to change rates during a path, or network demand and service to examine local exposure and completion delays. Those tutorials introduce their own controls and scientific contracts explicitly.