μSim API Reference
usim package provides access to the entire μSim API in one
convenient, flat namespace.
Logically, the API can be divided into different topics.
usim.typing allows for type annotations to statically
Starting a Simulation
Simulations in μSim are always defined based on a number of initial root
which may branch out to more activities.
A simulation is started by calling
usim.run(), passing in its
activities and optionally the time window to simulate.
- usim.run(*activities: Coroutine, start: float = 0, till: Optional[float] = None)
Run a simulation from the initial
activities – initial activities of the simulation
start – initial time of the simulation
till – time at which to terminate the simulation
μSim provides a number of primitives to check or wait for specific points in time of a simulation.
Expressions define points in time or delays. For example,
await (time + 20)delays for 20 time units.
A point in time indefinitely far into the future.
A point in time indistinguishable from the current moment.
In addition, recurring actions can be repeated at specific delays or intervals
async for blocks.
Branching and Multitasking
Scopethat is forcefully closed if a specific notification triggers.
Exception that propagates all exceptions from child activities at once; also occurs if only a single child activity fails. Never includes an exception raised in the scope itself.
μSim allows to model any boolean that may change at a later time
These can be combined and negated to derive new
It is common for types to return a
Condition instead of
Simulations commonly revolve around resources which are produced/consumed, blocked or waited for. μSim implements a range of generic, ready-to-use resources for various use-cases.
Supply of named resources which can be temporarily borrowed or permanently produced/consumed.
Fixed supply of named resources which can be temporarily borrowed.
Current, expected or desired levels of resources.
Exception raised when an attempt to
Common Building Blocks
- Working with simulated time
- Branching Tasks and Concurrent Exceptions
- Synchronisation via Conditions
- Sharing State
- Resource Modelling
- Concurrency Utilities and Patterns
- usim.typing module