Skip to main content

Composable building blocks for creating trajectory planners for autonomous systems, with NumPy and JAX implementations of the MPPI algorithm.

Project description

Faran Logo

Pipeline Status Coverage Benchmarks PyPI Python License

The GitHub mirror of Faran exists for discoverability. The primary repo is on GitLab.

Faran: A Composable Trajectory Planning Library

Faran provides composable building blocks for trajectory planning in Python, intended for researchers who want a working planner quickly and the flexibility to customize components as needed.

The library includes implementations of MPPI, dynamics models, samplers, state estimation algorithms, cost functions, and other useful components, with support for both NumPy and JAX backends. The API is flexible, type-safe, and designed to minimize boilerplate.

Faran also provides an optional visualization package, faran-visualizer, which can generate standalone HTML files for interactive visualizations of simulation results.

Animated visualization of a trajectory planner navigating through traffic

Faran is being actively developed — expect missing features, some gotchas and possible API changes. See the roadmap for what's available and what's coming. You can help by reporting issues or contributing fixes and features.

Why Faran?

The Python ecosystem has plenty of individual MPPI implementations 1, 2, 3, state estimation libraries 4, 5, and distance computation tools 6, but getting them to work together still requires a lot of glue code, plus reimplementing smaller components like cost functions, obstacle tracking, and motion prediction. Faran provides all of these under one roof, with a consistent API across backends.

  • Comprehensive — Includes all the components needed for a working planner: dynamics models, samplers, state estimation, cost functions, obstacle tracking, and more.
  • Composable — Swap out a cost function or sampler without reimplementing everything else.
  • Tested — Extensive test suite covering every component.
  • Backend-agnostic — Set up your planner with NumPy, then switch to JAX by changing only the imports. No code rewrite needed.

Installation

Python 3.13+ is required.

pip install faran          # NumPy + JAX (CPU only)
pip install faran[cuda]    # JAX with GPU support

The visualizer CLI can be installed separately:

pip install faran-visualizer

Quick Start

Here's how you can configure an MPPI planner for the MPCC formulation, assuming a kinematic bicycle model:

from faran.numpy import mppi, model, sampler, trajectory, types, extract
import numpy as np

reference = trajectory.waypoints(
    points=np.array([[0, 0], [10, 0], [20, 5], [30, 0], [40, -5], [50, 0]]),
    path_length=35.0,
)

planner, augmented_model, contouring_cost, lag_cost = mppi.mpcc(
    model=model.bicycle.dynamical(
        time_step_size=0.1, wheelbase=2.5,
        speed_limits=(0.0, 15.0), steering_limits=(-0.5, 0.5),
        acceleration_limits=(-3.0, 3.0),
    ),
    sampler=sampler.gaussian(
        standard_deviation=np.array([0.5, 0.05]),
        rollout_count=256,
        to_batch=types.bicycle.control_input_batch.create, seed=42,
    ),
    reference=reference,
    # Components do not implicitly assume any semantic meaning for state dimensions.
    position_extractor=extract.from_physical(lambda states: states.positions),
    # Configs are typically typed dicts, so you get IDE support without many imports.
    config={
        "weights": {"contouring": 100.0, "lag": 100.0, "progress": 1000.0},
        "virtual": {"velocity_limits": (0.0, 15.0)},
    },
)

Switching from faran.numpy to from faran.jax uses the JAX backend — same API, no other changes needed.

Full example: simulation loop + visualization

To see how the planner works, we can collect runtime data as follows:

from faran import access, collectors, metrics

planner = collectors.states.decorating(
    planner,
    transformer=types.augmented.state_sequence.of_states(
        physical=types.bicycle.state_sequence.of_states,
        virtual=types.simple.state_sequence.of_states,
    ),
)
registry = metrics.registry(
    error_metric := metrics.mpcc_error(contouring=contouring_cost, lag=lag_cost),
    collectors=collectors.registry(planner),
)

Now we set up a dummy simulation loop.

state = types.augmented.state.of(
    physical=types.bicycle.state.create(x=0.0, y=0.0, heading=0.0, speed=0.0),
    virtual=types.simple.state.zeroes(dimension=1),
)
nominal = types.augmented.control_input_sequence.of(
    physical=types.bicycle.control_input_sequence.zeroes(horizon=30),
    virtual=types.simple.control_input_sequence.zeroes(horizon=30, dimension=1),
)

for _ in range(100):
    control = planner.step(temperature=50.0, nominal_input=nominal, initial_state=state)
    state = augmented_model.step(inputs=control.optimal, state=state)
    nominal = control.nominal

Finally, we can visualize the results:

import asyncio
from faran_visualizer import MpccSimulationResult, configure, visualizer

errors = registry.get(error_metric)
result = MpccSimulationResult(
    reference=reference,
    states=registry.data(access.states.require()),
    contouring_errors=errors.contouring,
    lag_errors=errors.lag,
    time_step_size=0.1,
    wheelbase=2.5,
)

configure(output_directory=".")
asyncio.run(visualizer.mpcc()(result, key="quickstart"))

Quickstart visualization

For a step-by-step walkthrough, see the Getting Started guide.

Features

See the feature overview for the full list of supported components, backend coverage, and roadmap.

Documentation

Getting Started Installation, first planner, simulation loop
User Guide Core concepts, models, samplers, costs, obstacles, estimation, risk metrics, and more
Examples End-to-end scenarios with interactive visualizations
API Reference Factory functions, protocols, and type documentation

Contributing

See CONTRIBUTING.md and DESIGN.md.

Code of Conduct

See CODE_OF_CONDUCT.md.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

faran-0.2.9.tar.gz (195.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

faran-0.2.9-py3-none-any.whl (219.9 kB view details)

Uploaded Python 3

File details

Details for the file faran-0.2.9.tar.gz.

File metadata

  • Download URL: faran-0.2.9.tar.gz
  • Upload date:
  • Size: 195.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for faran-0.2.9.tar.gz
Algorithm Hash digest
SHA256 299f412c346811b22b86b419bd982ff2550f7c9f6542c8b1b417d2e86a6e8020
MD5 58e53de9b7e9c3fdf094db1d347dc69c
BLAKE2b-256 185b5e316a06c4ddf4213202188c97266b0e29751305b2d9d8705175403921a2

See more details on using hashes here.

File details

Details for the file faran-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: faran-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 219.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for faran-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ccfccc9cc7fce5a96eaaebb08d728b8790efe6b0f5761459e0516c7221fad99d
MD5 1f5fb2d7a50524eda3c1122c299ee5c6
BLAKE2b-256 c9d491eaa3817ab1aa69bc39343d50bec26bab54af4ea4d25232a4dc11025e92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page