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.2.tar.gz (21.3 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.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (125.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

disco_toolbox-0.0.2-cp313-cp313-macosx_11_0_arm64.whl (88.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

disco_toolbox-0.0.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (124.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

disco_toolbox-0.0.2-cp312-cp312-macosx_11_0_arm64.whl (88.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

disco_toolbox-0.0.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (126.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

disco_toolbox-0.0.2-cp311-cp311-macosx_11_0_arm64.whl (87.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: disco_toolbox-0.0.2.tar.gz
  • Upload date:
  • Size: 21.3 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.2.tar.gz
Algorithm Hash digest
SHA256 2dda16b08738690f2798ced1b4780bd37510fc4133988065aa73a94130f3ef1f
MD5 8a1140d659436022fbb0e6a074c0037d
BLAKE2b-256 b7c2f67c1f7c4ff964a98cd1f9c5813778b4cddc09cb326089339aaa6928a3ed

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 3c82e0d5ded6be4222b9938b5f604aef6982e179aaea18a11cbd608cd9acfeca
MD5 f6fb036d7d0117a781144d6f789a728d
BLAKE2b-256 4de20efbab8a47fd7e9916f54d4c904419c2a51969eec3b3a6f758f450a6a99b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31f3f81eeb3c56d357d4cb98678fc6953610d54bf3f42068f899d091ddd9c96d
MD5 90b980f82c60c3a2fc2ce84fae497d7a
BLAKE2b-256 9dbfe683f29593d9f68c66135b30ef22bd76cccb21334e6fc376abb444919894

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 199b97c80fc45f77870e4963de3ed82029642609de8245525e1ba257b845c754
MD5 9ecccc658d9712a0f47813617ed02342
BLAKE2b-256 a35186db0bbffda6ac98f817aeee2eccaf4ce2daffdb4d510abdcc3ca563a1c2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf9ef1d64c59df08016397c66f46b0655349c19a288c068f6308b5229c5b23b7
MD5 9d919d7c3e9f6bc2370089937536ac0c
BLAKE2b-256 ff952975d7a4f5233a05aa10a5d3ccb86e6d6386da8f323bd0e7d8e3a2006616

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 fa9d009f562b271558b3615f42d2c4fcf2a1d97f2c0b17b4f4904b310d60eec0
MD5 4190364a327b9bd0356ecf2bbb76b16e
BLAKE2b-256 53f6b3e159d7e665e386e44dde8088486729b5bf2088737607596f1a767c584e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 13ea13b60b6e460ceb011f47b3fc74259d1f0a2dcc3540229db59de0c91e5f5d
MD5 68d1c1fe0990bdf02ab91565fd16f2d1
BLAKE2b-256 390290c8224694e24de8d92b71e25951c5a56f23e62a4da5b0ee4b05433d0798

See more details on using hashes here.

Provenance

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