What this is about
MuJoCo is a physics engine. You give it a body made of parts and joints, and it tells you how that body moves under forces, how its feet push on the ground, and when it falls. Robot builders and animal researchers use it widely, and it is free to use under the Apache-2.0 license. We use it as the referee for everything we simulate.
This article explains what an engine like this does, what it needs from you, and why we rebuilt parts of it for the graphics card.
Why it matters
A brain model needs a body to be tested fairly, as we explain in A body for a brain. But a body is not a picture. It has weight, joints, friction and contact. If the physics is wrong, a result about the brain means nothing, because the body did something no real body would do.
So the engine must be trustworthy. A trusted, standard engine gives us something to compare against. When we build our own version, we do not ask readers to believe us. We ask the standard engine to say whether we are right.
What the engine does, step by step
An engine like MuJoCo repeats one small cycle many times a second. Each pass is a step.
- Read the pose. Where is every body part, and how fast is it moving?
- Add the forces. Gravity pulls down. Motors push on joints. Springs and dampers resist.
- Find the contacts. Which parts touch the floor or each other right now?
- Solve the constraints. A foot cannot sink into the ground. A joint cannot bend past its limit. The engine finds the forces that keep those rules true.
- Move the body. It takes a small step in time and updates the pose.
A walk is thousands of steps. The hard part is step 4, because contacts and limits switch on and off, and the engine has to find consistent forces each time.
How you describe a body
You write the body in a text file in a format called MJCF, which is a kind of XML. It lists the parts, their shapes and masses, the joints that connect them, the motors that move them and the floor they stand on.
Our fly body is described this way. It weighs 1.026 milligrams, with 44 joint motors and 6 sticky foot pads. A new animal means a new description file, not new engine code. That is a large part of why this approach is useful.
Why we rebuilt parts of it for the GPU
One fly in the engine runs fine on a processor. But we want crowds. Hundreds or thousands of animals, each with its own brain, at once. A graphics card has thousands of small workers, and each could simulate one body.
We first tried a ready-made GPU version, called MuJoCo Warp, on our card. After three fixes to its AMD support, the physics came out right. It then ran slower than six processor workers, which managed 70,582 steps a second. We closed that route.
So we took a different bet. We copy MuJoCo's own functions one by one into the Mojo language, for one fixed kind of body, with one GPU thread per animal. We call the result Kinestride. Every function is a file named after its original, and every output must agree with MuJoCo to within 1e-5 of the size of the field on random body states. That is one part in 100,000. And each function has a planted bug, a fault we add on purpose, that its check must catch.
What Kinestride gets you, and what it does not
The numbers below come from the Kinestride README and its comparison page.
| Bodies in one launch | Result |
|---|---|
| 65,536 | a full step in 84.7 ms on one AMD RX 7900 XTX |
| 65,536 (actuated fly) | 11.0 times MuJoCo on six processor workers |
| 16,384 | 6.0 times |
| 1,024 | 0.65 times, so the processor wins |
The lesson is the last row. A graphics card pays off only when the crowd is big. With a small crowd, the processor is faster. We show the same pattern with a spider in Simulating a spider: when the CPU beats the GPU.
Kinestride does not port every part of MuJoCo. The README lists what is missing, for example noslip and contact pairs beyond those it lists. A function that is not ported is refused with a message and not silently dropped. And MuJoCo stays the referee: a speed number from an unchecked build is not reported.
Glossary
- Physics engine: a program that computes how a body moves and touches the world.
- MJCF: the text format MuJoCo uses to describe a body.
- Joint: a point where two body parts connect and can bend or turn.
- Contact: a point where two parts touch, for example a foot on the floor.
- Constraint: a rule the engine must keep true, such as a foot not sinking into the floor.
- GPU: the chip in a graphics card, good at doing the same small task for many items at once.
- Referee: the trusted reference we compare our own code against.
Try it
- MuJoCo itself: mujoco.org has the documentation, and the code is on GitHub from Google DeepMind.
- Our GPU version: Kinestride. Read its comparison with MuJoCo to see when each one fits.
- Run the CPU-only smoke test the README names,
tools/smoke.sh. It needs no graphics card and no extra assets. - The full story of how we built and distrusted the port is in We rebuilt MuJoCo for the GPU, and trusted it only after planting bugs in it.
Previous in the series: A body for a brain. Next: The worm whose whole brain was mapped first.

Commentaires
Pas encore de commentaires.
Se connecter pour commenter.