Skip to main content

🧰 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.13
  • Key dependencies: python-graphblas (≥ 2026.11), numpy (≥ 2.5), pandas (≥ 3.0), 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 calc_finish integration: finish times are computed 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, calc_finish=cal.elapse)

# 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.

Metadata

Release files for disco-toolbox 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for disco-toolbox 0.1.0
File Size Uploaded Provenance Actions
disco_toolbox-0.1.0.tar.gz 35.4 kB With provenance Details for disco_toolbox-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for disco-toolbox 0.1.0
File Actions
disco_toolbox-0.1.0-cp315-cp315-win_amd64.whl CPython 3.15 CPython 3.15 Windows x86-64 Details for disco_toolbox-0.1.0-cp315-cp315-win_amd64.whl
disco_toolbox-0.1.0-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for disco_toolbox-0.1.0-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
disco_toolbox-0.1.0-cp315-cp315-macosx_11_0_arm64.whl CPython 3.15 CPython 3.15 macOS 11.0+ ARM64 Details for disco_toolbox-0.1.0-cp315-cp315-macosx_11_0_arm64.whl
disco_toolbox-0.1.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for disco_toolbox-0.1.0-cp314-cp314-win_amd64.whl
disco_toolbox-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for disco_toolbox-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
disco_toolbox-0.1.0-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for disco_toolbox-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
disco_toolbox-0.1.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for disco_toolbox-0.1.0-cp313-cp313-win_amd64.whl
disco_toolbox-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for disco_toolbox-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
disco_toolbox-0.1.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for disco_toolbox-0.1.0-cp313-cp313-macosx_11_0_arm64.whl

Total release size: 3.1 MB

Release files / disco_toolbox-0.1.0.tar.gz

Download URL disco_toolbox-0.1.0.tar.gz
Size 35.4 kB
Tags Source
SHA-256 checksum
How to use checksums
80811fa64a32012d269b9cbf5554b21e5a86f54fdc3b4542c7ac49d607acf581
BLAKE2b-256 checksum
How to use checksums
4683b5876c36156f72556c8d7741c88d6cfb8b2511f4c7c8b9a5f702a937336d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp315-cp315-win_amd64.whl

Download URL disco_toolbox-0.1.0-cp315-cp315-win_amd64.whl
Size 522.6 kB
Tags CPython 3.15 Windows x86-64
SHA-256 checksum
How to use checksums
40cc3b451fd3637d4092e628dcf08b3133fe71bda811e99846e06f397e68a30e
BLAKE2b-256 checksum
How to use checksums
b8d743b0bf0e326af1239cf25a8860ce283cf99e6ed6ea52b6d23c1ff09d8a1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL disco_toolbox-0.1.0-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 328.0 kB
Tags CPython 3.15 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
41a9ad312e94ec740310e6155d4a5aaa7d975690c1a94a16f3fe944e792a9ca6
BLAKE2b-256 checksum
How to use checksums
150f16d9cd70b7286f0c93f45ea609673bcc1dbbe12b281af7b6ea48a1fa7d70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp315-cp315-macosx_11_0_arm64.whl

Download URL disco_toolbox-0.1.0-cp315-cp315-macosx_11_0_arm64.whl
Size 168.1 kB
Tags CPython 3.15 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5ad5d1dd43bf0fc80a047d5da8bb50546f537ae227aca02859cce9315d119990
BLAKE2b-256 checksum
How to use checksums
580915ccfa57eeff414eb6f97db80b5955800dce8ec3f54ea366f973bf3f6abc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp314-cp314-win_amd64.whl

Download URL disco_toolbox-0.1.0-cp314-cp314-win_amd64.whl
Size 522.7 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
63680b431465e9aac5e038d994c3ce0addb95740df297998500146341de15ee8
BLAKE2b-256 checksum
How to use checksums
a74256b041c8fcb7584725d1ab39c8e608dce5a5e4719f0fa8c7b7fd7a0191fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL disco_toolbox-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 328.9 kB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
14027bb217ea14db2dec45a6bd2d7999e318fd9a4f497f01f26a0416acf7ceea
BLAKE2b-256 checksum
How to use checksums
18c205990c1889564cf31871967381fe05f030178040ab10718b17a3cc030c57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL disco_toolbox-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Size 168.0 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
594757fa351679ab5ccc577744f7462b39fd52dd4b9fd575fdfb2da80e151060
BLAKE2b-256 checksum
How to use checksums
426fd99c73b2b5551586619d1581806508a7bd7340d6cbac7df55d5b49b88797
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp313-cp313-win_amd64.whl

Download URL disco_toolbox-0.1.0-cp313-cp313-win_amd64.whl
Size 507.7 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
6b7b3fbb79bd8523fd9cdc99e48063d7faa6ad649b51f9f7922e4a90d4a40ab9
BLAKE2b-256 checksum
How to use checksums
64a8bf7bac025e37d1dcbf5e39076eefcdcd4018a630d81c8e39b468bbaa0eb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL disco_toolbox-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 326.9 kB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b03ac987e41199c85e56753d77c9cea2e0868f4745e27f8fba2dc124b5cce96a
BLAKE2b-256 checksum
How to use checksums
cbd65cee349b950f3eb9a93a9e11248de1047e1853a2cda8052f92e150545b1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / disco_toolbox-0.1.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL disco_toolbox-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Size 167.5 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f15a28f68bfd21a569c5bb52da3a20903be3cce71af5010d2b57f4150c86cad6
BLAKE2b-256 checksum
How to use checksums
16a737889226378d196e8c8207c136199f74cd35680a4809add9dc42be06c309
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for disco-toolbox 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 10 files in this release have been uploaded with provenance metadata.

Select from 10 files

Attestation for disco_toolbox-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page