Skip to main content

turbo-ckf

PyPI version Python versions CI License: MIT OR Apache-2.0

turbo-ckf is a Rust-backed Cubature Kalman Filter package for high-throughput prediction/update loops. Implemented here purely as an experiment after reading the paper.

What This Package Optimizes

  • Fast prediction with built-in linear models:
    • predict_standard_model(...)
    • predict_standard_model_ckf(...)
    • predict_linear_model(F)
    • predict_linear_model_ckf(F)
  • Fast AHRS update path:
    • update_paper_ahrs(...)

predict(...) and update(...) also run through Rust, but callback cost in Python can dominate if your models are heavy.

Square-Root Variant

TurboSRCKF is a separate estimator that propagates the lower-triangular Cholesky factor of P directly. The filter loop never calls stable_cholesky on P, so the silent diagonal-jitter accumulation TurboCKF surfaces via jitter_count is structurally impossible in steady state. Use it when P becomes ill-conditioned (e.g., long predict chains with tiny Q/R, or rank-deficient seed covariances). Mirrors predict(...) + update(...); for closed-form linear predicts or the AHRS update use TurboCKF.

from turbo_ckf import TurboSRCKF
kf = TurboSRCKF(dim_x=4, dim_z=2, dt=0.1, hx=hx_vectorized, fx=fx_vectorized)
kf.predict()
kf.update(z)
# kf.chol_P is the lower-triangular factor; kf.P = chol_P @ chol_P.T

Callback Contract

Custom fx and hx must be vectorized:

  • Input shape is (2 * dim_x, dim_x).
  • fx output shape must be (2 * dim_x, dim_x).
  • hx output shape must be (2 * dim_x, dim_z).

If you pass pointwise callbacks, TurboCKF raises immediately.

Install

pip install turbo-ckf

Wheels are published for CPython 3.9 - 3.13 on Linux, macOS, and Windows.

Install from source (development)

From turbo-ckf/:

bash turbo_ckf/setup_env.sh

Usage

from turbo_ckf import TurboCKF

kf = TurboCKF(dim_x=2, dim_z=1, dt=0.1, hx=hx_vectorized, fx=fx_vectorized)
kf.predict_standard_model("constant_velocity")
kf.update(z)

State assignment is forgiving about spelling: x accepts lists, integer arrays, and column vectors; P, Q, R accept scalars (kf.R = 0.25 means 0.25 * I), 1-D diagonals (kf.Q = [1e-3, 1e-2]), or full matrices. Wrong sizes and non-finite values raise at assignment time with the attribute named in the error. Changing kf.dt after construction takes effect on the next predict, including the standard/linear-model paths.

A NaN or inf measurement raises instead of corrupting the state. For a missed measurement pass z=None, which runs the predict-only step and clears the innovation diagnostics.

Filtering a whole sequence

run(...) wraps the predict/update loop, stacks the per-step outputs, and handles measurement dropouts:

result = kf.run(zs)                # zs: (N, dim_z), or (N,) when dim_z == 1
result.xs, result.Ps               # posterior means / covariances, stacked
result.log_likelihoods, result.nis # per-step diagnostics

# Missed measurements: None entries (or all-NaN rows with
# nan_means_missing=True) skip the update for that step.
kf.run([z0, None, z2])
kf.run(zs, nan_means_missing=True)

# Per-step time steps and measurement noise:
kf.run(zs, dts=dt_array, Rs=r_stack)

run is available on both TurboCKF and TurboSRCKF. For linear models prefer the static TurboCKF.batch_filter, which runs the whole loop inside Rust in a single crossing.

AHRS path:

kf.predict_linear_model(Fk)
kf.update_paper_ahrs(z6, sigma_acc2=1e-2, sigma_mag2=1e-2)

Benchmarks

Paper-Reported Targets (Shing et al., arXiv:2602.12283)

These are the KCKF-vs-CKF results reported in the paper:

  • MacBook Pro 2021 (M1 Pro): KCKF 0.110 ms vs CKF 0.135 ms (18.79% lower time, about 1.23x faster).
  • Raspberry Pi 4 Model B: KCKF 1.28 ms vs CKF 1.51 ms (15.15% lower time, about 1.18x faster).

Local Results In This Repo

Measured on February 21, 2026 on Apple M4 Max, Python 3.12.0, NumPy 2.4.2.

From:

.venv-turbo-ckf/bin/python turbo_ckf_tests/verify_before_after.py --steps 50000 --repeats 7 --warmup 1 --parity-steps 500

Median runtime per 50k predict+update steps:

  • FilterPy (filterpy_predict_update): 2.354375 s (baseline)
  • TurboCKF callback path (turbo_callback_predict_update): 0.662003 s (3.56x vs FilterPy)
  • TurboCKF standard model KCKF (turbo_standard_model_predict_update): 0.539281 s (4.37x vs FilterPy)
  • TurboCKF standard model CKF (turbo_standard_model_ckf_predict_update): 0.549905 s (4.28x vs FilterPy)
  • KCKF-vs-CKF full-step speedup in this setup: 1.02x (0.549905 / 0.539281)

From:

.venv-turbo-ckf/bin/python turbo_ckf_tests/benchmark_paper.py
  • KCKF-vs-CKF (prediction only, backend): 1.67x
  • KCKF-vs-CKF (full step, backend): 1.09x
  • KCKF-vs-CKF (full step, wrapper): 1.03x

Interpretation:

  • The largest gains here are from the Rust-backed implementation versus pure-Python FilterPy loops (~3.5x to ~4.4x in these runs).
  • The direct KCKF-vs-CKF algorithmic gain is present but smaller on full-step end-to-end runs, and larger when isolating prediction equations.

Research Basis

  • This repo is an implementation of the KCKF AHRS equations described in:
  • Credit for the method belongs to the paper authors.

License

Dual-licensed under either:

  • MIT (LICENSE-MIT)
  • Apache-2.0 (LICENSE-APACHE)

Metadata

Release files for turbo-ckf 0.8.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 turbo-ckf 0.8.0
File Size Uploaded
turbo_ckf-0.8.0.tar.gz 89.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for turbo-ckf 0.8.0
File Interpreter ABI Platform
turbo_ckf-0.8.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
turbo_ckf-0.8.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
turbo_ckf-0.8.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details

Total release size: 1.5 MB

Release files / turbo_ckf-0.8.0.tar.gz

Download URL turbo_ckf-0.8.0.tar.gz
Size 89.4 kB
Tags Source
SHA-256 checksum
How to use checksums
969687b0f26d4af220907d41ac6466050668ac9687e7bee8ea0d708e1b4ce146
BLAKE2b-256 checksum
How to use checksums
f9b23b9fb897a68899e83db0f4f0afb5d73dae460e14667aa96cf9d05856a307
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 Aug 12, 2026.

Transparency log

Release files / turbo_ckf-0.8.0-cp39-abi3-win_amd64.whl

Download URL turbo_ckf-0.8.0-cp39-abi3-win_amd64.whl
Size 378.2 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
45e3ad4bb7eb15a8347e321da751717c8cf382fc09c3f0d096bf5e1796dcbe1a
BLAKE2b-256 checksum
How to use checksums
aa69c24fa5949d93ffb12da04fbc90a99dd79c7e6f8d35bf4158fd2a1baafd5e
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 Aug 12, 2026.

Transparency log

Release files / turbo_ckf-0.8.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL turbo_ckf-0.8.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 544.2 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
838b951a38304481a7713ecdf0392f4328fbd560543d2c37f73ecfc9f2c30449
BLAKE2b-256 checksum
How to use checksums
1426826aec65e25139f72192cdec7958f0e815b3c90f3e1485ec4452ed81a662
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 Aug 12, 2026.

Transparency log

Release files / turbo_ckf-0.8.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL turbo_ckf-0.8.0-cp39-abi3-macosx_11_0_arm64.whl
Size 461.4 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3ab7271c52a6aefaff381cd2d6c1259c3f2c18c8c710fd234c63a49b4ef3a0d7
BLAKE2b-256 checksum
How to use checksums
e806b2c4f7b459faac6e52e3285fbead7f3fcf222d59433efa2dbf567c5f2127
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 Aug 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.9.0

4 release files

This release

0.8.0 This release

4 release files

0.1.1

4 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