cadet.roles

Generic multi-connection server runtime.

What this is for:

Accepts many concurrent client connections, each with its own reader + delay line, all feeding ONE shared request queue in front of a single model. A scheduler (fifo default, or round_robin across clients) picks the next request; the model processes it and the reply goes back on the originating connection (through that connection’s reverse delay line, if any).

What it contains:
  • Request, _FifoScheduler, _RoundRobinScheduler.

  • ServerRuntime: accept loop + feeder-per-connection + scheduler loop; records per request the queue wait, inference time and queue depth at enqueue.

  • build_server().

How it fits into CADET:

cadet serve <config>; the server node’s scheduler field picks the policy. Per-request metrics are written to outputs/<experiment>/<app>/server_metrics.csv (used by the concurrent-load experiments).

System metrics. When metrics.collectors names them, this runtime also runs the per-node collectors (cadet.metrics.collectors) for its own node, around the serving loop, writing <collector>_<node>.csv into the run directory. If the energy collector is among them, each per-request record additionally carries that inference’s own energy: the collector is asked for the average power over the window the request was being processed in, on the same monotonic clock the record’s inference_s is measured on, so the attribution needs no second alignment step. Default is no collectors, and then nothing here changes.

class cadet.roles.server.Request(client_id, payload, transport)

Bases: object

One client request waiting for the model, tagged with its client id.

client_id
payload
transport
enqueue_time
depth
drops
class cadet.roles.server.PeerModels(config, node_name, seed=None, log=None)

Bases: object

The network models for each connection into one node, by its peer.

A node can be the far end of several paths at once - N sensors into one gateway, an ego and a roadside feed into one server - and those paths are not the same link. The server used to resolve one path and hand the same hops to every connection, varying only the RNG stream, so a cell whose uplinks differed could not be expressed: the difference was configured and then ignored.

Call it as (client_id, peer_ip) for a plain accept loop, or pass for_source() to cadet.core.transport.MultiConnectionEndpoint.serve() as its model_for, which is the fan-in form. Each connection gets fresh models with their own RNG stream, seeded from the experiment seed so a run stays reproducible.

Peers are told apart by address, which is what a connection carries. Two client nodes on one host therefore cannot be distinguished, and they share the first path declared into this node; that is logged rather than hidden, because the alternative - the client naming itself in band - is a wire change and this is not the place to make one.

for_source(source_id)

model_for for MultiConnectionEndpoint: "ip:port" in.

class cadet.roles.server.ServerRuntime(host, port, model_factory, app, logger, warmup=True, extra_processing_s=0.0, node=None, scheduler='fifo', metrics_path=None, inbound_max_pending=None, server_delay_mode='blocking', collectors=None, expect=1, protocol='tcp', mode='frame', inbound_block_at=None)

Bases: object

Multi-connection server: concurrent readers -> scheduler -> one model.

run()
Return type:

None

cadet.roles.server.build_server(config_path, overrides, run_index, model_dirs, logger=None, node_name=None, rep=0, bind_host=None)

Build a ServerRuntime for one run from a config file.

node_name selects which server node to bind (needed when a config has more than one server); it falls back to the first node with role server.

rep names the repetition, because the per-request metrics and the per-node metrics CSVs are written into that repetition’s run directory and two reps of one config would otherwise write to one file.

bind_host overrides the address this server listens on, leaving the config alone. It exists for a role whose container does not hold the address its peers use: a node on another machine is reached at that machine’s address and its container has to listen on one of its own. It cannot be a config override, because the config is hashed into the run id and the orchestrator and the role would then disagree about which run this is.

Parameters:
  • config_path (str)

  • overrides (List[str])

  • run_index (int)

  • model_dirs (List[str])

  • rep (int)

  • bind_host (str | None)

Generic client runtime (paper Fig. 1(b)).

What this is for:

Drives one client run through the pipeline stages (source, frame processing, transport, action translation, metric collection), delegating the per-stage behaviour to an app plugin’s client hooks.

What it contains:
How it fits into CADET:

cadet client <config> –node client [–run N] [–rep R] calls build_client() then ClientRuntime.run(). The app (e.g. examples.braking.flat.app) supplies control/encoding/metrics; the source is cadet.sources.carla.CarlaSource.

System metrics. When metrics.collectors names them, the runtime also runs the per-node collectors (cadet.metrics.collectors) for this client’s node, around the loop, writing <collector>_<node>.csv into the run directory. Default is no collectors, and then nothing here changes.

cadet.roles.client.client_outcome_file(node_name)

Return the outcome file name for a client node.

Return type:

str

cadet.roles.client.scene_timeout_for(config)

Return how long this config’s client should wait for the scene.

Return type:

float

class cadet.roles.client.RunContext(config, source, transport, run_id, rep, out_dir, log)

Bases: object

Handles shared between the runtime and the app for one run.

class cadet.roles.client.ClientRuntime(ctx, app, server_host, server_port, node=None, server_label=None, client_start='after_scenario', scene_timeout_s=120.0, collectors=None)

Bases: object

Runs the client loop until the app reports it is done.

Parameters:
  • ctx (RunContext)

  • client_start (str)

  • scene_timeout_s (float)

run()
Return type:

None

property node_name: str

This client’s node name, which its records are keyed by.

cadet.roles.client.build_client(config_path, overrides, run_index, rep, logger=None, node_name=None)

Build a ClientRuntime for one run from a config file.

node_name selects which client node this process is, the way cadet.roles.server.build_server() already did for servers. Without it every client process in a run believed it was the first client node: the flag existed on cadet client and was never passed through, so with N clients they shared one identity, one outcome file and one link report.

Parameters:
  • config_path (str)

  • overrides (List[str])

  • run_index (int)

  • rep (int)

Load generator role: N synthetic clients at a configured rate -> server(s).

What this is for:

Drives concurrent-load experiments. A load node describes N synthetic clients, a send rate, and an arrival process (constant or Poisson). Each client connects to every server node (fan-out) and sends frames in the reference-app wire format, recording round-trip latency. Combined with the server’s per-request metrics (queue wait vs load), this measures contention.

What it contains:
How it fits into CADET:

cadet load <config> --app-module examples.reference.app. Targets all server nodes in the config: clients=10, servers=[s] is 10->1; clients=1, servers=[s1,s2] is 1->2.

class cadet.roles.load.LoadRunner(config, csv_path, logger=None)

Bases: object

Runs a fleet of synthetic clients against the config’s server nodes.

run()
Return type:

None

cadet.roles.load.build_load(config_path, overrides, run_index, logger=None)

Construct a LoadRunner from a config file.

Parameters:
  • config_path (str)

  • overrides (List[str])

  • run_index (int)

Shared wiring for the client/server runtimes.

What this is for:

Small helpers both role runtimes use: select one run config from a file (overrides + sweep run index), look up nodes/links, and prepare the output directory (creating it and saving the resolved config alongside results).

What it contains:
How it fits into CADET:

Used by cadet.roles.client and cadet.roles.server. Output paths come only from the resolved config’s outputs section — never a curated results directory.

class cadet.roles.common.StopSignal

Bases: object

A role’s stop signal: first a flag its own loop acts on, then its exit.

The orchestrator stops a role with SIGTERM and escalates to SIGKILL after a grace. Python’s default action for SIGTERM ends the process at once, so a role that is stopped rather than finishing by itself never ran its own shutdown path: a server’s finally did not execute and its per-request metrics were never written. Measured: the braking app wrote server_metrics_*.csv because its app stops the loop itself after the brake, while the reference app, whose server waits for work until it is stopped, produced none at all.

install() makes the handler set a flag through on_stop; the loop notices on its next turn and unwinds normally. Raising from the handler would skip the same shutdown path by another route, which is also why the loop’s wait has to be bounded rather than indefinite.

finish() then hands the process back to the signal, so its exit status is the one a signalled process has. That is not cosmetic: the orchestrator reads a worker’s exit code during the active phase to tell a guard that finished its job (code 0 - the braking server is single-shot by design) from one that died under it (non-zero - node exited unexpectedly). A server that flushed its records and then exited 0 would make an operator’s kill look like a clean finish, which is exactly the failure the lifecycle matrix exists to catch.

Signals can only be installed from the main thread, and a role process is one process per role, so this is used from the role’s own run. Off the main thread (a test driving a runtime in-process) install() is a no-op rather than an error, and finish() then has nothing to do.

install(on_stop, log=None)

Install the handler for SIGTERM and SIGINT.

Return type:

None

Parameters:

on_stop (Callable[[], None])

finish()

Exit as a signalled process, now that the records are written.

Return type:

None

cadet.roles.common.select_run_config(path, overrides, run_index)

Load + override + expand a config and return the run_index-th run.

Returns (config, run_id_base) where run_id_base is the config hash (the per-repetition -r<rep> suffix is added by the caller).

Return type:

Tuple[Config, str]

Parameters:
  • path (str)

  • overrides (List[str])

  • run_index (int)

cadet.roles.common.node_by_role(config, role)

Return the first node with role (or None).

Parameters:

Return the first link whose to endpoint is node_name (or None).

Parameters:
  • config (Config)

  • node_name (str)

cadet.roles.common.output_dir(config, run_id)

Return the output directory path for a run (does not create it).

Directory = outputs.root/<outputs.naming formatted>. Kept pure so the orchestrator can locate a run’s outputs (e.g. for resume) without side effects.

Return type:

str

Parameters:
  • config (Config)

  • run_id (str)

cadet.roles.common.prepare_output_dir(config, run_id)

Create the output directory for this run and save the resolved config.

Directory = output_dir(). The resolved config is written as config.yaml next to the results.

Return type:

str

Parameters:
  • config (Config)

  • run_id (str)