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.1.tar.gz (7.2 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.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mc_dagprop-0.1.1.tar.gz
  • Upload date:
  • Size: 7.2 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.1.tar.gz
Algorithm Hash digest
SHA256 bc20be00b66f8cf29215585ad337b66762d1f6316857dfb1334c8b941f802c5a
MD5 56d76d253ac33e0ad03b22cb9ac48266
BLAKE2b-256 80bae46e1fbc13e2fe8d47bee0e852853a7b4c533b1ac71fc5443f80a5e4e019

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mc_dagprop-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e72c6113910a94052f06b5ae740cdb33e3084277c41c048cac147befc3d96ddc
MD5 6bdb995c4bf32684ea27d896efa37962
BLAKE2b-256 74e884aa4d391715e0172ad986089f0507d48e6d00446baae667b0f619b7fec6

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