As robots move from controlled lab environments into the real world — navigating city streets, sharing factory floors with humans, and flying through cluttered airspace — the question is no longer can they work, but can we guarantee they are safe?
Classical control gives us stability. Machine learning gives us adaptability. But neither alone provides formal safety guarantees at runtime — the mathematical promise that a robot will never collide, never exceed a boundary, never enter a dangerous state, regardless of what its nominal controller wants to do.
This is the domain of Control Barrier Functions (CBFs): a framework that acts as a safety filter on top of any controller, solving a constrained optimization problem at each timestep to find the closest safe action to the desired one. The theory is elegant. The implementations have historically been painful — slow, inflexible, and difficult to extend.
CBFKit addresses this. It is built on JAX, so the safety filter is automatically differentiable, JIT-compiled, and vectorizable — the same code runs a single controller or thousands of Monte Carlo rollouts in parallel.
Composable Safety by Design
Every component in CBFKit is a pure function. No class hierarchies, no inheritance chains — just composable building blocks that you snap together into a simulation pipeline.
The safety filter sits at the heart of the pipeline. It receives the nominal control signal — whatever your planner or tracking controller wants to do — and solves a Quadratic Program to find the minimally invasive correction that keeps the system within its safe set. If the nominal command is already safe, it passes through unchanged. If not, the CBF bends it just enough.
JAX Under the Hood
Built on JAX from the ground up. Automatic differentiation for barrier gradients.
JIT compilation for real-time loop performance. vmap for massively
parallel Monte Carlo safety verification.
Every Tile Is a Runnable Example
Each animation below is rendered by a script in the repository — open a tile to read the source it came from.
















jax.vmap.Express Safety in a Few Lines
CBFKit's functional API lets you define dynamics, barriers, and controllers as composable building blocks. A complete safe simulation in under 40 lines.
import jax.numpy as jnp import cbfkit.simulation.simulator as sim import cbfkit.systems.unicycle.models.accel_unicycle as unicycle from cbfkit.controllers.cbf_clf import vanilla_cbf_clf_qp_controller from cbfkit.certificates import concatenate_certificates, rectify_relative_degree from cbfkit.certificates.conditions.barrier_conditions import zeroing_barriers # 1. Define dynamics dynamics = unicycle.plant (lam=1.0) # 2. Define a nominal goal-reaching controller nom_controller = unicycle.controllers.proportional_controller ( dynamics=dynamics, Kp_pos=1.0, Kp_theta=1.0 ) # 3. Define obstacles and barrier functions barriers = [rectify_relative_degree ( function=ellipsoid_cbf (center, radii), system_dynamics=dynamics, state_dim=4, form="high-order", )(certificate_conditions=zeroing_barriers.linear_class_k (5.0)) for center, radii in obstacles ] # 4. Compose the safety filter controller =vanilla_cbf_clf_qp_controller ( control_limits=jnp.array([100.0, 100.0]), dynamics_func=dynamics, barriers=concatenate_certificates (*barriers), ) # 5. Run the simulation — JIT-compiled for real-time speed x, u, z, p, *_ = sim.execute ( x0=jnp.array([0.0, 0.0, 0.0, 0.785]), dt=0.01, num_steps=1000, dynamics=dynamics, controller=controller, nominal_controller=nom_controller, use_jit=True, )
Beyond Vanilla CBFs
Real-world robots face noise, disturbances, and model uncertainty. CBFKit provides a spectrum of CBF formulations that match the right safety guarantee to the right problem.
Vanilla CBF
Robust CBF
Stochastic CBF
Risk-Aware CBF (CVaR)
All formulations share the same compositional API. You can concatenate multiple barriers (obstacle avoidance + workspace bounds + inter-robot separation) into a single QP, swap in a different solver backend (jaxopt, cvxopt, or casadi), and switch between deterministic and stochastic dynamics — all without changing the rest of your pipeline.
MPPI Meets Safety Filters
Sampling-based planning for complex environments, with CBF safety filtering on the executed trajectory. The best of both worlds.
Model Predictive Path Integral (MPPI) control generates candidate trajectories by sampling thousands of control sequences in parallel, weighting them by a user-defined cost function. CBFKit's MPPI implementation runs entirely in JAX — meaning the sampling, rollout, and cost evaluation are all JIT-compiled and GPU-acceleratable.
The MPPI planner outputs a reference trajectory. At each timestep, the CBF safety filter intervenes only if needed, ensuring that the executed control never violates the barrier constraints. This decouples planning quality from safety — you get aggressive, cost-optimal plans with ironclad safety guarantees.
GPU-Accelerated Monte Carlo Safety Verification
Don't just simulate once. Simulate a thousand times in parallel and statistically verify that your controller is safe.
CBFKit's Monte Carlo engine uses jax.vmap to run hundreds to thousands
of simulations simultaneously — each with different initial conditions, noise
realizations, or disturbance profiles. The result is a statistical safety certificate:
violation rates, minimum barrier values, and success probabilities
across your entire operating envelope.
Combined with the Optuna-powered parameter sweep engine, you can automatically search for the CBF and class-K function parameters that maximize performance while maintaining zero safety violations. The sweep engine tracks per-trial metrics and produces structured JSON results for downstream analysis.
From Single Integrators to 6-DOF Quadrotors
Eight ready-to-use robotic systems with dynamics, controllers, and barrier functions. Start running experiments in minutes, not days.
Three Backends, One API
From interactive exploration to publication-quality renders. Choose the visualization backend that fits your workflow.
The unified CBFAnimator class provides a single interface across all three
backends. Visualize 2D trajectories, 3D multi-robot coordination with distance-to-goal
panels, minimum inter-robot distance tracking, and per-robot safety metrics —
all generated from the same simulation results.
Generate New Systems Automatically
Define dynamics as symbolic expressions. CBFKit's code generator builds a complete system module with controllers, barriers, and ROS 2 nodes.
The code generation engine uses Jinja2 templates to transform symbolic dynamics definitions into fully typed Python modules. Specify your drift dynamics as string expressions, provide a control matrix, and list your barrier function formulas. CBFKit generates a complete package: plant model, barrier functions with automatic differentiation, Lyapunov functions, and optionally ROS 2 nodes for deployment.
This is how multi-robot coordination scales. Instead of hand-coding N(N-1)/2 inter-robot collision avoidance barriers, you define the pattern once and generate for any number of agents. The 3D multi-robot tutorial demonstrates this with 4 robots, 6 pairwise collision barriers, and 4 obstacle barriers — all auto-generated and composed into a single QP.
Tutorials for Every Level
From first barrier function to multi-robot 3D reach-avoid with MPPI. Each tutorial builds on the last.