How toto171/loom works
1. What Loom is
Loom is a Python 3.12+ framework for composing a vehicle from swappable subsystems, checking those subsystem contracts, simulating the composed vehicle against a plant model, and generating safety evidence artifacts. The repository is organized around a single end-to-end pipeline, not a standalone app server or a library of unrelated utilities.
2. Primary inputs and configuration
The core input is a vehicle composition YAML file in spec/ that references module contracts, plant selection, and scenario/fault configuration. Module-specific contract files live under modules/*/contract*.yaml; plant implementations live under plant/*/plant.py; scenarios live under scenarios/*.yaml. Schema definitions in spec/schema/ define the two main configuration domains: vehicle composition and module contracts.
3. Composition and resolution layer
The loom.compose package is the first major subsystem. It loads the vehicle composition, resolves module references, and produces a composed model. This layer is the boundary where the declared vehicle architecture is turned into an executable configuration that later stages can validate, simulate, and analyze.
4. Contract and static-checking layer
The loom.contracts package models each module’s contract and performs static composition checks. The checker enforces things like producer uniqueness, signal resolution, units consistency, and timing/assume-guarantee constraints. It also encodes an explicit license policy for default modules, so legal metadata is treated as part of the architecture rather than an afterthought.
5. Runtime execution core
The execution entrypoint is loom.run.execute_run, which the CLI and dashboard both reuse. The main lifecycle is: compose → validate → check → gate → simulate → assure. This is the central data flow of the repo; every user-facing path ultimately converges here.
6. Orchestrators and bus abstraction
Loom separates orchestration from the bus transport. The loom.orchestrator package defines the control loop and multiple orchestrator backends: in-process, Compose/KUKSA, and Ankaios. The loom.bus package provides the transport abstraction, with a shim/in-process bus and a KUKSA-backed bus. This boundary is important because it lets the same simulation/control loop run either locally or against distributed infrastructure.
7. Modules and closed-loop vehicle behavior
The reference modules in modules/ are the swappable subsystems being composed: BMS, powertrain, ADAS, HMI, and body. In the default closed loop, the driver target speed propagates through powertrain commands into the plant, while BMS tracks state of charge and reacts to plant state. These modules are intentionally split from the plant so the architecture can show how contract changes affect composition without changing the underlying physics model.
8. Plant models
The loom.plant package loads the plant implementation selected by the vehicle spec. The repository includes at least two plant families: a longitudinal plant and a higher-fidelity Motoquant plant. Plant choice changes simulation fidelity and dynamics but does not require changing module contracts, which is a key separation in the architecture.
9. Simulation, stimuli, and fault injection
The loom.sim package contains the execution-time mechanics around scenarios, stimulus generation, traces, and faults. Scenario files drive the simulated driving conditions, while fault injection can model dropout, stuck values, latency, and crashes. This layer feeds the runtime monitors and produces trace artifacts for later reporting.
10. Monitoring and safety gating
Runtime checks live in loom.monitors and loom.safety. Monitors evaluate predicates over observed runtime signals, and the safety gate blocks below-line swaps unless revalidation is explicitly requested. This is the repository’s main safety boundary: it separates allowed “above the line” changes from changes that require renewed evidence.
11. Assurance artifacts
The loom.assurance package generates evidence artifacts during or after a run. The README indicates three main outputs: per-module SBOMs, an aggregate vehicle SBOM, and a GSN assurance-case skeleton. These are written into each runs/<id>/ directory along with trace and report data, making the run directory the primary evidence bundle for a composition.
12. Deployment path
The loom.deploy package generates an Eclipse Ankaios workload manifest for composed systems. This is a separate output path from simulation: it translates the same composed vehicle model into deployment-oriented artifacts rather than runtime evidence. That makes deployment another first-class boundary in the architecture.
13. Dashboard and operational surface
The dashboard/ app is a FastAPI-based UI with HTML templates for composing vehicles, launching runs, and inspecting results. It is a thin operational frontend over the same execution core used by the CLI, so it does not define a separate business path; it visualizes and drives the same pipeline.
14. Persistence and baseline state
Runs are persisted under runs/ and the safety baseline is committed in locks/*.lock.json. The committed lock file is architecturally important because it prevents the safety gate from being reset simply by deleting local run outputs. In other words, the repository distinguishes transient evidence from versioned safety state.
15. How to think about the architecture diagram
A good diagram for this repo should show a left-to-right flow from composition spec and contracts, through static checking and gating, into simulation with modules, bus, orchestrator, and plant, and then out to monitoring, SBOM/GSN assurance artifacts, and deployment output. The key cross-cutting boundaries are: contract vs runtime, orchestrator vs bus, modules vs plant, and transient run evidence vs committed lock/baseline state.
Main entry points: _loop.py Control loop · run.py Run pipeline · loader.py Plant loader · vehicle.example.yaml Vehicle spec
Components 32
Inputs & specs
Repository files that declare vehicles, contracts, scenarios, and schemas.
- Vehicle spec · Top-level vehicle composition and subsystem selection.
spec/vehicle.example.yaml - Comp schema · Vehicle composition schema definitions.
spec/schema/composition.schema.json - Contract schema · Module contract schema definitions.
spec/schema/contract.schema.json
Core pipeline
Composition, checking, orchestration, simulation, and runtime control.
- Contract loader · Loads module contracts from YAML.
loom/contracts/loader.py - Contract model · Represents module contracts and related metadata.
loom/contracts/model.py - Static checks · Enforces uniqueness, resolution, units, timing, and policy rules.
loom/contracts/checker.py - Compose loader · Loads the vehicle composition and module references.
loom/compose/loader.py - Resolver · Resolves referenced modules into a composed model.
loom/compose/resolve.py - Composed model · Executable vehicle configuration used by later stages.
loom/compose/model.py - Run pipeline · Main execution entrypoint that drives compose, validate, check, gate, simulate, and assure.
loom/run.py - Control loop · Shared orchestration loop for runtime execution.
loom/orchestrator/_loop.py - Safety gate · Blocks below-line swaps unless revalidation is requested.
loom/safety/gate.py - Monitors · Evaluates predicates over observed runtime signals.
loom/monitors/engine.py
Runtime backends
Swappable modules, buses, plants, and deployment targets.
- Bus API · Transport abstraction for module communication.
loom/bus/base.py - Shim bus · In-process bus implementation.
loom/bus/shim.py - KUKSA bus · KUKSA-backed bus implementation.
loom/bus/kuksa.py - In-process orch · Local orchestrator backend.
loom/orchestrator/inprocess.py - Compose orch · Compose/KUKSA orchestrator backend.
loom/orchestrator/compose.py - Ankaios orch · Distributed Ankaios orchestrator backend.
loom/orchestrator/ankaios.py - Modules · Reference vehicle subsystems such as BMS, powertrain, ADAS, HMI, and body.
modules - Plant loader · Selects and loads the configured plant implementation.
loom/plant/loader.py - Longitudinal · Lower-fidelity longitudinal plant.
plant/longitudinal/plant.py - Motoquant · Higher-fidelity Motoquant plant.
plant/motoquant/plant.py - Faults · Fault injection for dropout, stuck values, latency, and crashes.
loom/sim/faults.py - Scenario · Driving scenario and stimulus selection.
loom/sim/scenario.py
Outputs & ops
Safety evidence, run artifacts, dashboard, and persisted state.
- Trace · Execution traces produced by runs.
loom/sim/trace.py - SBOMs · Per-module and aggregate SBOM evidence.
loom/assurance/sbom.py - GSN case · Assurance-case skeleton generation.
loom/assurance/gsn.py - Deploy manifest · Generates Ankaios workload manifests from the composed vehicle.
loom/deploy/ankaios.py - Dashboard · Operational frontend for composing, launching runs, and inspecting results.
dashboard/app.py - Run artifacts · Per-run evidence bundle containing traces, reports, and generated artifacts.
- Safety lock · Committed safety baseline that persists across local run cleanup.
locks/toy-ev-l7.lock.json
Connections 33
- Vehicle spec → Compose loader: loads · The vehicle spec is parsed by the composition loader.
- Vehicle spec → Plant loader: selects · The vehicle spec selects the plant implementation.
- Vehicle spec → Scenario: references · The vehicle spec can reference scenarios and faults.
- Comp schema → Compose loader: validates · Composition schema constrains vehicle YAML.
- Contract schema → Contract loader: validates · Contract schema constrains module contract YAML.
- Contract loader → Contract model: builds · Contract files are loaded into the contract model.
- Contract model → Static checks: checks · The checker operates on the loaded contract model.
- Compose loader → Resolver: hands off · Loaded composition is resolved into concrete module references.
- Resolver → Composed model: produces · Resolution yields the composed vehicle model.
- Composed model → Static checks: static check · The composed model is checked against module contracts.
- Composed model → Run pipeline: inputs · The run pipeline consumes the composed model.
- Run pipeline → Control loop: drives · The run pipeline invokes the shared control loop.
- Control loop → Bus API: uses · The control loop communicates through the bus abstraction.
- Bus API → Shim bus: implements · Shim bus is one transport backend.
- Bus API → KUKSA bus: implements · KUKSA bus is another transport backend.
- Control loop → In-process orch: backend · In-process orchestration is one backend.
- Control loop → Compose orch: backend · Compose/KUKSA orchestration is one backend.
- Control loop → Ankaios orch: backend · Ankaios orchestration is one backend.
- Control loop → Modules: executes · Modules participate in the closed-loop control execution.
- Modules → Plant loader: commands · Module outputs drive the plant interface through the runtime loop.
- Plant loader → Longitudinal: loads · The loader can select the longitudinal plant.
- Plant loader → Motoquant: loads · The loader can select the Motoquant plant.
- Scenario → Faults: combines · Scenario execution can include injected faults.
- Faults → Trace: records · Faulted execution contributes to trace artifacts.
- Control loop → Monitors: observes · Runtime signals are evaluated by monitors.
- Monitors → Safety gate: gates · Monitor outcomes feed the safety gate.
- Run pipeline → SBOMs: emits · Runs generate SBOM evidence.
- Run pipeline → GSN case: emits · Runs generate assurance-case artifacts.
- Run pipeline → Deploy manifest: exports · The same composed model can be translated into deployment artifacts.
- Run pipeline → Run artifacts: persists · Run execution writes artifacts into the run directory.
- Trace → Run artifacts: stored in · Traces become part of the run evidence bundle.
- Dashboard → Run pipeline: reuses · The dashboard drives the same execution core as the CLI.
- Safety lock → Safety gate: baseline · Committed locks provide persistent safety baseline state.