How do you simulate pouring a liquid with a robot arm in Python? In the Alloy physics engine (pip install alloy-engine, Apache-2.0), the water is simulated as DFSPH particles that a rigid container carries and pours while the robot arm steps in MuJoCo Warp on a GPU (or MuJoCo C on the CPU).
Two setups work:
- Tilt a kinematic container with
sim.drive(..., pivot=lip)when you want to test the liquid flow without a robot file. - Make the container part of the robot's hand in its MJCF and ramp the wrist joint target.
The walkthrough below uses the second method, copied as published from the pouring how-to page.
1. Build a one-joint arm that carries a container
import numpy as np
import alloy
LIP_Z, INNER, WALL = 0.12, 0.05, 0.004
CUP_X, CUP_R, CUP_DEPTH = 0.04, 0.035, 0.06
OUT = INNER + 2 * WALL
def wall(name, centre, half):
pos, size = " ".join(map(str, centre)), " ".join(map(str, half))
return f'<geom name="{name}" type="box" pos="{pos}" size="{size}" mass="0.02"/>'
# the container is a body of the arm's link: five box geoms, its +x top edge (the lip) at the joint
GEOMS = "\n".join([
wall("floor", (-OUT / 2, 0, -OUT + WALL / 2), (OUT / 2, OUT / 2, WALL / 2)),
wall("back", (-OUT + WALL / 2, 0, -OUT / 2), (WALL / 2, OUT / 2, OUT / 2)),
wall("front", (-WALL / 2, 0, -OUT / 2), (WALL / 2, OUT / 2, OUT / 2)),
wall("left", (-OUT / 2, -OUT / 2 + WALL / 2, -OUT / 2), (OUT / 2, WALL / 2, OUT / 2)),
wall("right", (-OUT / 2, OUT / 2 - WALL / 2, -OUT / 2), (OUT / 2, WALL / 2, OUT / 2)),
])
ARM = f"""<mujoco><compiler angle="radian"/><worldbody><body name="hand" pos="0 0 0">
<joint name="wrist" type="hinge" axis="0 1 0" range="-2 2" damping="1"/>
{GEOMS}
</body></worldbody>
<actuator><position joint="wrist" kp="40" kv="4"/></actuator></mujoco>"""
The hand's link holds five box geoms (a floor and four walls, 4 mm thick, 5 cm inside) with its top edge, the lip, placed at the wrist joint. Because the container is part of the arm body, the arm cannot put it down, which keeps the setup focused on the pour itself.
2. Add water and a receiving cup, tilt the wrist, and count the water
scene = alloy.Scene(dt=0.005)
scene.add_ground()
scene.add_robot("arm", mjcf=ARM, pos=(0, 0, LIP_Z))
scene.add_liquid("water", size=(0.04, 0.04, 0.016), pos=(-OUT / 2, 0, LIP_Z - OUT + WALL + 0.0085))
scene.add_open_cylinder("cup", inner_radius=CUP_R, depth=CUP_DEPTH, wall=WALL, pos=(CUP_X, 0, 0))
sim = alloy.build(scene)
print(sim.routes()["water"]["route"], len(sim.state(["water"], world=0)["water.points"]))
sim.settle(0.2)
sim.run(2.0, targets={"wrist": (0.0, 1.5)})
sim.step(100)
p = sim.state(["water"], world=0)["water.points"]
in_cup = (np.hypot(p[:, 0] - CUP_X, p[:, 1]) < CUP_R) & (p[:, 2] < WALL + CUP_DEPTH)
past_lip = p[:, 0] > 0
print("over a third in the cup:", bool(in_cup.mean() > 1 / 3))
print("over 0.4 past the lip:", bool(past_lip.mean() > 0.4))
print(sim.check()["ok"])
liquid_sph 400
over a third in the cup: True
over 0.4 past the lip: True
True
sim.routes() confirms the water took the liquid_sph route with 400 particles. The wrist ramps to 1.5 rad (about 86 degrees) over 2 s, then steps another 0.5 s so the stream finishes falling. Because the stream leaves the lip with a small horizontal velocity, the receiving cup sits 4 cm past the lip rather than directly underneath it. sim.check()["ok"] is True: no world went INVALID (a DEGRADED world still passes it; sim.health() lists its flags).
Measured GPU throughput and RL pouring
From the measurements behind Alloy's paper (arXiv:2611.16312), on one NVIDIA L4:
- 200 ml pour throughput (physics only, warm, 10 ms period, pre-release build, 1 run per point): 0.53 / 2.0 / 7.1 simulated seconds per wall second (summed over worlds) at 1 / 4 / 64 parallel worlds.
-
RL training on the shipped
Pour-v0environment (alloy-engine 0.1.0rc2, one training run, PPO in 512 worlds): 118 of 128 held-out episodes (92.2 %) put at least 75 % of the water in the bowl at the 38.5-minute checkpoint.
Keep in mind
- CPU speed: Liquid simulation is slow on a CPU. Keep particle counts small and runs short on CPU, or move to an NVIDIA GPU for parallel rollouts.
-
Container opening size: A container opening needs at least 8 liquid particles across (32 mm at the default setting, 16 mm at
super, 12 mm atultra). A thin stream into a narrow receiver mostly misses unless surface tension is enabled (details). - Tilt speed and placement: Tilt slowly and place the cup past the lip. Dropping a block of water from above causes splashes over the rim.
-
Grasping a jug: A container held only by finger friction is not verified for pouring. Use either an MJCF-mounted vessel as above or a kinematic container tilted with
sim.drive. - Material combinations: A robot can share a scene with liquid, and liquid beside sand or paste meets it as a solid wall (no wetting), but liquid cannot start inside sand/paste or inside a free cloth or soft container.
- Full limits: Read Keep in mind before relying on a result.
Links
- Docs page this is based on: https://alloy.argonrobotics.ai/docs/how-to/pour-liquid-robot-arm/
- Liquids guide: https://alloy.argonrobotics.ai/docs/guides/liquids/
- Imitation data with liquids: https://alloy.argonrobotics.ai/docs/how-to/imitation-data-with-liquids/
- Code: https://github.com/argonrobotics-ai/alloy
- Paper: https://arxiv.org/abs/2611.16312
Top comments (0)