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

Uploaded CPython 3.13Windows x86-64

disco_toolbox-0.0.3-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.3-cp313-cp313-macosx_11_0_arm64.whl (88.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

disco_toolbox-0.0.3-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.3-cp312-cp312-win_amd64.whl (97.3 kB view details)

Uploaded CPython 3.12Windows x86-64

disco_toolbox-0.0.3-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.3-cp312-cp312-macosx_11_0_arm64.whl (88.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

disco_toolbox-0.0.3-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.3-cp311-cp311-win_amd64.whl (96.1 kB view details)

Uploaded CPython 3.11Windows x86-64

disco_toolbox-0.0.3-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.3-cp311-cp311-macosx_11_0_arm64.whl (87.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.11macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: disco_toolbox-0.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 3aa85abebdd621d43b59cff23b58b1cb22b8f1dbf29dd026fafb783865bafa38
MD5 0350b5b68bab9d3bebbcf2e1874e35c3
BLAKE2b-256 d180f2390a4a4ade14f0eb06ebd818e6c34785ecfc7467dabdb00f2d0efce48e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 bd1958843dca5b86681579740356ecc73f34511b5d1ecabadefe8e1ecd5c5a38
MD5 f423c1f2e4045c4a5dfe6a3cf81ea69e
BLAKE2b-256 bbcaf4536192c5bb605fe46c90a5964a7f3520d1e3db4f0e2a3cb414ac6b9d14

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c5c5e0bb1f329582ce3dd4f4a143dc78a448a69f874a2c787f65d8837ec1385b
MD5 3a64174cd08ab53a8ef75639d39a8728
BLAKE2b-256 745b06a0ac9ab47ad8686448fc34dabeb56db8ceccce7d8312635614d1836430

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00ffd7fc82ea903452168d1be98262e01c01d1340ff5a564db27133fecc549cf
MD5 1fbf6f70acaec43f9411393b7527063f
BLAKE2b-256 706ebfcb76802cc8c3efa2179a0172951b0cd38b2b00e245eaac29238126ec01

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 184e6bdde12d3533bbcc2541706a83f60af7efbc01932e03a363ad46ef548a42
MD5 2277d25d174edd2e4740f153058a0e56
BLAKE2b-256 9f5d1968f95dc9ff2187aa15e4b63a25dcbc0e33ae85c7121e46fab3739c21a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a39bd704380abee1ad6664b43882c32908da89192195904d0acfae4995ae10f4
MD5 e821f9f3de15e8c4ed55be10df03015d
BLAKE2b-256 1b4fbc48742447cb63efcdbd8c62ad71a5e83b1b8eac28359bd6ccef6b09a00d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 998973a6b67c543d64eadaf3b8ffb2162e055baecec12bb6ba88159749395807
MD5 d55258eb95c459075a9c747a4ee1317e
BLAKE2b-256 7ba2db20eefa563dda1f85f843df9b22a2e7b77cf6d939d7f92038f765a5976d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b1aa1785d39a2f9f4218eadb12dd99f6c2e7c830911ba58f70d0e2bcbe4f8575
MD5 ee34c8ee49fb97526b5e32f249393711
BLAKE2b-256 ac0cb3f4363cfcceeb9bafbf3b0680f0e7793ad6a0cc726cff53a4de6529dd44

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 077cadc9251c7a6772a267c74333d4ff4fbef56587a8b67ad0f8d3ee45168634
MD5 4794dc8b3e7ebbe1e65732f2ea273962
BLAKE2b-256 ae7a30eeffcd7652dc6a52ee620de5bcc25c3d9eb7fe564427c2452f49724e2b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3ae92924ebc957b2ada03be35d17238a836928bc6f21362fb41dbda1d15ddcbc
MD5 0f1ef564fd03ee4550ca1b152667de7f
BLAKE2b-256 80f4b87e2b0edd2659fbf637155443f276961729b13b588feaf855f5276ba007

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b840380b3ea9fc4341082237f51a24cb8fd027bfd01ceb7e44d2a11916d12690
MD5 4f3862c3fe7ae15bb423fd76dd5d999a
BLAKE2b-256 eec596646929ddd28ce69b7f3783de27afba748ad250f11f14b32a4c27b0de90

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 85f5d2f7c524d99c4843477515cea81f5bab7bb11f189e641ba3b56151e924bc
MD5 2fe1f6bdf32b588172748191c772c4fd
BLAKE2b-256 29f810fc66b8acdc21088917f33c41b4fd087fd06fb91ae149f4f14f594375a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for disco_toolbox-0.0.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 aba66633528a92ef181fd76cf4068f751edd8e0e43d10b7bbbd241ad3d11f2ac
MD5 6b944efc7b7ad1468aa250c51aa9f493
BLAKE2b-256 6256daf81e7150970ed338f4b02056b2478792d4ea0ab7125bcf90f4834c97a6

See more details on using hashes here.

Provenance

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