Fast, Monte Carlo DAG propagation simulator with user‑defined delay distributions
Project description
mc_dagprop
mc_dagprop is a fast propagation toolkit for directed acyclic graphs (DAGs), with a C++ Monte Carlo engine and a Python analytic engine.
The package provides two propagation modes:
- Monte Carlo simulation based on sampled edge delays.
- Analytic propagation of full discrete probability mass functions (PMFs).
Both engines share the same event/activity DAG model and expose aligned naming:
MonteCarloPropagator and AnalyticPropagator.
Background
mc_dagprop was developed as part of the SORRI project at the Institute for Transport Planning and Systems (IVT), ETH Zurich. The SORRI project— Simulation-based Optimisation for Railway Robustness Improvement —focuses on learning real-life constraints and objectives to determine timetables optimized for robustness interactively. This research is supported by the SBB Research Fund, which promotes innovative studies in transport management and the future of mobility in Switzerland.
Features
- High-performance Monte Carlo core in C++ via pybind11.
- Deterministic analytic propagator for full event-time PMFs.
- Custom per-activity-type Monte Carlo delay distributions:
- Constant
- Exponential
- Gamma
- Empirical absolute/relative
- Single-run (
run(seed)) and batched (run_many(seeds)) Monte Carlo APIs. - Shared DAG concepts (
Event,Activity,DagContext) and unified naming. - Optional global
max_delaycap available in both engines.
Note: For Monte Carlo, configuring multiple distributions for the same
activity_typeoverrides previous settings. Keep exactly one distribution per type.
Installation
This library requires Python 3.12 or newer.
# with poetry
poetry add mc-dagprop
# or with pip
pip install mc-dagprop
Quickstart (Monte Carlo)
from mc_dagprop import (
Activity,
DagContext,
Event,
EventTimestamp,
GenericDelayGenerator,
MonteCarloPropagator,
)
# 1) Build your DAG timing context
events = [
Event("A", EventTimestamp(0.0, 100.0, 0.0)),
Event("B", EventTimestamp(10.0, 100.0, 0.0)),
]
activities = {
(0, 1): Activity(idx=0, minimal_duration=60.0, activity_type=1),
}
precedence = [
(1, [(0, 0)]),
]
ctx = DagContext(
events=events,
activities=activities,
precedence_list=precedence,
max_delay=1800.0,
)
# 2) Configure a delay generator (one distribution per activity_type)
gen = GenericDelayGenerator()
gen.add_constant(activity_type=1, factor=1.5)
# 3) Run propagation
sim = MonteCarloPropagator(ctx, gen)
result = sim.run(seed=42)
print("Realized times:", result.realized)
print("Edge durations:", result.durations)
print("Causal predecessors:", result.cause_event)
Simulator remains available as a compatibility alias of
MonteCarloPropagator.
Analytic Propagator
Use AnalyticPropagator to propagate discrete delay PMFs deterministically.
from mc_dagprop import (
AnalyticContext,
Event,
EventTimestamp,
OverflowRule,
UnderflowRule,
create_analytic_propagator,
)
from mc_dagprop.analytic import AnalyticActivity, exponential_pmf
step = 1.0
delay_pmf = exponential_pmf(scale=10.0, step=step, start=0.0, stop=300.0)
events = (
Event("A", EventTimestamp(0.0, 10.0, 0.0)),
Event("B", EventTimestamp(0.0, 20.0, 0.0)),
)
activities = {
(0, 1): (0, AnalyticActivity(idx=0, pmf=delay_pmf)),
}
precedence = (
(1, ((0, 0),)),
)
ctx = AnalyticContext(
events=events,
activities=activities,
precedence_list=precedence,
step=step,
underflow_rule=UnderflowRule.TRUNCATE,
overflow_rule=OverflowRule.TRUNCATE,
max_delay=None,
)
sim = create_analytic_propagator(ctx)
pmfs = sim.run()
print(pmfs[1].pmf.values)
print(pmfs[1].pmf.probabilities)
Notes:
stepis the shared PMF grid spacing for the analytic context.create_analytic_propagator(..., validate=True)validates PMF alignment, mass consistency, indices, and DAG acyclicity before running.- PMF binary operations (
convolveandmaximum) use numerically stable intermediates (np.longdouble) and a post-operation mass correction. This prevents tiny probabilities from being lost to cumulative floating-point drift in deep analytic propagation chains. max_delaymirrors Monte Carlo semantics by capping each event atmin(latest, earliest + max_delay).
Package structure
mc_dagprop.monte_carlo— compiled Monte Carlo core and delay generator.mc_dagprop.analytic— pure-Python PMF types, distributions, and propagator.mc_dagprop.types— shared typed aliases.demo/— runnable examples for analytic and Monte Carlo usage.
Install the distribution as mc-dagprop and import from mc_dagprop:
from mc_dagprop import Simulator
Building wheels for Windows, macOS, and Linux
Cross-platform wheel builds are configured through GitHub Actions in
.github/workflows/build-wheels.yml using cibuildwheel.
- Windows (
windows-latest) - macOS (
macos-latest,x86_64andarm64) - Linux (
ubuntu-latest)
To run a local source build without the CI workflow:
python -m pip install --upgrade build
python -m build
References
[^1]: Büker, T., et al. (2018). Delay propagation in stochastic railway networks. [^2]: Subsequent extensions used in SORRI for timetable robustness analysis. [^3]: De Wilde, B., et al. Event-based simulation approaches for railway delay analysis.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mc_dagprop-0.9.1.tar.gz.
File metadata
- Download URL: mc_dagprop-0.9.1.tar.gz
- Upload date:
- Size: 47.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d4be21316ed2cbb221d8147756c5dfd56995a6a3a372085013aba6992e4c40e
|
|
| MD5 |
45807e4189ff2e52542eade120aa2997
|
|
| BLAKE2b-256 |
a4440fc82f12e49c9bbafe8a07511adbecfcac24e63e7f43915fad874dd378cc
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1.tar.gz:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1.tar.gz -
Subject digest:
8d4be21316ed2cbb221d8147756c5dfd56995a6a3a372085013aba6992e4c40e - Sigstore transparency entry: 976406400
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mc_dagprop-0.9.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: mc_dagprop-0.9.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 181.5 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c89a16d6a1f73610aa07ab8c23cac97dc396043382c66b26f1ba9b351ab99ee
|
|
| MD5 |
baf6bbf575bee734046a1bbc4a26df9f
|
|
| BLAKE2b-256 |
12e91ce2a78b945799ea3a7a2e6fd40279fdf5395375642393ede74c6bc48ea1
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1-cp313-cp313-win_amd64.whl:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1-cp313-cp313-win_amd64.whl -
Subject digest:
8c89a16d6a1f73610aa07ab8c23cac97dc396043382c66b26f1ba9b351ab99ee - Sigstore transparency entry: 976406418
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mc_dagprop-0.9.1-cp313-cp313-win32.whl.
File metadata
- Download URL: mc_dagprop-0.9.1-cp313-cp313-win32.whl
- Upload date:
- Size: 161.4 kB
- Tags: CPython 3.13, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
409c5b4a38a74c35422db2c94a718e71db59307984be76b7fca832d19e5e13cd
|
|
| MD5 |
faf10f2bbd58bbba3f2afc91e3dbab78
|
|
| BLAKE2b-256 |
ad641744aa30facd169a00145b16ad1078ba3d7e3fc97939a63330df1ecb8d35
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1-cp313-cp313-win32.whl:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1-cp313-cp313-win32.whl -
Subject digest:
409c5b4a38a74c35422db2c94a718e71db59307984be76b7fca832d19e5e13cd - Sigstore transparency entry: 976406411
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mc_dagprop-0.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mc_dagprop-0.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98ec599ec8d6abf42829cd3050619270b8bba74a2e57f4a78aa015d1713986ca
|
|
| MD5 |
e437d7afef85e2305a0b455879c6816b
|
|
| BLAKE2b-256 |
bdf51d335d77d8d33818c681a79e48a6a3dcb7db1405079ede236afea61a05f3
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
98ec599ec8d6abf42829cd3050619270b8bba74a2e57f4a78aa015d1713986ca - Sigstore transparency entry: 976406402
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mc_dagprop-0.9.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: mc_dagprop-0.9.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 202.3 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff58509689b7f0141a6bda22526e92b3c157228adc611bd4b197a77564dff154
|
|
| MD5 |
738ad46ce2ba5dc275fe477b2156fa19
|
|
| BLAKE2b-256 |
2ab904a138d531e8534def8a181ab32af06ff2d3126d7b1c257bf732b4a3b765
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1-cp313-cp313-macosx_11_0_arm64.whl:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1-cp313-cp313-macosx_11_0_arm64.whl -
Subject digest:
ff58509689b7f0141a6bda22526e92b3c157228adc611bd4b197a77564dff154 - Sigstore transparency entry: 976406404
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mc_dagprop-0.9.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: mc_dagprop-0.9.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 181.5 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
698bbdbecd30474beb177ab42a72b40d0216e9c635bb08ed1880e0b6df6e05cb
|
|
| MD5 |
04fb50c3f7c14f5db33ef784069e6889
|
|
| BLAKE2b-256 |
dbb04c3524c64164de18936c3989ca9b925badd52835819f74a8970773f357b9
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1-cp312-cp312-win_amd64.whl:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1-cp312-cp312-win_amd64.whl -
Subject digest:
698bbdbecd30474beb177ab42a72b40d0216e9c635bb08ed1880e0b6df6e05cb - Sigstore transparency entry: 976406409
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mc_dagprop-0.9.1-cp312-cp312-win32.whl.
File metadata
- Download URL: mc_dagprop-0.9.1-cp312-cp312-win32.whl
- Upload date:
- Size: 161.4 kB
- Tags: CPython 3.12, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5a8a5d957eb00ba06b3c5455a72dd347b45990da2e741a1cccc742d39782ac9
|
|
| MD5 |
b803bf3dd817ab343da413c79183fbbf
|
|
| BLAKE2b-256 |
67bcc16d674fbdef7988a6595700d5597006d684ffa7ac888f1acd97266f08f3
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1-cp312-cp312-win32.whl:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1-cp312-cp312-win32.whl -
Subject digest:
d5a8a5d957eb00ba06b3c5455a72dd347b45990da2e741a1cccc742d39782ac9 - Sigstore transparency entry: 976406412
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mc_dagprop-0.9.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mc_dagprop-0.9.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c428dd3aa6a5cdd8b27e68c034633f32efd813363437751869ca82e3172cfe92
|
|
| MD5 |
d92bebdde2c4aa8d2aaf771acf002faf
|
|
| BLAKE2b-256 |
2987c28c40ca09e80b3fc28f9cb7eb14bc6632deadab8daf3eb53967ae3d4b9d
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
c428dd3aa6a5cdd8b27e68c034633f32efd813363437751869ca82e3172cfe92 - Sigstore transparency entry: 976406413
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mc_dagprop-0.9.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: mc_dagprop-0.9.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 202.3 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35271641abcb2953e18db1659b7dda80ab9cefe2a2ed501221b60b933dfb6ab7
|
|
| MD5 |
7e977e2c26c03d8ec4d9788737bbde3e
|
|
| BLAKE2b-256 |
89133dc71487a98be6fef05c820fce012d6fd295a2b33cbb2cf45465b2241753
|
Provenance
The following attestation bundles were made for mc_dagprop-0.9.1-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
publish.yml on WonJayne/mc_dagprop
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mc_dagprop-0.9.1-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
35271641abcb2953e18db1659b7dda80ab9cefe2a2ed501221b60b933dfb6ab7 - Sigstore transparency entry: 976406406
- Sigstore integration time:
-
Permalink:
WonJayne/mc_dagprop@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Branch / Tag:
refs/tags/v9.0.1 - Owner: https://github.com/WonJayne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14bdfca68dc5cb2ea228c71b295338bac5f1f174 -
Trigger Event:
push
-
Statement type: