Skip to main content

Delta Cycle

Project description

Delta Cycle

DeltaCycle is a Python library for discrete event simulation (DES). Processes are described by async def coroutine functions, and concurrency is implemented using async / await statements.

In DES, the simulation is subdivided into sequential slots. Each slot is assigned a monotonically increasing integer value, called "time". Multiple events may happen during each time slot. Those events will trigger tasks that execute in zero time, which may schedule additional events for present or future time slots. The term "delta cycle" refers to a zero-delay subdivision of a time slot.

DeltaCycle implements a fixed-priority task scheduling algorithm. This allows fine-grain control over the task execution order from simultaneous events.

Read the docs! (WIP)

Documentation Status

Features

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.7.0.tar.gz (19.9 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.7.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for deltacycle-0.7.0.tar.gz
Algorithm Hash digest
SHA256 8caacba2b7cf0d162bbef3523ff3b5b4d9aaf004b7f32c1681374017657fdb52
MD5 9e2d6f9ec4ed07e4fb38998b73cc7395
BLAKE2b-256 fa592c36a97d47f56ac8d8d4240116d7fe2f4a65bcbe7be57523aa9246e17d1f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: deltacycle-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for deltacycle-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59f5a3422f1a7fccbf0bd6a6f74c6e2c05b3e52bb93f5046c34cebcc684ca793
MD5 fc4acdb2f5578d87c86e7a14d3d1ae97
BLAKE2b-256 fefe6b95d7daed87e78aef23aec029ef580dac3ea23b042ecd6ae06f5c18a2e7

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