Expand description
§Syren
Syren is a parallel Rust framework for agent-based models. It stores agents in an archetype entity-component-system (ECS), runs systems over them through a deterministic stage scheduler on top of Rayon, and adds agent, environment, messaging, and optional GPU layers behind Cargo features.
This is the API reference. For a task-oriented introduction, worked examples, and the reproducibility guarantees, see the guide at https://ashvinperera.github.io/Syren-ABM-Framework/.
§Installation
Syren has no default features; enable the ones your model needs:
[dependencies]
syren = { version = "0.6.0", features = ["model"] }§Features
agents,environment— agent templates and typed model-wide values.model— theModelBuilderlayer (impliesagentsandenvironment).messaging— the four message specialisations.gpu,messaging_gpu— GPU state mirroring and compute dispatch.profiling— tracing spans and Chrome Trace output.
§Getting started
The first_model example is the smallest complete model: register a
component, build a population with ModelBuilder, run
a system whose access is derived from its query, draw per-entity randomness
from the run context with DetRng, and summarise with a Welford
reduction. Run it with cargo run --example first_model --features model.
§Determinism
A model run with the same version, features, seed, and initial state produces
the same trajectory regardless of thread count. Draw randomness through
DetRng::from_context, keyed on the run context and a salt, and set the
model seed with ModelBuilder::with_seed.
See the guide’s reproducibility chapter for the model author’s obligations.
§Stability
Syren is pre-1.0: patch releases keep the public API; minor releases may break
it with migration notes. Lower-level building blocks live in the advanced
module and may change with less notice.
Modules§
- advanced
- Advanced extension APIs that expose storage and scheduling internals.
- agents
- Domain-facing agent API layered over the raw ECS.
- environment
- Simulation-wide typed parameter store.
- gpu
- GPU Execution Backend
- messaging
- Typed, per-tick messaging for agent-based simulations.
- model
- Top-level model composition API.
- prelude
- Commonly used ECS types.
- space
- First-class agent spaces: discrete grids and continuous 2-D space.
Structs§
- Access
Sets - Declares the component access set of a system.
- Agent
Template Id - Compact identifier for an agent template registered in an agent registry.
- Batch
Column - One component column in a dynamically-typed spawn batch.
- Boundary
Channel Profile - Backend profile for one channel at a scheduler boundary.
- Boundary
Context - Engine-side surfaces a
BoundaryResourcemay interact with during a lifecycle hook. - Boundary
Handle - Short-lived typed reference to a boundary resource.
- Built
Query - An immutable, fully constructed ECS query description.
- Bundle
- Concrete implementation of a dynamic component bundle.
- Channel
Set - Bitset of
ChannelIDs for non-component scheduling dependencies. - Component
Desc - Describes a registered component type.
- Component
Registry - Mapping between Rust component types and compact
ComponentIDvalues. - Count
- Accumulator that counts the number of entities processed.
- DetRng
- Deterministic pseudo-random generator keyed by simulation coordinates.
- DotExport
- Display wrapper that renders a compiled scheduler plan as a Graphviz DOT graph.
- ECSManager
- Thread-safe entry point to the ECS world.
- ECSReference
- A non-owning handle granting access to ECS data.
- Entity
- Opaque, versioned identifier for an ECS entity.
- Entity
Location - Physical storage location of an entity within archetype storage.
- FnSystem
- A concrete
Systembacked by a function or closure. - MinMax
- Accumulator that tracks minimum and maximum values.
- Plan
Display - Display wrapper that renders a compiled scheduler plan as a text table.
- Query
Builder - Builder for constructing ECS query descriptions.
- Query
Component - One component column declared by a query.
- Query
Signature - Component signature used for query matching.
- Read
- Marker for a read-only component parameter in a tuple-based query.
- RunContext
- Deterministic execution context for the system currently running on this thread.
- Scheduler
- Stores systems, compiles them into conflict-free execution stages, and executes stages with Rayon parallelism.
- Signature
- Bitset representing a set of components.
- Span
Guard - A RAII guard that records a Chrome Trace complete event on drop.
- Span
Name - A span name; accepts
&'static str,String, orCow<'static, str>. - Spawn
Batch - Dynamically-typed batch payload for spawning many entities with one signature.
- Stage
- A logical execution stage used by
Schedulerduring planning. - Sum
- Accumulator that computes a floating-point sum.
- Welford
- Accumulator implementing Welford’s online algorithm for mean and variance.
- Write
- Marker for a mutable component parameter in a tuple-based query.
Enums§
- Activation
Order - Controls the order in which entities are visited by a system’s iteration.
- Arg
- Argument value for profiling spans.
- Attribute
Error - Aggregate error for attribute (component column) operations.
- Boundary
Access Failure - Reason a boundary-resource access failed.
- Channel
Order - Directional ordering constraint derived from channel produces/consumes.
- Command
- Represents a deferred ecs mutation command.
- ECSError
- Unified error type for the public ECS API.
- Execution
Error - Errors that occur during ECS execution and iteration.
- GPUAccess
Mode - Declares how a component buffer is accessed during GPU execution.
- Move
Error - Errors that can occur while moving an entity between archetypes.
- Profiling
Error - Errors returned by
try_init. - Registry
Error - Errors from the global component registry and its factories.
- Spawn
Error - High-level error for entity spawning.
- System
Backend - Execution backend for a system.
Constants§
- CHUNK_
CAP - Maximum number of rows per chunk.
Traits§
- Boundary
Resource - Trait for tick-lifecycle resources owned by
ECSManager. - Dynamic
Bundle - Type-erased container for component values.
- Entity
Query Param - Entity-aware variant of
QueryParam. - GPUPod
- Marker trait for component types that are safe to transfer to and from the GPU.
- GpuSystem
- GPU capability trait (feature-gated).
A GPU system is still a
System, but additionally provides WGSL. - Query
Param - Trait implemented by query parameter markers (
Read<T>,Write<T>) and tuples thereof to enable a single genericfor_eachentry point. - System
- A unit of executable logic operating on the ECS world.
Functions§
- flush_
thread - Flush this thread’s local event buffer into the global
collected_eventsstore. - init
- Initialize the profiler and ignore repeated initialization attempts.
- max_
workers - Returns Rayon’s current pool size.
- next_
arg - Add an argument to the next span created on this thread.
- register_
gpu_ component - Registers a component type as GPU-safe and eligible for GPU execution.
- shutdown
- Shut down the profiler and write the Chrome Trace JSON.
- span
- Create a profiling span.
- span_
fmt - Create a profiling span using format_args without forcing the caller to allocate manually.
- thread_
name - Assign a human-friendly thread name (shown in Perfetto/Chrome tracing).
- try_
init - Initialize the profiler and set output path.
- worker_
id - Returns the stable worker identifier for the calling thread.
Type Aliases§
- ArchetypeID
- Unique identifier for an archetype.
- BoundaryID
- Opaque identifier for a boundary resource registered on
ECSManager. - ChannelID
- Opaque identifier for a non-component scheduling channel.
- ChunkID
- Chunk index within an archetype.
- ComponentID
- Unique identifier for a component type.
- ECSResult
- Result type used by the ECS engine.
- EntityID
- Globally unique entity identifier encoded as a packed 64-bit value.
- GPUResourceID
- Unique identifier for a GPU resource.
- SystemID
- Unique identifier for a system.