Skip to main content

A toolbox for disco simulation models.

Project description

🧰 disco-toolbox

A toolbox for disco simulation models.

PyPI License: Apache-2.0 Build Tests

disco-toolbox contains reusable utilities intended to be embedded in disco models and supporting code. The toolbox is deliberately small and focused: each subpackage should solve one clear problem well, with an emphasis on correctness, testability, and performance.


🧭 Overview

  • Python ≥ 3.11
  • Key dependencies: python-graphblas, numpy, scipy (orderbook uses dense numpy arrays; GraphBLAS is used elsewhere in the toolbox)
  • Includes optional C++/pybind11 and Cython extensions for hot paths (built with scikit-build-core).

📦 Installation

pip install disco-toolbox

📚 Subpackages

toolbox.orderbook

A compact order book for simulation loops (fast C++/pybind11 core):

  • Store outstanding orders as dense numpy.ndarray (float64) vectors
  • Keys are stored as opaque bytes (so you can pack identifiers however you like)
  • Allocate available capacity/stock against orders with a greedy strategy
  • Remove fully fulfilled orders during allocation
  • Supports pickling / unpickling for checkpointing

Quick example

import numpy as np
from toolbox.orderbook import Orderbook

ob = Orderbook()
ob.append(b"abc", np.array([1, 2, 3], dtype=np.double))
ob.append(b"def", np.array([4, 5, 6], dtype=np.double))

stock = np.array([5, 5, 5], dtype=np.double)
allocations = ob.allocate_greedy(stock)

for key, alloc in allocations:
    print(key, alloc)

print("remaining:", stock)

toolbox.calendar

Calendar-aware time arithmetic for simulation models (Cython-accelerated hot path):

  • Define working-time patterns via a cyclic weight array — full days, non-working days, or partial days
  • Add non-repeating holiday overrides by absolute day index
  • Compute elapse(start, duration) -> finish: the calendar time at which duration working units have elapsed since start
  • Accepts and returns both scalars and NumPy arrays (any broadcastable shape)
  • Compiled to a dense prefix-sum array at construction time; elapse is a single binary search — O(log H) per element

Quick example

import numpy as np
from toolbox.calendar import Calendar

# Mon–Fri = 1 working day, Sat–Sun = 0
cal = Calendar([1, 1, 1, 1, 1, 0, 0])

# Add public holidays
cal.add_holiday(0)        # Monday 0 is a bank holiday
cal.add_holiday(1, 0.5)   # Tuesday 1 is a half-day

# Scalar
finish = cal.elapse(start=0.0, duration=5.0)
print(finish)   # 9.0  (loses Mon, half Tue)

# NumPy arrays
starts    = np.array([0.0, 7.0, 14.0])
durations = np.array([5.0, 3.0,  1.0])
print(cal.elapse(starts, durations))

toolbox.capacity

Fixed-capacity token pool for scheduling jobs across parallel resources:

  • Models a multi-server queue where each token represents a parallel resource (server, machine, worker)
  • Jobs are assigned greedily to the earliest-free token — no sequencing decisions are made
  • Accepts a single duration (scalar) or an ordered vector of durations; vector jobs are assigned in occurrence order
  • Optional Calendar integration: finish times are computed in working time rather than wall-clock time

Quick example

import numpy as np
from toolbox.capacity import Capacity
from toolbox.calendar import Calendar

# Two parallel resources on a Mon–Fri calendar
cal = Calendar([1, 1, 1, 1, 1, 0, 0])
cap = Capacity(2, calendar=cal)

# Single job
start, finish = cap.process(epoch=0.0, duration=3.0)
print(start, finish)   # 0.0  3.0

# Batch of jobs assigned in order
starts, finishes = cap.process(epoch=0.0, duration=np.array([5.0, 5.0, 2.0, 2.0]))
print(starts)    # [0. 0. 5. 5.]   both tokens occupied for first two jobs
print(finishes)  # [5. 5. 8. 8.]   next two wait for weekend, finish Monday

toolbox.distributions

Small, simulation-oriented distribution utilities on top of SciPy:

  • Generic, registry-backed moment fitting via fit_moments.fit(...) returning standard SciPy frozen distributions
  • Custom distributions:
    • rectnorm: rectified normal distribution (X = max(0, Z) where Z ~ Normal(mu, sigma))
    • conditional: zero-inflated wrapper around a base SciPy distribution

Quick example

import numpy as np
from numpy.random import default_rng
from scipy import stats
from toolbox.distributions import fit_moments
from toolbox.distributions.conditional import conditional

rng = default_rng(42)

data = stats.gamma(a=3.0, scale=2.0).rvs(size=50_000, random_state=rng)

rv = fit_moments.fit("gamma", data, ddof=1)
print(rv.mean(), rv.std())

# Zero-inflated normal: P(X=0)=1-p, else Normal(inner_loc, inner_scale)
norm_cond = conditional(stats.norm, name="norm_cond")
x = norm_cond(0.3, 0.0, 1.0).rvs(size=10_000, random_state=rng)
print("zero fraction:", np.mean(x == 0.0))

🧰 Development Setup

Clone and install in editable mode:

git clone https://github.com/michielmj/disco-toolbox.git
cd disco-toolbox
pip install -e ".[dev]"

Run tests:

pytest -q

Type checking:

mypy src

🏗️ Building extensions locally

The toolbox includes two compiled extension modules:

  • toolbox.orderbook._core — C++ / pybind11
  • toolbox.calendar._core — Cython (with optional OpenMP parallelism)

Both are built automatically on install via scikit-build-core.

Typical local build (editable install):

pip install -e ".[dev]"

To enable native CPU optimisations for the Cython extension (local development only):

DISCO_NATIVE_MARCH=1 pip install -e ".[dev]"

If you are modifying C++ or Cython sources and want a clean rebuild:

rm -rf build
pip install -e .

🧾 License

Apache 2.0 License © 2026 — part of the disco-toolbox project.

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

disco_toolbox-0.0.4.tar.gz (35.4 kB view details)

Uploaded Source

Built Distributions

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

disco_toolbox-0.0.4-cp313-cp313-win_amd64.whl (179.1 kB view details)

Uploaded CPython 3.13Windows x86-64

disco_toolbox-0.0.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (320.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

disco_toolbox-0.0.4-cp313-cp313-macosx_11_0_arm64.whl (163.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

disco_toolbox-0.0.4-cp313-cp313-macosx_10_13_x86_64.whl (178.0 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

disco_toolbox-0.0.4-cp312-cp312-win_amd64.whl (179.3 kB view details)

Uploaded CPython 3.12Windows x86-64

disco_toolbox-0.0.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (320.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

disco_toolbox-0.0.4-cp312-cp312-macosx_11_0_arm64.whl (164.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

disco_toolbox-0.0.4-cp312-cp312-macosx_10_13_x86_64.whl (178.7 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

disco_toolbox-0.0.4-cp311-cp311-win_amd64.whl (178.1 kB view details)

Uploaded CPython 3.11Windows x86-64

disco_toolbox-0.0.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (321.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

disco_toolbox-0.0.4-cp311-cp311-macosx_11_0_arm64.whl (163.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

disco_toolbox-0.0.4-cp311-cp311-macosx_10_9_x86_64.whl (176.4 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

Details for the file disco_toolbox-0.0.4.tar.gz.

File metadata

  • Download URL: disco_toolbox-0.0.4.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for disco_toolbox-0.0.4.tar.gz
Algorithm Hash digest
SHA256 f51a65ffc8f787c024da1678a0fd13bfbc29d8c5bcca42fb6ab0eb717fe04ccf
MD5 afc5bc6b580612c6326d7d0b3ec5115a
BLAKE2b-256 d489a7dee4c9625f32605102ad2570ef3593360d5a391b113fc92f9877660e53

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4.tar.gz:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ac848b6532c99a754177a6dfbb8accfecaf593b5d36fcef0b7c1735f3fc7e95d
MD5 9010d65546ea237dc502d54c5aef127c
BLAKE2b-256 bd60d60e9a7190a969db2c798037c43d24e01e51b111cd52f9a72600ffe36dbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp313-cp313-win_amd64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ed71a393561b666f84215e7582d2ff92083bde20a3a492fc9a35f9ce61dfa127
MD5 8620ce0936853be4c9b3c37e804f0f54
BLAKE2b-256 b7c84196c1cebe4e6b45859952f381ac142cc9a2ba7a61405563ef5bfeb1e995

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aae8a3aa896a3b8c9ea7a886dd6bbcc6d889f139e4de5c9658b81a31d048d854
MD5 9962d2609e7ea58998598db497052d21
BLAKE2b-256 67ee3a9f6c3d7464f48e992ac406ad49265a9d23991925ec1adf72ae1a545ec6

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 7a4c28dddf549b50044d9939afb7cfc4f7df4b374ff0e21154cb74e31a2b3fe8
MD5 9f903287d0dc09b1d94ce9fd089b54c9
BLAKE2b-256 d8e115245e3b72fe9e36d7eaf7ab6c646e5ae10629fb30cdd961e7a3c1926b7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e40af2dc29f013aeb1f48b6f5a64120207f08697bb25f69108e0dac9b0e497fc
MD5 09a54ccb2ad264135e255f4889b9807b
BLAKE2b-256 93fad26ede9169a1fc233c320ab4b560cf69fbce5644d3fe63991c5b12c2b85a

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp312-cp312-win_amd64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a94c997a9f424575da5dad79aab1d30df709fe1678bf1a89df633e96af47f968
MD5 8a719634a23f03c29a9763acb70873a9
BLAKE2b-256 930504a9fe69ccce59d5dfac90da3b24305e1a65212da885b1cc55e5d27f8613

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f6eb50e70f0ee2ca4d8a5cc855a48478e84556c4220138b21468ed225add610
MD5 585e5c69bd747c3c51029ab30780e227
BLAKE2b-256 cb2938ca0c65e6ce048a3c9130a73c9f5ad0e22cdcf8dc41307e8f14aa3f6880

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 8e2c67b61b1e426c6e5a53c0b4b20a7c6336a9a9680b0e09fdbe027184bf39cf
MD5 caa2fce5c4bacbdd07d082f6fafa7c7b
BLAKE2b-256 4255939200f8413a77641e27f435ee36f837f6e0f2745713306e1007670bbb63

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0f5d98bbc71c341c8a980fa11aaba8fe58955d93d751af0d83dc5625bdcbc81e
MD5 063b41d0e3a21ba12069847f113e7bfb
BLAKE2b-256 dc047f99f01d5a27dcd216c43b4d09c60ffbae890951e69a7559fbbe1031d84f

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp311-cp311-win_amd64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3f4f559d3dd10f582557c4c4e1c1c0719efce28702b0d2b381b00baf6dff2605
MD5 d910063ea076d77f1171f8a78248f3a2
BLAKE2b-256 f6af6ad659bfd92761d4687cd3856077ed3e839b91196f15c401caeee9e84687

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 05bae7bff1ce9c982029b824bac97280d18168692183b495ea8a31b6d5013e75
MD5 d56e777b5665c3b80ec3398a4e91cc12
BLAKE2b-256 c29a2fc2396cb6e2c97bb966caabeceb4a03777d52c74a38fa9dc07c3f30b5bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file disco_toolbox-0.0.4-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9091a00e460801e931179079109ad345ac5259fa3b5c48cc2ecbd4c401604820
MD5 f5f2f78bea346d95eab1fa8916886e8b
BLAKE2b-256 41318557eb8b8f102ba17d326f0e46418f809a20f905e38305ffe834a5d4384b

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: release-publish.yml on michielmj/disco-toolbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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