Skip to content

FMM ground truth as a Field - #13

Open
Tass0sm wants to merge 6 commits into
mainfrom
feature/gt-field
Open

Tass0sm wants to merge 6 commits into
mainfrom
feature/gt-field

Conversation

@Tass0sm

@Tass0sm Tass0sm commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Makes the FMM ground truth (ntfields.gt) usable anywhere a Field is: planners, ntfields.eval, and downstream code that takes a Field. The FMM itself is unchanged: obstacles are still slow (S* from the speed model), not impassable, which matches how NTFields are trained.

Changes

  • GoalField is a protocol (travel_time(q), gradient(q)), so fields that aren't networks can implement Field.towards. The network-backed dataclass is now EncodedGoalField.
  • GridField is a GoalField:
    • travel_time replaces value;
    • gradient is computed by autograd through the interpolation;
    • to(device) moves the grid once instead of copying it per query.
  • gt.FMMField(problem, resolution, interp, cache_size, device, default_planner="mppi"), a full Field:
    • one solve per distinct goal, in an LRU cache;
    • pair queries are grouped by goal;
    • ∇ with respect to the goal comes from the solve seeded at the start, since isotropic eikonal travel time is symmetric.
  • Catmull-Rom interpolation, now the default (interp="cubic"), in 2D and 3D. Its gradient is continuous across cell edges, so descent no longer zig-zags there. interp="linear" keeps the grid_sample path. The interpolation lives in the new ntfields.grid module.
  • envs.GridEnv.from_occupancy(occupancy, resolution, origin) builds an environment from an occupancy grid (a pyrobosim or ROS map). Its distance is a signed EDT stored at the cell centres, accurate to about half a cell. This adds scipy to the gt extra.
  • eval.travel_time_error(field, gt, goal, starts) takes any GoalField as the reference, with the goal passed in explicitly.

Breaking changes

  • GoalField(...) construction becomes EncodedGoalField(...). Annotations don't change.
  • GridField.value is removed; use travel_time.
  • travel_time_error takes a new goal argument.
  • FMM grids interpolate with Catmull-Rom by default.

Notes

  • Speed: on box2d/one_sphere (CPU), one solve takes 2 ms at 101² and 7–9 ms at 201². mppi plans within 0.1% of the FMM optimum in 10–16 ms (linear) or 60–80 ms (cubic). Cubic is slower because of per-op overhead at mppi's small batches. grid_sample(mode="bicubic") would make 2D cubic fast if that matters.
  • gradient_bidirectional solves twice per step (0.1–0.4 s per plan in 2D). It fails on queries that are exactly point-symmetric through an obstacle: the planner keeps the symmetry, so both fronts stay on each other's ridge, where ∇T isn't defined. The gradients themselves check out: ‖∇T‖·S* has a median of 1.000 over the domain. mppi isn't affected, which is why it's the default planner.

Testing

ruff, pyright and tests/unit + tests/test_end_to_end.py all pass (108 tests). New tests cover:

  • FMMField pair queries against towards, caching, symmetry, and planning with both planners;
  • gradients against finite differences and the free-space unit vector;
  • Catmull-Rom: passes through the nodes, gradient continuous across cell edges, reproduces linear functions in 3D;
  • GridEnv distance against an analytic disc, cell lookups, and a 3D box;
  • FMM on a GridEnv raster agrees with the analytic scene within 2%.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TBC2JbgSTTRbQQJoHPtEJx

Tass0sm and others added 6 commits November 16, 2026 11:53
The network-backed dataclass is now EncodedGoalField.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
travel_time replaces value; GridField can be moved to a device once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One cached solve per distinct goal; the goal gradient comes from the
start-seeded solve, since isotropic eikonal travel time is symmetric.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its gradient is continuous across cell edges, unlike multilinear
interpolation's, so descent doesn't zig-zag; interp="linear" keeps
the old grid_sample path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A signed distance transform at the cell centres, so FMMField and training
can run on maps that exist only as occupancy grids. Grid interpolation
moves to ntfields.grid, shared with GridField.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TBC2JbgSTTRbQQJoHPtEJx
The goal is now passed in explicitly, so an FMMField's towards(goal), or
another field's, works as well as a GridField. The README describes
FMMField and GridEnv.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TBC2JbgSTTRbQQJoHPtEJx
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