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.1.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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (125.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

disco_toolbox-0.0.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: disco_toolbox-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d49f8b2497cd22b7af215b80163d5806c20113d0f5fa71daa2be8b360569ffac
MD5 4dbd3c0d2243c860307af8953bff137f
BLAKE2b-256 a094d043114b8ead79476f59e5734a3cd20ecce1ad2b67079f848f330bb59b09

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 e49db94e16d65ffc460caa0a73140ab832fc5c750607bd3b493d091942ec7cb7
MD5 befbafa670bf31c4a27b2f1e104b3875
BLAKE2b-256 4362ffe89cbc2ec5079ec17643531dd522cd7bea060041bf4e6c65d361cecf91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bfe8f9671529f3d719f03b0349ef610e23d337599cc0781c55626890ad934ce1
MD5 cf7805ee9050800eb115549e6ecdf082
BLAKE2b-256 580afb8a3102e9b5a582ced266dac8ee90dbab1af887255426b2dcd9e0852ba5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 d5fce3d341effef4fb790193077b2297a89ec853c08f94882a1e5f8b0336292f
MD5 cdb23f5b7b0fc68aa45638973f217d24
BLAKE2b-256 2217414259756eac650ef911605fe581eb751ae064af2f7e61a18e69d208dc4b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 27ff69fd191756a78344999014b7d3bfde81a8d5ac903244758968b09ce9eae1
MD5 bd4dd971f1a95b6c45bf9ef7bbfdb768
BLAKE2b-256 fdda567d79c000436298af47a81dd3315301a3f0b7cbca774febd43c2e7ada66

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 072d9ac83326da72d4ffd84a0fafb3a7165021c64ebd87995124aea5f767f0ad
MD5 9de90f25c74f51e0e2e2534aa4cd7074
BLAKE2b-256 57fd661aa1a20604111b8ad3f399c2a1d68b21e8176e20a309928a7c9bdc5e92

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eff7860d5db632c221df37f5cdd28ae6963d1b2057b6972b33ab677fae631d77
MD5 e6b3082888d9c609e0d2bee500d773be
BLAKE2b-256 027c85a1cfca70cf9c5b5d950fea61e1291f70d1488e1a6bdaa7159dee9570ca

See more details on using hashes here.

Provenance

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