Skip to main content

Flat World

License Python CI

English | 中文

Warp-accelerated 2D physics engine with explicit FEM, impulse-based rigid bodies, and mixed-domain contact (analytical ground, height fields, voxel maps).

Features

  • FEM / soft bodies — explicit dynamics, linear elastic / Neo-Hookean / J2 plasticity
  • Rigid bodies — ball, box, capsule, mesh; 2D SAT; PGS impulses
  • Ground types — GroundDomain (plane), HeightFieldDomain, VoxelGridDomain; rigid and FEM contacts run as batched Warp kernels
  • Joints — revolute, weld, prismatic, spherical
  • GPU batching — unified FEM / spring manager + MixedContact penalty kernels

Quick start

Once published to PyPI (Trusted Publisher / OIDC):

pip install flat-world-model

Import the installed package as flatworld (PyPI name ≠ import name):

From source:

git clone https://github.com/swaggyliu/FlatWorld.git
cd FlatWorld
pip install -r requirements.txt
pip install -e .
import numpy as np
from flatworld import Mesh, FemDomain, SolidProp, Elastic, Gravity, ExplicitLoop, GroundDomain
from flatworld.wp_init import ensure_warp

ensure_warp()

conn = np.array([[0, 1, 3], [0, 3, 2]], dtype=np.int32)
coords = np.array([[0.5, 0.5], [0.7, 0.5], [0.5, 0.7], [0.7, 0.7]], dtype=np.float32)
mesh = Mesh(2, conn, coords)
domain = FemDomain(mesh, SolidProp(Elastic(E=2e4, nu=0.2, rho=40.0)), bcs=[Gravity([0, -1.0])])
ground = GroundDomain(2, [0, 0.0], [0, 1])

looper = ExplicitLoop(0.0, [domain, ground], useAdapativeDT=True)
for _ in range(60):
    looper.advanceWithTime(1.0 / 60.0)

.msh / .vtu meshes go through FEMesher and need meshio (pip install meshio). The Spirit Push game needs raylib.

Tests

# Headless (recommended for CI)
set HEADLESS=1          # Windows
export HEADLESS=1       # Linux / macOS
pytest test2D -q

# With GUI when a display is available
pytest test2D/test_2Dfem_elastic.py

51 pytest modules under test2D/ cover FEM, rigid contact, joints, friction, and all ground types.

Learning stacks (StateLeWM)

One state + tactile latent world model (~320K params), three controllers. Full architecture / losses: learning/README.md. Paradigm comparison + roadmap: docs/PARADIGMS.md. Site: GitHub Pages (enable once: Settings → Pages → Source = GitHub Actions) · Play: python -m game --mode pusht (You vs AI) · Manuscript: arXiv forthcoming (cs.RO, no PDF in-repo).

Paradigm Tasks Result Weights
WM + CEM PushToGoal · Two-room · Reacher 96–98% (50 ep) learning/checkpoints/{push_game,two_room,reacher}
WM + BPTT SuperMimic-2D skills multi-skill tracking supermimic2d/runs/lafan2d
WM + PPO Push-T 36/40 = 90% learning/checkpoints/push_t_wm_rsl (+ WM push_t)

▶ Push-T / You vs AI · SuperMimic promo

StateLeWM one-step world model

StateLeWM inference loop

1. WM + CEM — Push · Two-room · Reacher

Goal-free interaction → StateLeWM → online CEM on latent rollouts. No policy network. Same encoder/predictor/losses across scenes; only data and typed readouts change.

scene success (50 ep, seed 1000) tol / vel weights
PushToGoal (leftmost / rightmost / random) 98 / 96 / 96 % 0.08 m / 0.08 m/s learning/checkpoints/push_game
Two-room 49/50 = 98% 0.10 m / 0.15 m/s learning/checkpoints/two_room
Reacher 48/50 = 96% 0.06 m / 0.18 m/s learning/checkpoints/reacher
method Two-Room Reacher
StateLeWM (this repo — state + EE tactile) 98 96
LeWM 87 86
Fast-LeWM 98 88
DINO-WM 100 79
PLDM 97 78

Success %. StateLeWM is measured here; LeWM-family rows are published numbers on their Two-Room / Reacher (pixels, own protocols — LeWM: Maes et al., 2026; Fast-LeWM: Gao & Xu, 2026; DINO-WM: Zhou et al., 2025; PLDM: Sobal et al., 2025). Size anchor, not a controlled head-to-head.

2. WM + BPTT — SuperMimic-2D

A 2D recreation of SuperMimic: fit a shared rigid-body WM, then improve a goal-conditioned policy by BPTT through short imagined rollouts (walk / run / sprint / dance / jump / crouch / fight / fall-getup). Write-up: supermimic2d/README.md.

python -m supermimic2d.bake_refs
python -m supermimic2d.train --out supermimic2d/runs/lafan2d --library lafan2d --iters 80
python -m supermimic2d.render_promo --ckpt supermimic2d/runs/lafan2d/best.pt

3. WM + PPO — Push-T

Underactuated T-block alignment where CEM alone is weak. Freeze Push-T StateLeWM (push_t), train rsl-rl PPO with policy obs = WM latents ‖ task features, rewards / dynamics on real FlatWorld, vectorized envs. Sim eval 36/40 = 90%.

Push-T WM-obs PPO success summary 90%

python -m learning.train_rsl_wm_push_t \
  --wm learning/checkpoints/push_t \
  --out learning/checkpoints/push_t_wm_rsl \
  --num-envs 128 --num-workers 6 --target-rate 0.9
python -m learning.eval_rl_push_t_report \
  --policy learning/checkpoints/push_t_wm_rsl/best.pt \
  --wm learning/checkpoints/push_t \
  --out learning/results/wm_rl --tag wm_rsl

Spirit Push

A raylib prototype that uses the world model as a spirit: you click what to push and where; CEM plans the force. Five campaign stages stay inside the trained scene (1 circular EE + 3 boxes + 2 balls). After Gauntlet, layouts randomize (seeded — retry is the same mix).

python -m game
# or: python -m game --checkpoint learning/checkpoints/push_game
# Push-T: You vs AI (WASD left, WM+PPO right)
python -m game --mode pusht

Gold is the target, red is a one-hit hazard, the star is the goal. Sliders set bounce / grip / size.

Spirit Push start menu

Level 1 Push Level 3 Bank Level 5 Gauntlet

shot stage
menu pick best.pt (or drop your own .pt into learning/world_models)
Push shove the gold box onto the star
Bank high bounce, knock the gold ball
Gauntlet red sits in the lane — don't touch it

How the planner talks to the engine: learning/README.md. Regenerate shots: python scripts/capture_game.py.

Live-rendered screenshots from test2D demos:

Domino chain FEM + rigid 2D robot arm 25 boxes FEM height field Pendulum

35 scenes — full catalog: docs/gallery/README.md

Regenerate locally: python scripts/capture_gallery.py

Documentation

Project layout

FlatWorld/
├── flatworld/          # Core engine
│   ├── explicitloop.py # Main simulation loop
│   ├── mixedcontact.py # Batched FEM / spring / ground contact
│   ├── femspringmanager.py
│   ├── rigidmanager.py # Rigid SAT / PGS / batched ground contact
│   └── sat.py          # 2D box–box SAT
├── learning/           # StateLeWM: CEM tasks + Push-T PPO
├── supermimic2d/       # SuperMimic-style 2D motion imitation (WM+BPTT)
├── game/               # raylib prototype (python -m game)
├── test2D/             # 2D examples & pytest suite
└── docs/               # gallery, diagrams, paradigms

Third-party dependencies

Package License Used for
NVIDIA Warp Apache-2.0 GPU/CPU kernels
numpy BSD Arrays
meshio MIT .msh / .vtu via FEMesher
matplotlib PSF Viewer / plots
raylib (optional) zlib python -m game

License

Copyright 2025-2026 Dongyu Liu

Licensed under the Apache License, Version 2.0.

Metadata

Release files for flat-world-model 0.20.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 flat-world-model 0.20.0
File Size Uploaded Provenance Actions
flat_world_model-0.20.0.tar.gz 127.8 kB With provenance Details for flat_world_model-0.20.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flat-world-model 0.20.0
File Interpreter ABI Platform Actions
flat_world_model-0.20.0-py3-none-any.whl Python 3 none any Details for flat_world_model-0.20.0-py3-none-any.whl

Total release size: 265.9 kB

Release files / flat_world_model-0.20.0.tar.gz

Download URL flat_world_model-0.20.0.tar.gz
Size 127.8 kB
Tags Source
SHA-256 checksum
How to use checksums
821ae218ddbdbdf1e2474c8d9fc4693485580faeefebcab21240c5d7ad4ef8fc
BLAKE2b-256 checksum
How to use checksums
cd22ea8de3bf887d37ce08c129ff12b5eb7ae32da39b7df4f22d70aa85ce5619
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 28, 2026.

Transparency log

Release files / flat_world_model-0.20.0-py3-none-any.whl

Download URL flat_world_model-0.20.0-py3-none-any.whl
Size 138.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f4b1ef5ab87d20b199f83a5e75037a8dcef0ce2a280992b396f5afd7bb95b99
BLAKE2b-256 checksum
How to use checksums
18cb38ae7c890ccc6fb49e5318a138afb8269cc2f4b61e1a36ecaddfd561477c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 28, 2026.

Transparency log

Security for flat-world-model 0.20.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for flat_world_model-0.20.0.tar.gz

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 Oct 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.20.0 This release

2 release files Full provenance

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