Skip to main content

Arena-like statistics layer for SimPy: Counter, Tally, Level, replications, and CI.

Project description

simpy-stats

Arena-like statistics layer for SimPy: streaming Counter, Tally, and time-weighted Level statistics, replication management, and t-based confidence intervals — all with no mandatory dependencies beyond SimPy itself.

Features

  • Counter — event counts and optional rates
  • Tally — observation-based streaming mean, variance, min, max (Welford algorithm)
  • Level — time-weighted average of a piecewise-constant signal (queue length, WIP, utilization)
  • Stats — factory + registry: one call per name, finalize()Snapshot
  • ReplicationRunner — independent replications with half-width stopping rules
  • ci_t — two-sided t-based confidence intervals (built-in table; scipy optional)
  • SimPy integrationsMonitoredResource, MonitoredStore, MonitoredContainer, attach_resource_monitors()

Installation

pip install simpy-stats

Or with uv:

uv add simpy-stats

Quick start

import simpy
import simpy_stats

env = simpy.Environment()
stats = simpy_stats.Stats(env)

wait = stats.tally("wait_time")
arrivals = stats.counter("arrivals")
queue_len = stats.level("queue_len")

# ... run simulation ...

snap = stats.finalize()
print(simpy_stats.summary_table(snap))

Replications with half-width stopping

from simpy_stats import ReplicationRunner

def my_rep(seed: int) -> simpy_stats.Snapshot:
    env = simpy.Environment()
    stats = simpy_stats.Stats(env)
    # ... build and run model ...
    return stats.finalize()

runner = ReplicationRunner(my_rep)
report = runner.run_until_precision(
    metrics=["wait_time.mean"],
    rel_half_width=0.05,   # 5% relative half-width
    min_reps=10,
    max_reps=200,
)
print(simpy_stats.summary_table(report))

Automatic resource monitoring

from simpy_stats.simpy_integration import MonitoredResource

server = MonitoredResource(env, capacity=1, stats=stats, prefix="server")
# server.queue_len and server.in_service Levels are updated automatically

Development

uv sync --extra dev   # install deps
uv run pytest -q      # run tests
uv run ruff check .   # lint

Milestones

M1 Core stats + Stats + 70 tests
M2 ReplicationRunner + CI / half-width
M3 MonitoredResource + helpers + examples
M4 Docs + PyPI release

License

MIT

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

simpy_stats-0.1.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

simpy_stats-0.1.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file simpy_stats-0.1.0.tar.gz.

File metadata

  • Download URL: simpy_stats-0.1.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for simpy_stats-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3790b0445651967aba5d7d990bd9bef6cc325e65e1dded278e37dd82d15e5e70
MD5 1a8018d1630ce4edc267be9bbf1920b2
BLAKE2b-256 96fe831e7b0ef84966a4cdcbe189edd10ee8fb8551069d67ae961130be107cce

See more details on using hashes here.

File details

Details for the file simpy_stats-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simpy_stats-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb60b9093bd08859563372e07888cc8950e332267c637ca7a359c173adc4149f
MD5 b611820bbff4d147b332e2afabab01ac
BLAKE2b-256 05c4c2b99d03908dbe9215d5082edd4fed3829ccbc508e9a44f8bf7456f97593

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