Separate network demand from completed adoption
An agent’s demand for adoption and its completed adoption can occur at different times. This tutorial separates those events using a small network with one service slot. It first checks graph-mediated spread, then uses a separate queue fixture to verify service completion and resource accounting. Both fixtures are synthetic.
Learning outcomes
Section titled “Learning outcomes”You will distinguish local network exposure from population adoption share, explain why pending agents do not transmit, and compare connected and disconnected graphs. You will reconstruct FIFO completion times with a simple independent recurrence and interpret the denominator of resource utilization.
Prerequisites
Section titled “Prerequisites”Use the native development environment and read the seeded Bass simulation tutorial. You need basic Python mappings and the distinction between a rate and a waiting time. The example downloads no graph or empirical dataset.
The call uses model key bass and engine kairos_network. The engine introduces
the graph, agent states and service resource; choosing a host language does not
select those mechanisms. The two fixtures deliberately isolate different
contracts:
| Fixture | Demand mechanism | Initial adoption | Service configuration |
|---|---|---|---|
| Three-agent chain | p=0, q=3; edges [0,1] and [1,2] |
Agent 0 is already adopted | One slot, five ticks per service |
| Queue accounting | p=1e12, q=0; no edges |
No initial adopters | The same one-slot, five-tick resource |
Edges are undirected here because the request does not enable directed mode.
Agent indices are zero-based. ticks_per_unit=1 makes one tick equal one
synthetic time unit; service_ticks=5 therefore lasts five such units. The
innovation and imitation coefficients have inverse-time units. Both fixtures
set population=3 and m=3, so counts and scaled levels coincide numerically.
-
Run the checked example from the repository root:
Terminal window .venv-native/bin/python -I examples/native_network.py -
Follow the chain’s requests and completions. Verify that agent 2 requests adoption only after agent 1 completes its adoption.
-
Remove all edges while leaving the chain fixture’s zero innovation rate and initial adopter unchanged. Check that no further requests or completions occur.
-
In the separate high-innovation fixture, reconstruct each service start and completion from the request times, then check the resource-accounting totals.
"""Check contagion, service completion and FIFO resource accounting.
One synthetic time unit equals one scheduler tick so the five-tick service timeis visible. The separate queue fixture uses a very high innovation rate to exposethe scheduler's minimum one-tick delay; it is not a calibrated adoption model."""
import json
from innovate import NativeError, execute
def main() -> None: """Verify graph-dependent spread, independent service timing and graph errors.""" times = [0.0, 5.0, 20.0, 100.0] parameters = {"p": 0.0, "q": 3.0, "m": 3.0} options = { "engine": "kairos_network", "seed": 42, "population": 3, "edges": [[0, 1], [1, 2]], "initial_agents": [0], "capacity": 1, "service_ticks": 5, "ticks_per_unit": 1, } request = {"inputs": {"time": times}, "parameters": parameters, "simulation_options": options} response = execute("simulate_model", "bass", **request) chain = response["result"] assert response == execute("simulate_model", "bass", **request) assert chain["counts"][0] == 1 and chain["counts"][-1] == options["population"] assert all(agent["state"] == "adopted" for agent in chain["agents"])
# With p=0, node two can request only after its sole neighbor one adopts. completions = {event["agent"]: event["tick"] for event in chain["completions"]} requests = {event["agent"]: event["tick"] for event in chain["requests"]} assert set(completions) == set(requests) == {1, 2} assert requests[2] > completions[1] assert chain["counts"][-1] == len(options["initial_agents"]) + len(completions) disconnected = execute("simulate_model", "bass", **{**request, "simulation_options": {**options, "edges": []}})[ "result" ] assert disconnected["counts"] == [1] * len(times) assert disconnected["requests"] == disconnected["completions"] == []
# A second fixture creates demand without peers and queues three agents. queue_options = {**options, "edges": [], "initial_agents": []} queued = execute( "simulate_model", "bass", inputs={"time": [0.0, 5.0, 20.0]}, parameters={"p": 1e12, "q": 0.0, "m": 3.0}, simulation_options=queue_options, )["result"] assert queued["counts"] == [0, 0, 3], "A pending request is not yet adoption." assert len(queued["requests"]) == len(queued["completions"]) == 3 free_at = 0 expected_occupied_ticks = 0 expected_wait_ticks = 0 for demand, completion in zip(queued["requests"], queued["completions"], strict=True): # Independent single-server FIFO recurrence; no native queue helper used. start = max(demand["tick"], free_at) free_at = start + queue_options["service_ticks"] assert completion["agent"] == demand["agent"] assert completion["tick"] == free_at expected_occupied_ticks += queue_options["service_ticks"] expected_wait_ticks += start - demand["tick"] metrics = queued["resource_metrics"] assert metrics["peak_in_service"] == queue_options["capacity"] assert metrics["occupied_slot_ticks"] == expected_occupied_ticks assert metrics["admitted_wait_ticks"] == expected_wait_ticks assert metrics["configured_slot_ticks"] == metrics["horizon_ticks"] * queue_options["capacity"] assert metrics["idle_slot_ticks"] + metrics["occupied_slot_ticks"] == metrics["configured_slot_ticks"] assert metrics["over_capacity_slot_ticks"] == 0
try: execute("simulate_model", "bass", **{**request, "simulation_options": {**options, "edges": [[0, 0]]}}) except NativeError as error: invalid_edges_rejected = error.code == "invalid_request" else: invalid_edges_rejected = False assert invalid_edges_rejected, "An undirected self-loop must fail the native graph contract."
print( json.dumps( { "chain_counts": chain["counts"], "disconnected_counts": disconnected["counts"], "fifo_completions": [event["tick"] for event in queued["completions"]], "invalid_edges_rejected": invalid_edges_rejected, }, sort_keys=True, ) )
if __name__ == "__main__": main()The script repeats the original chain request to check same-runtime replay. It
also supplies an invalid self-loop and requires a native invalid_request
error. The network implementation
defines the graph validation, local exposure and completion semantics described
below.
Expected results
Section titled “Expected results”The script prints this output after its assertions pass:
{"chain_counts": [1, 1, 3, 3], "disconnected_counts": [1, 1, 1, 1], "fifo_completions": [6, 11, 16], "invalid_edges_rejected": true}The chain begins with one adopted agent and reaches all three by the sampled
time 20. The disconnected graph remains at its initial count of one. In the
separate queue fixture, the three completion ticks are 6, 11 and 16; its sampled
counts are [0, 0, 3] at times [0, 5, 20]. Pending demand is excluded from
those adoption counts.
Interpretation
Section titled “Interpretation”Use the local exposure denominator
Section titled “Use the local exposure denominator”For the unweighted, homogeneous network in this fixture, a susceptible agent’s
request hazard is p + q * (adopted neighbors / degree). An agent with no
neighbors has zero imitation contribution. The denominator is that agent’s
degree, not the whole population of three. This differs from the homogeneous
population process, which uses the population share n/N.
At the start, agent 1 has two neighbors, of whom only agent 0 is adopted. Its
hazard is therefore 0 + 3 * (1/2) = 1.5 per time unit. Agent 2 has one
neighbor, agent 1, which has not adopted, so its initial hazard is zero. A
queued or in-service agent still does not transmit. Once agent 1 completes,
agent 2’s adopted-neighbor fraction becomes one and its hazard becomes three.
The script verifies the ordering of those events, not just the final count.
With all edges removed and p=0, there is neither innovation nor local
imitation. The initial adopter remains, but no new request can start. This
comparison isolates a mechanism supplied in the simulation; it is not an
estimated effect of social contact in an observed population.
Count service time independently
Section titled “Count service time independently”In the queue fixture, a very high innovation rate makes the scheduler’s minimum one-tick waiting delay visible. It is a test input rather than a calibrated adoption coefficient. All three requests must pass through the single slot. For each request, the independent FIFO calculation is:
start = max(request_tick, previous_completion_tick)
completion = start + service_ticks
The observed completion sequence implies these service intervals:
| Completion order | Service starts | Service completes | Occupied slot-ticks |
|---|---|---|---|
| First | 1 | 6 | 5 |
| Second | 6 | 11 | 5 |
| Third | 11 | 16 | 5 |
Through time 20, this resource provides 20 * 1 = 20 configured slot-ticks,
of which 15 are occupied and five idle. Its utilization over that horizon is
15/20 = 0.75. The final adoption fraction is 3/3 = 1. These have different
denominators and answer different questions: service occupancy over time and
adoption status at the endpoint. Neither is a probability that an individual
will request service.
The script separately checks admitted waiting time, peak simultaneous service, configured capacity, and zero over-capacity slot-ticks. Counts include adopted agents; the service metrics account for the resource used to reach that state.
Check your understanding
Section titled “Check your understanding”- Why does agent 1’s initial imitation hazard use
1/2rather than1/3? - If agent 1 has requested service but is still waiting, can it enable agent 2 to request through imitation in this fixture?
- Why can the queue fixture have 100% final adoption but 75% resource utilization?
Compare your answers
- One of agent 1’s two neighbors is adopted. The local exposure denominator is its degree; the total number of agents is not used in that fraction.
- No. The network engine counts an agent as adopted, and able to transmit, only after service completion. The initial adopter is already in that state.
- All three agents have completed by time 16, giving an adoption fraction of one at time 20. The resource was occupied for only 15 of the 20 available slot-ticks across the observation horizon.
Limitations
Section titled “Limitations”This small unweighted, undirected graph and one-slot queue do not qualify every network option, priority policy, abandonment rule or time-varying graph. The FIFO recurrence relies on the equal-priority, fixed-service, single-slot configuration used here. A different configuration needs its own oracle.
One seed tests replay and concrete invariants, not the distribution of outcomes across repeated simulations. The graph and coefficients are assumed, and the large innovation coefficient in the queue test is deliberately artificial. The example does not infer a network, estimate contagion, measure causal peer effects or validate real service demand. Preserve engine, graph order, rates, initial state, time resolution and runtime identity when recording an experiment.