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.3rc1.tar.gz (21.0 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.3rc1-cp313-cp313-win_amd64.whl (97.3 kB view details)

Uploaded CPython 3.13Windows x86-64

disco_toolbox-0.0.3rc1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (107.7 kB view details)

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

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

Uploaded CPython 3.13macOS 11.0+ ARM64

disco_toolbox-0.0.3rc1-cp313-cp313-macosx_10_13_x86_64.whl (97.2 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

disco_toolbox-0.0.3rc1-cp312-cp312-win_amd64.whl (97.3 kB view details)

Uploaded CPython 3.12Windows x86-64

disco_toolbox-0.0.3rc1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (107.7 kB view details)

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

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

Uploaded CPython 3.12macOS 11.0+ ARM64

disco_toolbox-0.0.3rc1-cp312-cp312-macosx_10_13_x86_64.whl (97.1 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

disco_toolbox-0.0.3rc1-cp311-cp311-win_amd64.whl (96.2 kB view details)

Uploaded CPython 3.11Windows x86-64

disco_toolbox-0.0.3rc1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (105.3 kB view details)

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

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

Uploaded CPython 3.11macOS 11.0+ ARM64

disco_toolbox-0.0.3rc1-cp311-cp311-macosx_10_9_x86_64.whl (95.9 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: disco_toolbox-0.0.3rc1.tar.gz
  • Upload date:
  • Size: 21.0 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.3rc1.tar.gz
Algorithm Hash digest
SHA256 2fe311c7eccede060429b6c07706d7de539bf594493418bddd30d33ad706344c
MD5 c40e18f61d6cbb24c12af6b7a8777305
BLAKE2b-256 4c05c222a93f07f458d34c8a2f4c9bf347d058871baf0f26e59ecd53ed1d12c1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 14f59d6666188e607258c9ce9f7a1d2e18d161a79bf0fe993c34eba537bebe06
MD5 4d7b7630b65b05bde9a2b8259a0ea05d
BLAKE2b-256 a742bac8f5a7e1d8b1631100318308bd4cfac1dccfe3eedba32b971a529543eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 345bccdd29807ef1dc42e2ce3eb898f3d6b4fc4847245d8eb95ef7b087c09385
MD5 38e2b1a9743d91482173bdeec595b4c7
BLAKE2b-256 ea60ce26371407c31eb0e905547e6c9c9d174c43774a16680086dd3327b243ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d0273c351672fe73bc9146404df579763d09004d98af51332c122aef82b5d8cf
MD5 cff4b7f1e35b9fc88b28fa9a899d340a
BLAKE2b-256 a9c5b2ebfdc370a88e8277436a4b4e2daceeb39556444fe65135d57b4249ad5e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 057e28aacc468638b6e8f1cd1913191d042fa4abb8ca94e7df3500efd551dd3d
MD5 2d096de36a04afa4cafd3ddb2e67c1db
BLAKE2b-256 8db9a669dc0f846a81de6b2d730850c23b78b7a886572c2a419eb3e77496196f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 53e7218b87575eb0b35d6776e726eb3857bca607349de4d3bf8256396cfb7fad
MD5 2331da5d75efc339fc35ad3eae0b045f
BLAKE2b-256 1a576263345ad904e3c664760f6ba88581e9a800829e043e6baacdcc7e9bd1ff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bcb6fa931272bca8bad2468d4a5d79501185a7062b03f88520d693ce03fb7adf
MD5 0eae3f8585f29730f6d7f949ddc31d0c
BLAKE2b-256 052ad6a9f5ec9ee9c22a21be6c9c59626566e9aec6b0b56e43bf8cb97196d097

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 73358dd526e352029ae6fb97ffd6d2079a752e63fb0d927672a2de24c3688e62
MD5 8caecacb156ea25be1b44cb6ff9ae725
BLAKE2b-256 563a3610bb3d97f803cf4aabce86c6d40c08508bef0d08c51285a81a656e4884

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 d718dcf194bbfe2dc46bbdb35b0a8510c400974d603072ef045f76dd3a989fb4
MD5 2d58888bdf7008dc5e25e2e6986456bb
BLAKE2b-256 8dc4e02f8e21c74429a66ca98737e7bcb46dfcbce97afae90955b51bf745e8bf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 407e65e04e63c0fbc7ed8fe5f590fe97cb01cb9933d0aae61910ba82265cca61
MD5 194df7a517857e6f71e2bd622850e814
BLAKE2b-256 77847b3e3baceda8d5e118e934731d151b2186d29e4b423cba3ee03bd07ca970

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b0a3421d3455547543a5daf8ff9b32cac439a2c70de40516cef84037d7a54aec
MD5 9b1eebf15fd309b5fa21cb51eddb16ad
BLAKE2b-256 00047c4c64ac780e46a5c96bfb47c07296bbd3803ce1db0ca7cf0d927b16faeb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bef5b5070cce23bc303ebed6a90e9453058a1bcb6908317355e0bba2a565e7f1
MD5 b99826a877c0122744b73f1e0b9617ff
BLAKE2b-256 8e9cf945dd388dfe1c751be5dbcbe67addf7f660194b9c4ac6e94acdcb983b08

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3rc1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 68ed5ab3fdfb53f8307b16f6c97bd12d7e9427ec3131fab731918bf0611fe26a
MD5 38298ccb726f63ac2ef8dfef598eec64
BLAKE2b-256 0ebebbe487cc45fa44ef9def0510f3450a5ebb5b0512e08e79d49c5b53ee60fb

See more details on using hashes here.

Provenance

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