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.4rc1.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.4rc1-cp313-cp313-win_amd64.whl (179.1 kB view details)

Uploaded CPython 3.13Windows x86-64

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

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

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.13+ x86-64

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

Uploaded CPython 3.12Windows x86-64

disco_toolbox-0.0.4rc1-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.4rc1-cp312-cp312-macosx_11_0_arm64.whl (164.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

disco_toolbox-0.0.4rc1-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.4rc1-cp311-cp311-win_amd64.whl (178.2 kB view details)

Uploaded CPython 3.11Windows x86-64

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

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

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

Uploaded CPython 3.11macOS 11.0+ ARM64

disco_toolbox-0.0.4rc1-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.4rc1.tar.gz.

File metadata

  • Download URL: disco_toolbox-0.0.4rc1.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.4rc1.tar.gz
Algorithm Hash digest
SHA256 17e71d4e5dfb3b2afda87095aeace7adcd94205ec9cea8638b6c50706dc98fca
MD5 f673da8c9ee9195c04ace75c0d134772
BLAKE2b-256 43ec013e70d70f0ed955d9d3317905946552853a2e8b8606c01d18e4146b0483

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1.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.4rc1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 30bdea02e75998c062a076b66cd42f38032b0557196f98f09e9eb0834fcf71b6
MD5 53ab61a3063304e788a7d67154971231
BLAKE2b-256 e48352b98be0adc0d622f79094fd00f4865cf7fe341bd86846c03f115efc03fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 830d26f4a4828f3e77448830be9286103eefe1906136cf11537eb61d05b78d9c
MD5 ea07462aefac45211212d113328694c0
BLAKE2b-256 04c57291da11b47240735d12aacfe3bc384adf735ddb8ccb9ef3a7246124ce55

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0543e4ab5d9bf40f4051787f9b62ad7d24b694ed5fbeef46c08b180db0c4fce5
MD5 e4dd7b3a4a543ec57737c590dd5a8160
BLAKE2b-256 5694eda85f8d1172001bb31882040a9d0c9300dccc660114563186397a518a28

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 2d32872a46b6a5219955d64550ef6ad9ef612505f21d056cdcf80c03439e7438
MD5 2b344cebb017761a523c85af37128ee2
BLAKE2b-256 e2ad203378d085bdc9ceb2d2e0a65ab4e8ea651eade19203d00d974f940bb48a

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a844400634387e447992d10609ab45066cf0bfca6b0767c0ff0bca69093278ac
MD5 884437251ae3c810b0b8e86ea7a49300
BLAKE2b-256 f2cd32e958ee73a675f919e033b83c4712f2213f2b5a0e3a7ad73b9428d7e23c

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 01b7f621af400c180a8bd1b11b2447dcab6da6437ae6c201dfb43cb5fbc18a6b
MD5 ffc7e52805309b3ac8468f48f9ec5edc
BLAKE2b-256 aafd9893c8e81e31c921e1efbb406e7d45dafd9a8edbe8253b39eaaf3c3e7671

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 468c222173bbe761ec4ef645b7b6670e2bc6d1761be1a5d0200c2d70b29edc78
MD5 ace344522be56678edf0b883b73eb918
BLAKE2b-256 1a23e429a40bfb0a41ee368cfe52af772f614e79e04caa7436fa9fb53b16d249

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d461b16c6ae8b94376efb8ebf3598e1d73ef6f613bd035d4d1d9db42920388f3
MD5 66326ee63ea023e5d5b7063d42a042ae
BLAKE2b-256 5003e323cedfb60370e5cb2516f83546fc72dc00506821eccbc39534ec8b6f48

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 55599c3333d7e639054ce78987491219612b3fa5f38acea119ca773a2abbd787
MD5 db478910aa57f4042f5aed6d55727a6f
BLAKE2b-256 e285afef01ccd6f77b18c5699188dfdb87a72831278371bda7ec7dfdbd905fe3

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6c3e56f8edec819de097160dda2d29bde285df70e91edca7d1a5a34dea948dea
MD5 c7b47bfea4b6eca24fc8a1d389c9bf0c
BLAKE2b-256 929991cbc4006abfaf541736b3f6e8a5951607d091849695fcea639f176e2307

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e507e0a1c529fa6771c47ca62270b701a9c103c1a72b6ee66a09e0a333484901
MD5 d553b9dbe3bc387c4e681f580e46bfdf
BLAKE2b-256 0cbeba417b8c487a1c1235d164ff7f8fd5ba1eb0db0a1132ac4ce2b7da245a4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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.4rc1-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.4rc1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a6c3b2cf990d260f8e1d2df61cb3da39d36e963c1ae48790ba133737622238e4
MD5 23a287bec14c18458daa91ed47be2ed4
BLAKE2b-256 8265d49c65ee2a9470dbbc80deb7046dd83a01c4c3392a6a68d1438b161b1e1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.4rc1-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