Skip to main content

rustmc

Bayesian models in Python. Inference in Rust.

rustmc focuses on small, structured models you need to fit repeatedly: regressions, group comparisons, calibration, and forecasts. Build a model once, fit new datasets, and keep the posterior draws for prediction and diagnostics.

The project is alpha. The Python package is supported; the Rust API is still changing. Check convergence and model fit on your own data.

pip install rustmc

NumPy is the only required Python dependency. Install rustmc[viz] for ArviZ and Matplotlib. Python 3.9–3.14 are covered by install tests.

Fit a regression

This example estimates an instrument's offset, gain, and measurement noise.

import numpy as np
import rustmc as rmc

rng = np.random.default_rng(42)
x = np.linspace(-2, 2, 100)
y = 0.3 + 1.2 * x + rng.normal(0, 0.2, x.size)

model = rmc.ModelBuilder()
offset = model.normal_prior("offset", 0.0, 1.0)
gain = model.normal_prior("gain", 1.0, 0.5)
noise = model.half_normal_prior("noise", 0.5)
model.normal_likelihood("reading", offset + gain * "x", noise, "y")
compiled = model.compile()

fit = compiled.sample(
    {"x": x, "y": y}, chains=4, warmup=1000, draws=1000, seed=42,
    show_progress=False,
)
print(fit.summary())

future = fit.predict({"x": np.array([-1.0, 0.0, 1.0])}, seed=43)
print(np.quantile(future["reading"], [0.025, 0.975], axis=(0, 1)))

predict keeps the (chain, draw, observation) axes. Use expected=True for the conditional mean without new observation noise. Priors above are chosen for this example's units.

Reuse the model

compiled.sample() accepts another dataset with the same columns and a different number of rows. compiled.sample_batch() fits independent datasets with stable IDs:

batch = compiled.sample_batch(
    [{"x": x, "y": y}, {"x": x[:50], "y": y[:50]}],
    ids=["instrument-a", "instrument-b"],
    chains=4, warmup=1000, draws=1000, threads=2, errors="collect",
    show_progress=False,
)
for instrument in batch.ids:
    if instrument not in batch.errors:
        print(instrument, batch.get(instrument).summary())
print(batch.errors)

Independent fits do not share information. For related groups, build one partial-pooling model.

What's included

  • NUTS and HMC with autodiff, constrained parameters, and parallel chains.
  • Scalar and vector regressions, group indexing, nonlinear expressions, and custom log-density terms. See custom models.
  • Prior and posterior prediction, pointwise log likelihood, R-hat, effective sample size, Monte Carlo error, and ArviZ export.
  • Per-fit warnings() for R-hat, ESS, divergences, E-BFMI and tree depth, and flagged() to list the fits in a batch that fail them.
  • Exact Gaussian AR regression, Gaussian hierarchical models, and Kalman/FFBS algorithms for state-space models.
  • Forecasting workflows for structural, count, hurdle, and runoff models, with joint predictive paths and backtests.
  • Versioned model and fit artifacts. Compiled model artifacts omit training data; fitted artifacts include it. Neither resumes sampler adaptation or RNG state.

Two engines, one result surface

Models you write with ModelBuilder compile to a differentiable graph and are fitted by NUTS or HMC. The forecasting models are different: structural, seasonal, AR, dynamic GLM, hurdle, runoff, and the Gaussian hierarchy are hand-written samplers that do not use that graph, its autodiff, or its samplers. Each exploits structure the general sampler cannot, and they are not all the same kind: Gibbs with FFBS for the Gaussian state-space models (the local linear trend without exog integrates its states out instead), exact independent conjugate draws for AR, block elliptical slice sampling for dynamic GLMs, and for runoff either exact conjugate draws or latent-count Gibbs, depending on whether every ultimate total is known. sampler_stats on a fit reports which one ran, and whether warmup applied.

What they share is narrower than "one engine" suggests. diagnostics is genuinely common: R-hat, ESS and MCSE are computed by the same code for every fit. The batch executor is shared inside Rust, not just at the Python edge. state_space and forecast_diagnostics are shared among the forecasting models but are not used by the graph sampler at all. What every model does share is the Python surface: summary() and diagnostics() mean the same thing wherever you find them. A change to the NUTS sampler does not change a forecast, and vice versa.

The modeling language is deliberately small. PyMC and Stan offer broader model support. rustmc aims to earn its place through repeated fitting and a few well-tested specialized algorithms. Performance depends on the workload; see the benchmark protocol.

Start here

The roadmap tracks five priorities: statistical release gates, representative benchmarks, native model artifacts, bounded batches, and consistent results and diagnostics. Most of that work sits in the shared layer, so it reaches the forecasting models and the graph models alike.

For source builds and checks, see Contributing. MIT licensed.

Metadata

Release files for rustmc 0.16.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rustmc 0.16.0
File Size Uploaded Provenance Actions
rustmc-0.16.0.tar.gz 685.1 kB With provenance Details for rustmc-0.16.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for rustmc 0.16.0
File Actions
rustmc-0.16.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for rustmc-0.16.0-cp39-abi3-win_amd64.whl
rustmc-0.16.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for rustmc-0.16.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
rustmc-0.16.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for rustmc-0.16.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
rustmc-0.16.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for rustmc-0.16.0-cp39-abi3-macosx_11_0_arm64.whl
rustmc-0.16.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for rustmc-0.16.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 12.8 MB

Release files / rustmc-0.16.0.tar.gz

Download URL rustmc-0.16.0.tar.gz
Size 685.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c9a36a4da53068f4f45f0682a5e1f9e1a53bb2e89c7567df44401fe6a2db2c72
BLAKE2b-256 checksum
How to use checksums
37a4bd4267e72533f83043c3bb19632879e615eac39268961d20062499510fc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / rustmc-0.16.0-cp39-abi3-win_amd64.whl

Download URL rustmc-0.16.0-cp39-abi3-win_amd64.whl
Size 2.2 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e1b0f9524af3de2ec23bd2d74ddce7c3a6410cf0d85e42b59a3bc04db64cf5d2
BLAKE2b-256 checksum
How to use checksums
6a35287749e2b65f7e252e5b1382ce428af725542a3c0f780f1303c872ba4b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / rustmc-0.16.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL rustmc-0.16.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 2.6 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a163cfb2874ebfa0f02bd4845526264f71d5ac636f247825e62d14b0544d7fef
BLAKE2b-256 checksum
How to use checksums
a1d7c0520d8f52e6764ca27de6450fab9d17c79cf58d0a1b6b46909e0d139b59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / rustmc-0.16.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL rustmc-0.16.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 2.6 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8b1a9a46a305b46f617f50316b702330da33c4e3c8e49f9f402206a46464e768
BLAKE2b-256 checksum
How to use checksums
1b8f933e0160f51476ada398c17cbf4ca5537bf6f14901f136233d829049a16c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / rustmc-0.16.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL rustmc-0.16.0-cp39-abi3-macosx_11_0_arm64.whl
Size 2.3 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
36a5dde7148f03841380b91d82d5446a14ab1421667cf235f5c7b0c9be2ab2ba
BLAKE2b-256 checksum
How to use checksums
0cd9e67e415ba0dbabf69e1c1e3bfea0d03f8b51044f219b46df1858c6576533
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Release files / rustmc-0.16.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL rustmc-0.16.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 2.5 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ccf6e98f99640862c0e5935b82ff35596da2feb5632ac1e31f20330d070acca6
BLAKE2b-256 checksum
How to use checksums
5990356bfa9d53b6faaeac98a1ed82594574d8dc520fa77994a77e82cce6d4e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

Security for rustmc 0.16.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for rustmc-0.16.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page