Skip to main content

Delta Cycle

Project description

Delta Cycle

DeltaCycle is a Python library for discrete event simulation (DES).

A simulation has two components: a collection of variables, and a collection of processes. Variables represent the instantaneous state of the simulation. They may be organized into arbitrary data structures. Processes define how that state evolves. They may appear concurrent, but are scheduled sequentially.

Process execution is subdivided into a sequence of slots. Slots are assigned a monotonically increasing integer value, called time. Multiple processes may execute in the same slot, and therefore at the same time. The term "delta cycle" refers to a zero-delay subdivision of a time slot. It is the clockwork mechanism behind the illusion of concurrency.

Read the docs! (WIP)

Documentation Status

Features

  • Loop: task scheduler
  • Tasks: coroutine wrapper
  • Synchronization Primitives:
    • Events
    • Locks
    • Semaphores
    • Queues
  • Structured concurrency:
    • Task groups
    • Task cancellation
    • Task dependencies
    • Exception handling
  • Variables:
    • Singular
    • Aggregate
    • Variable dependencies

Example

The following code simulates two clocks running concurrently. The fast clock prints the current time every time step. The slow clock prints the current time every two time steps.

>>> from deltacycle import create_task, now, run, sleep

>>> async def clock(name: str, period: int):
...     while True:
...         print(f"{now()}: {name}")
...         await sleep(period)

>>> async def main():
...     create_task(clock("fast", 1))
...     create_task(clock("slow", 2))

>>> run(main(), until=7)
0: fast
0: slow
1: fast
2: slow
2: fast
3: fast
4: slow
4: fast
5: fast
6: slow
6: fast

Installing

DeltaCycle is available on PyPI:

$ pip install deltacycle

It supports Python 3.12+

Developing

DeltaCycle's repository is on GitHub:

$ git clone https://github.com/cjdrake/deltacycle.git

It is 100% Python, and has no runtime dependencies. Development dependencies are listed in requirements-dev.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deltacycle-0.10.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deltacycle-0.10.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file deltacycle-0.10.0.tar.gz.

File metadata

  • Download URL: deltacycle-0.10.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for deltacycle-0.10.0.tar.gz
Algorithm Hash digest
SHA256 44a01e5c8c1f8300d6a26f9cbe3fdbe12728ecce309ee6ebd1fccbf8002660aa
MD5 66356185e02a86994742ef17b21d7820
BLAKE2b-256 525ae1cf42343b797630fc4eafb33bc2a38fdd905de3723339a7a4b3b85700ea

See more details on using hashes here.

File details

Details for the file deltacycle-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for deltacycle-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e357aa6ae5b3327bb052ed426790e84025ccbc86dac0a5c532c89ea96e365b4
MD5 59412b0e630f163194496b3f4dd0cf5e
BLAKE2b-256 85522cc6435d09041f6ea9125a8c342ce7dfa75ace6ab7a12bdfe9ead8a08443

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page