Skip to content

Implement Manim 2D backend for CBFAnimator#367

Draft
Eduard-Zippenfenig wants to merge 4 commits into
bardhh:mainfrom
Eduard-Zippenfenig:feature/manim-2d-backend
Draft

Implement Manim 2D backend for CBFAnimator#367
Eduard-Zippenfenig wants to merge 4 commits into
bardhh:mainfrom
Eduard-Zippenfenig:feature/manim-2d-backend

Conversation

@Eduard-Zippenfenig

Copy link
Copy Markdown

Summary

Implements the 2D Manim backend for CBFAnimator, filling the gap where backend="manim" was accepted but raised NotImplementedError ("Manim 2D backend not yet implemented").

CBFAnimator(states, backend="manim") (or "manim-<low|medium|high|production>") now renders the full declarative element API — goals, circular/elliptical obstacles, line/scatter trajectories, agents with bodies/safety zones/solid+dashed trails, per-frame linear and data predictions, and the time overlay — to MP4 (or GIF) via Manim.

Demo

Rendered from the README quick-start CBF example (unicycle reach-avoid) with backend="manim-medium":

Manim 2D animator demo

The existing high-level path works as a drop-in: visualize_crowd(..., backend="manim") renders pedestrians with safety zones and fading predictions with no other changes.

Design

Mirrors the existing 3D module (manim_3d_multi_robot.py) throughout:

  • Guarded try: import manim with Scene = object fallback — the module imports cleanly when the manim extra is absent (as in CI), and the constructor raises the standard cbfkit[manim] ImportError via _require_manim().
  • Data injected into CBFAnimator2DScene via class attributes before scene.render(); animation driven by a ValueTracker + updaters.
  • Reuses the established manim-<quality> backend-string convention and _parse_manim_backend — no new config fields. Invalid quality strings raise ValueError before the dependency check.
  • White canvas so matplotlib-convention colors (e.g. black obstacles) stay visible; matplotlib-style color names translated to hex.
  • Render intermediates go to a temp dir, so the caller's cwd stays clean; the finished video is copied to the requested path.
  • _ManimMixin added to CBFAnimator alongside the matplotlib/plotly mixins; dispatch added to build/animate/save/show.

Also adds a [mypy-manim.*] stanza to mypy.ini.

Tests

  • Dependency-free (run in CI without manim): quality parsing for all five backend strings, import-guard ImportError, invalid-quality ValueError, and save() dispatch with a mocked render.
  • A real-render smoke test that skips when manim is not installed.
  • Full suite: 479 passed, 4 skipped locally (Python 3.11, manim 0.20.1); ruff check src clean; changed files formatted with black 25.11.0 (pre-commit pin).

🤖 Generated with Claude Code

Eduard-Zippenfenig and others added 3 commits July 18, 2026 18:08
Fills the declared gap where backend='manim' raised NotImplementedError.
Adds _ManimMixin + CBFAnimator2DScene rendering the full declarative
element API (goals, obstacles, trajectories, agents, predictions, time
overlay) on a white canvas, with quality selected via the existing
manim-<quality> backend-string convention. Renders MP4 or GIF; module
imports cleanly without manim installed (guarded like the 3D backend).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ender

Replaces the NotImplementedError pin with quality-parsing, import-guard,
and save-dispatch tests (dependency-free) plus a real-render smoke test
that skips when manim is not installed (as in CI).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Demo renders the README quick-start CBF example (unicycle reach-avoid)
via backend='manim-medium'.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Eduard-Zippenfenig
Eduard-Zippenfenig marked this pull request as draft July 18, 2026 15:30
…mple

Repeated renders in one process crashed because Manim's global config and
animation cache outlived each render's temp media dir. Scope overrides with
tempconfig and disable caching; add a regression test.

examples/unicycle/reach_goal/manim_2d_animation.py reproduces the showcase
GIF from the README quick-start simulation (CBFKIT_TEST_MODE-gated).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant