Skip to main content

No project description provided

Project description

mc_dagprop

PyPI version Python Versions License

mc_dagprop is a fast, Monte Carlo–style propagation simulator for directed acyclic graphs (DAGs), written in C++ with Python bindings via pybind11.
It allows you to model timing networks (timetables, precedence graphs, etc.) and inject user‑defined delay distributions on links.


Features

  • Lightweight & high‑performance core in C++
  • Expose a simple Python API via poetry or pip
  • Define custom delay distributions per link‑type:
    • Constant (linear scaling)
    • Exponential (with cutoff)
    • Easily extendable for Weibull, Gamma, …
  • Single‑run (run(seed)) and batch‑run (run_many([seeds])) support
  • Returns a SimResult struct: realized times, link delays, and causal events

Installation

# with poetry
poetry add mc_dagprop

# or with pip
pip install mc_dagprop

Quickstart

from mc_dagprop import (
    SimulationTreeLink,
    SimContext,
    GenericDelayGenerator,
    Simulator,
)

# 1) Build your DAG timing context
events = [
    ("A", (0.0, 100.0,  0.0)),
    ("B", (10.0, 100.0, 0.0)),
    ("C", (20.0, 100.0, 0.0)),
]

# Map (source_idx, target_idx) → (link_idx, SimulationTreeLink)
links = {
    (0, 1): (0, SimulationTreeLink(minimal_duration=5.0, link_type=1)),
    (1, 2): (1, SimulationTreeLink(minimal_duration=7.0, link_type=1)),
}

# Precedences: target_idx → [(predecessor_idx, link_idx)]
precedence = [
    (1, [(0, 0)]),
    (2, [(1, 1)]),
]

ctx = SimContext(
    events=events,
    link_map=links,
    precedence_list=precedence,
    max_delay=60.0,
)

# 2) Configure your delay generator
gen = GenericDelayGenerator()
gen.add_constant(link_type=1, factor=1.5)     # 50% extra on each link
gen.add_exponential(link_type=2, lambda_=2.0, max_scale=5.0)  

# 3) Create simulator and run
sim = Simulator(ctx, gen)

# Single seeded run
result = sim.run(seed=42)
print("Realized times:", result.realized)
print("Link delays:",    result.delays)
print("Causal events:",  result.cause_event)

# Batch runs
batch = sim.run_many([1,2,3,4,5])

API Reference

SimulationTreeLink(minimal_duration: float, link_type: int)

Encapsulates the base duration and type id of a link.

SimContext(events, link_map, precedence_list, max_delay)

Container for your DAG:

  • events: list of (node_id, (earliest, latest, actual))
  • link_map: dict (src_idx, dst_idx) → (link_idx, SimulationTreeLink)
  • precedence_list: list of (target_idx, [(pred_idx, link_idx), ...])
  • max_delay: overall cap on delay propagation

GenericDelayGenerator

Configurable delay factory:

  • .add_constant(link_type, factor)
  • .add_exponential(link_type, lambda_, max_scale)
  • .set_seed(seed)

Simulator(context: SimContext, generator: GenericDelayGenerator)

  • .run(seed: int) → SimResult
  • .run_many(seeds: Sequence[int]) → List[SimResult]

SimResult

  • .realized: List[float] – event times after propagation
  • .delays: List[float] – per‑link injected delays
  • .cause_event: List[int] – which predecessor caused each event

Development

# clone & install dev dependencies
git clone https://github.com/yourorg/mc_dagprop.git
cd mc_dagprop
poetry install

# build & test
poetry run pytest

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

mc_dagprop-0.1.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

mc_dagprop-0.1.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file mc_dagprop-0.1.2.tar.gz.

File metadata

  • Download URL: mc_dagprop-0.1.2.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.4 Windows/10

File hashes

Hashes for mc_dagprop-0.1.2.tar.gz
Algorithm Hash digest
SHA256 87c122b054fc01e992d146f68c8f919fcc3d21509deb04eb36b970b81256b23d
MD5 5aa492e03cbf39bbe8a6b0859ca2cc2a
BLAKE2b-256 93e39ef209cbda9e7bc26e9800737257d601cb5097fdfa8a44331875c811a7f6

See more details on using hashes here.

File details

Details for the file mc_dagprop-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mc_dagprop-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.10.4 Windows/10

File hashes

Hashes for mc_dagprop-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 909f88f800fac1dcea6eef9e0dc5c52789cdaa6bfdef1d966456c3d1b6562908
MD5 d01e4bba2db32c07c394664d0f210adc
BLAKE2b-256 d4bac4246ecab141aa8ef835ae58b1b078615b35be99f401398c8db492f5bfdd

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