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 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.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 the extension locally

The orderbook implementation includes a C++ extension module (toolbox.orderbook._core) built with pybind11.

Typical local build (editable install):

pip install -e ".[dev]"

If you are modifying C++ sources and want a clean rebuild, remove the build directory and reinstall:

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.1rc1.tar.gz (20.7 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.1rc1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (125.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

disco_toolbox-0.0.1rc1-cp313-cp313-macosx_11_0_arm64.whl (88.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

disco_toolbox-0.0.1rc1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (124.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

disco_toolbox-0.0.1rc1-cp312-cp312-macosx_11_0_arm64.whl (88.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

disco_toolbox-0.0.1rc1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (125.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

disco_toolbox-0.0.1rc1-cp311-cp311-macosx_11_0_arm64.whl (87.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file disco_toolbox-0.0.1rc1.tar.gz.

File metadata

  • Download URL: disco_toolbox-0.0.1rc1.tar.gz
  • Upload date:
  • Size: 20.7 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.1rc1.tar.gz
Algorithm Hash digest
SHA256 1793b66e9da14e5dca19f53d444ff350be651300e3086ff76378d0f201c6c229
MD5 547d5f39ec9a1e68bdba241933fd8448
BLAKE2b-256 a89b9b20bcf733a2469a20d6a9353572987e196bd8d34999200b7205b5a35814

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.1rc1.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.1rc1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.1rc1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 5cb9c367d25855c8a21d177ae2a8895569979e144c20f75b4f23848b3950ac45
MD5 6c69a7e3a30c8ce913f4b63aeafa0cbf
BLAKE2b-256 3711b380345ee81af51b7ff9f43a8516c63552bc8105ca4b801160d6ddc1d9b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.1rc1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_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.1rc1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.1rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 67487dbd5893f1eee59f8a588a7e22e3ebe759fc41d23e200d0d141a81e5b196
MD5 4b59f2545a1c80a2ce2aff530d555f42
BLAKE2b-256 9ccb89ffca3b87af7bd2ac7de464c42d1f89d14e0ace18dcb36dbc46d62c1155

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.1rc1-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.1rc1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.1rc1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 fd42586d94e0e0139ee9c14ddf24eac0a2a14892f37fb4d344df1884beabcd43
MD5 3db8eb98238ca32a1bbc5e0da5aae333
BLAKE2b-256 18d432e8b9588f0c4c91cdb77f3f7aed327a8475a10ce79dbbc74eb6e84a460a

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.1rc1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_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.1rc1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.1rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 51bfa2621bca0508b2fedd14c34ec8c7c30a28c8b46fdf14e3f63f0672264a78
MD5 b6fb70e2f6c7e9c21963ef7c893624d9
BLAKE2b-256 5fa42b8d4426fb3d9fb19f01a8fd32f68043f0b9f7814bb1f68833bd3e9c5623

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.1rc1-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.1rc1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.1rc1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 99b4c36dcb80ba5c5caf824c935e0a5174480b797729dbf1a80f2b732d90592e
MD5 e8501a78828db196ed5f7fda12f7cea1
BLAKE2b-256 424028594e0b112b1c868f658da63ad6a2372e3b151af36108bca46a1d780802

See more details on using hashes here.

Provenance

The following attestation bundles were made for disco_toolbox-0.0.1rc1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_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.1rc1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for disco_toolbox-0.0.1rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a419a17a614b148a0f9bf4326085af1971d173e55184911c687dc65d2df75dcc
MD5 c8e06b48689df2770ff9bb19ea6b00a5
BLAKE2b-256 dcc71c7b80242bc46748f431b7a59b7d6fd11654f4135024851d80e1a879e9c1

See more details on using hashes here.

Provenance

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

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