Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

sequince

Sequince is a modular Sequential Monte Carlo (SMC) library for Bayesian inference, particle filtering, and related sequential methods.

Installation

sequince targets Python 3.11+ and can be installed directly from PyPI:

pip install sequince

Features

  • Array API support for NumPy, JAX, PyTorch, and CuPy backends.
  • Compose SMC pipelines from reusable weighting, resampling, mutation, and control steps.
  • Prebuilt pipelines with make_standard_bayesian_smc and other pre-built recipes.
  • Analyse runs via SMCResult, including posterior resampling and diagnostics helpers.
  • Estimate Bayesian evidence alongside posterior sampling.
  • Save checkpoints and resume sampling runs.

Quick start

Below, we show a short example of how to use sequince, for more detailed examples, see the documentation.

Here, we fit a straight line, y = slope * x + intercept, to synthetic data with independent Gaussian measurement errors and uniform priors on both parameters. The log-prior and log-likelihood callbacks accept particles shaped (n_particles, n_parameters) and return one log density per particle.

import numpy as np
from sequince import ParticleState, make_standard_bayesian_smc


def log_prior(theta, context):
    """Uniform log-prior"""
    # log-prior and -likelihood can optionally accept context to access shared data.
    lower, upper = context.shared["bounds"]
    inside = np.all((theta >= lower) & (theta <= upper), axis=-1)
    log_density = -theta.shape[-1] * np.log(upper - lower)
    return np.where(inside, log_density, -np.inf)


def log_likelihood(theta, context):
    """Gaussian log-likelihood"""
    x = context.shared["x"]
    y = context.shared["y"]
    sigma = context.shared["sigma"]
    slope = theta[..., 0, None]
    intercept = theta[..., 1, None]
    residual = (y - (slope * x + intercept)) / sigma
    return -0.5 * np.sum(
        residual**2 + np.log(2 * np.pi * sigma**2), axis=-1
    )


# Construct the runner
# `smc` is the main runner
# `posterior` contains definitions of the tempered posterior
# `metadata` contains metadata passed between the SMC steps
smc, posterior, metadata = make_standard_bayesian_smc(
    log_prior,
    log_likelihood,
)

rng = np.random.default_rng(42)

# Generate observations with true slope 2 and intercept 1.
x = np.linspace(-1, 1, 20)
sigma = 0.5
y = 2 * x + 1 + rng.normal(scale=sigma, size=x.shape)

bounds = [-5, 5]

# Draw initial (slope, intercept) particles from the prior.
n = 1000
initial_particles = rng.uniform(*bounds, size=(n, 2))
# Construct the initial state
initial_state = ParticleState(particles=initial_particles)

# Construct the shared context dictionary that will be exposed to the log_prior
# and log_likelihood
shared_context = dict(bounds=bounds, x=x, y=y, sigma=sigma)

# Run the SMC
results = smc.run(
    initial_state,
    rng=rng,
    shared_context=shared_context,
    metadata=metadata,
)

# Obtain equal-weight posterior samples and their weights
samples, sample_weights = results.posterior_samples(
    rng=rng, method="rejection"
)

# Compare the posterior means with the true slope 2 and intercept 1.
mean_slope, mean_intercept = np.average(
    samples, weights=sample_weights, axis=0
)
print(f"Posterior mean slope: {mean_slope:.2f}")
print(f"Posterior mean intercept: {mean_intercept:.2f}")

See the documentation for details on the different components (shared context, metadata, results), composing custom pipelines and implementing additional steps.

Documentation

Full documentation is maintained in the docs/ directory and published to Read the Docs: https://sequince.readthedocs.io

Examples

The sequince-examples repository and corresponding documentation contain examples highlighting different features in sequince.

Contributing

Bug reports, feature requests, and pull requests are welcome via the GitHub repository. Please see the contributing guidelines and AI policy.

The following repositories are part of the sequince ecosystem:

  • sequince-density: provides density estimators for sequince, supporting preconditioned SMC and ASPIRE-style analyses
  • sequince-bilby: provides an interface for using prebuilt sequince samplers with bilby
  • orng: provides cross-backend random number generation
  • acai: provides array-API compatible control flow and iteration

License

Licensed under the MIT License.

Metadata

Release files for sequince 0.1.0b1

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

Source distribution (sdist)

Source distribution for sequince 0.1.0b1
File Size Uploaded Provenance Actions
sequince-0.1.0b1.tar.gz 347.7 kB With provenance Details for sequince-0.1.0b1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sequince 0.1.0b1
File Interpreter ABI Platform Actions
sequince-0.1.0b1-py3-none-any.whl Python 3 none any Details for sequince-0.1.0b1-py3-none-any.whl

Total release size: 555.4 kB

Release files / sequince-0.1.0b1.tar.gz

Download URL sequince-0.1.0b1.tar.gz
Size 347.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5fb93b6dbba6aaad1aa101b58d8f6d81e3e62c570388ba41c45a4d5ce7f2d7e6
BLAKE2b-256 checksum
How to use checksums
3c044dd1fdc52678068be9dca4fbec1472044aaa3826acbb07929ece99aab62a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 23, 2026.

Transparency log

Release files / sequince-0.1.0b1-py3-none-any.whl

Download URL sequince-0.1.0b1-py3-none-any.whl
Size 207.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4c85cfe9c6c0ebd3ebeed5953fec79ef58d6b365df3232d8fff57e8d4954b40
BLAKE2b-256 checksum
How to use checksums
bcbc8d12a3ea38b7569e773efa574964110435b20ab3d9719b0185dc8d716cc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 23, 2026.

Transparency log

Security for sequince 0.1.0b1

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 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sequince-0.1.0b1.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 Oct 23, 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