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.
  • 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, 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.

Release files for rustmc 0.13.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.13.0
File Size Uploaded
rustmc-0.13.0.tar.gz 447.5 kB Details

Built distributions (wheels)

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

Total release size: 10.7 MB

Release files / rustmc-0.13.0.tar.gz

Download URL rustmc-0.13.0.tar.gz
Size 447.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8b28a505ecd8efff3c01a384f17a2acfdf9ead51188ae74f596ae3e4c9b6a15d
BLAKE2b-256 checksum
How to use checksums
0ee8877bd24da597bbb76db7ffe0be027ff526e9efb59d882c491326c78306f7
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 Sep 26, 2026.

Transparency log

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

Download URL rustmc-0.13.0-cp39-abi3-win_amd64.whl
Size 1.8 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
ff5f5856988dea21c33500b9332b390cb65a63570d64c70ba1249dd182deb82d
BLAKE2b-256 checksum
How to use checksums
129c5f149781ccbd9276f991e6ab9adf1fcb6cad475d97d5bf6cad47d6ece60c
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 Sep 26, 2026.

Transparency log

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

Download URL rustmc-0.13.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e2d7bc167cbad51ab701469f556b5db909e7ad1a9b85912646ee50cdfea42bfc
BLAKE2b-256 checksum
How to use checksums
841df2383add2ab3d59b2e9ee63043a36bd11e37ee370431ea367947ce95af74
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 Sep 26, 2026.

Transparency log

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

Download URL rustmc-0.13.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.2 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
6362307f21cc3f0ab73c1d0c0b2303d7ab9f8de15484a738776e61f020a80888
BLAKE2b-256 checksum
How to use checksums
e81d0873000b0380367860dddd5dfd5ea13d07e2306a3d3e1a64071a71e2a2d2
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 Sep 26, 2026.

Transparency log

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

Download URL rustmc-0.13.0-cp39-abi3-macosx_11_0_arm64.whl
Size 2.0 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5180f37a3c15b839e635aa2f862a68df6c73244e29001507773b6f042d0c7c07
BLAKE2b-256 checksum
How to use checksums
88549994d141eb484e035a78e352701d15bfc2537e5b68877f822f362ab87bd2
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 Sep 26, 2026.

Transparency log

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

Download URL rustmc-0.13.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 2.1 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
bc3c8f804738c1afc1a450fa6ef3e9614b2392f92c23ea53ef51669458ff404b
BLAKE2b-256 checksum
How to use checksums
e2590a34d5e1c96559e8b7b43eadd86c6a639538d367e1aebe64da79eec4c751
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 Sep 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.13.0 This release

6 release files

0.12.0

6 release files

0.9.0

6 release files

0.8.0

6 release files

0.7.0

6 release files

0.6.0

6 release files

0.5.1

6 release files

0.4.0

5 release files

0.3.1

5 release files

0.3.0

5 release files

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