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.14.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.14.0
File Size Uploaded Provenance Actions
rustmc-0.14.0.tar.gz 598.9 kB With provenance Details for rustmc-0.14.0.tar.gz

Built distributions (wheels)

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

Total release size: 12.3 MB

Release files / rustmc-0.14.0.tar.gz

Download URL rustmc-0.14.0.tar.gz
Size 598.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2655fc98a93054f516d11a738d3d75bca79879d20684bf87fbee21bb4f74e7ec
BLAKE2b-256 checksum
How to use checksums
8c5b69cc7a62d35fc66952bc9357eb832c7c21e4eb029b48a861df3cf84ca40a
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.14.0-cp39-abi3-win_amd64.whl

Download URL rustmc-0.14.0-cp39-abi3-win_amd64.whl
Size 2.1 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
aa185cdd2d3f3c32dab6494cde18e856f26ffe76ca153e033c248327bbe7cd63
BLAKE2b-256 checksum
How to use checksums
db85b1dcb46ae5d84ac01a3364212c0458b33b060103a030f3de7f11e2f07469
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.14.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rustmc-0.14.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
56a9ef07ab1dd43e4daf8ab1cf67d64a24e9dec649dc7ed36e2cec806b8fe5df
BLAKE2b-256 checksum
How to use checksums
9906b7d61cbb1e81f1258f53b6ec41ae67bde9515a0965e28678fe6b782ccb4a
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.14.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL rustmc-0.14.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.5 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
53c8f1e986b929a7a31ed967b067299cd4ae5eb323befb266d12a3cd66003066
BLAKE2b-256 checksum
How to use checksums
a5e48c945a1cb17167d4ceca5bf9b5745a2178de4cf20bce94f9110e77790261
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.14.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL rustmc-0.14.0-cp39-abi3-macosx_11_0_arm64.whl
Size 2.2 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
765d95380a880ace6ff215091ce29352051912ebc047082df0fb8c3bea762935
BLAKE2b-256 checksum
How to use checksums
a0124a0419348175a565979dd9ea607649d4de6510f682daf195292100b16d28
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.14.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL rustmc-0.14.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 2.4 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
4c843266e9ebbdc3b8ed535b8a1e95fec66d1da07c93e46d3677105e40718a6f
BLAKE2b-256 checksum
How to use checksums
db9afa2d5ccce2348af6e52aa90553aa2a02e89c15f376da1a1acf11252755e7
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.14.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.14.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