Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A world made of small time steps
A physics simulator is a flip-book. It knows the positions and speeds of everything now, works out the forces, and draws the next page a tiny moment later. Thin pages make a smooth, believable film. Thick pages make mistakes: a swinging pendulum slowly gains energy from nowhere, or a ball that should land softly is thrown back into the air. A reinforcement learning agent trained inside a buggy world will happily learn to exploit the bugs, so knowing how simulators go wrong matters as much as knowing how to use them.
MuJoCo (now open source from Google DeepMind) powers the Gymnasium robotics benchmarks; Isaac Sim and Isaac Lab train legged robots and robot hands with thousands of simulated copies in parallel.
- 1. A simulator advances the world in…
- 2. Too large a time step can make a simulation…
- 3. An RL agent in a buggy simulator may…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Time step (timestep): the interval between simulated states; MuJoCo’s default is 2 ms.
- Integrator: the rule that turns forces into the next state. Explicit Euler uses the old velocity; semi-implicit (symplectic) Euler updates the velocity first and moves with the new one, which is MuJoCo’s default ‘Euler’; RK4 evaluates the dynamics four times per step.
- Energy drift: the systematic change of total energy in a simulation of a system that should conserve it; a sign of integration error.
- Soft contacts: contacts modelled as stiff spring–dampers (MuJoCo’s constraint impedance, set by solref = (time constant, damping ratio)), which allow small penetrations.
- Stiffness and stability: a spring with natural frequency ω = √(k/m) needs dt·ω well below 1; MuJoCo recommends a contact time constant of at least twice the time step.
- Action repeat (frame skip): environments apply each action for several simulation steps (for example 5 × 2 ms = 10 ms of control).
- GPU simulation: Isaac Gym, Isaac Lab and MuJoCo XLA (MJX) step thousands of environments as batched array operations.
- 1. MuJoCo's default integrator is…
- 2. MuJoCo's solref sets a contact's…
- 3. Action repeat (frame skip) means…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Integrators and soft contact
Exercise 1.
- A frictionless pendulum integrated with explicit Euler, semi-implicit Euler and RK4, on batches of starting states.
- Accuracy against a reference run with a 0.1 ms RK4 step, and the relative energy error over long runs.
- A 1 kg ball dropped from 1 m onto a floor that, below height 0, pushes back with k·depth − c·velocity, c = 2ζ√(km); ζ = 1 is critical damping, so a correct simulation must not bounce.
- Checks: RK4 is the most accurate and explicit Euler the least; semi-implicit Euler’s energy error stays bounded while explicit Euler’s grows; the resting ball settles at depth mg/k.
Practice.
- Keep MuJoCo’s defaults (2 ms, semi-implicit Euler or implicitfast) unless you have a reason; use RK4 only for smooth systems without contacts.
- Check stability when you change stiffness, masses or the time step: contact time constants of at least 2 time steps, and no unexplained energy gain.
- Watch for exploits: if a policy finds surprising high rewards, replay it and look for penetration, jitter or energy gain.
- Use GPU simulators (Isaac Lab, MJX, Brax) when you need thousands of environments, and keep physics settings identical across them.
- Randomise physics parameters within physically valid ranges for transfer to real robots (topic L7-1).
def semi_implicit_euler(x, dt):
w = x[..., 1] - dt * G * np.sin(x[..., 0]) # velocity first
return np.stack([x[..., 0] + dt * w, w], -1) # then position with the new velocity
def drop_ball(k, zeta, dt, T=3.0, m=1.0, z0=1.0):
c = 2 * zeta * np.sqrt(k * m); z, v = z0, 0.0
for t in range(int(round(T / dt))):
f = -m * G + ((-k * z - c * v) if z < 0 else 0.0) # soft floor
v += dt * f / m; z += dt * v
return z- 1. RK4 is best suited to…
- 2. A surprising high reward should prompt you to…
- 3. Thousands of environments in parallel need…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why semi-implicit Euler conserves energy approximately. For a Hamiltonian system, semi-implicit Euler is a symplectic map: it preserves phase-space area exactly. A symplectic integrator exactly conserves a slightly perturbed energy, so the true energy oscillates within a band of size O(dt) instead of drifting. Explicit Euler is not symplectic; for an oscillator its update matrix has determinant 1 + dt²ω² > 1, so each step multiplies the energy by about that factor and it grows without bound.
Accuracy and cost. RK4’s error per unit time is O(dt⁴), against O(dt) for the Euler methods. In Exercise 2, RK4 with a 20 ms step (200 derivative evaluations per simulated second) was about 7,500 times more accurate in energy than semi-implicit Euler with a 1 ms step (1,000 evaluations). The advantage disappears at contacts, where forces switch on abruptly and high-order methods lose their order.
The stability limit for stiff springs. For a spring x″ = −ω²x, semi-implicit Euler’s update matrix has determinant 1 and trace 2 − dt²ω², so it is stable when dt·ω < 2. With damping and a contact that switches on and off within a step, energy is injected well before that: in Exercise 2 the critically damped floor launched the ball once dt·ω reached about 1. Penetration depth, set by k, and the time step, set by ω = √(k/m), must therefore be chosen together, which is why MuJoCo parametrises contacts by a time constant relative to the time step.
- 1. Semi-implicit Euler's energy error…
- 2. Explicit Euler's update matrix for an oscillator has determinant…
- 3. RK4 loses its advantage at…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How large is the energy drift of each integrator at different time steps, and for which combinations of contact stiffness and time step does a critically damped floor wrongly bounce?
History.
- E. Todorov, T. Erez and Y. Tassa (2012) introduced MuJoCo; DeepMind acquired it and made it free (2021) and open source (2022); MuJoCo XLA (MJX) followed in 2023.
- V. Makoviychuk and colleagues (2021) introduced Isaac Gym for GPU-parallel robot learning; NVIDIA’s Isaac Sim and Isaac Lab (formerly Orbit, M. Mittal and colleagues 2023) build on it.
- E. Hairer, C. Lubich and G. Wanner (2006) set out the theory of symplectic integrators.
- Earlier engines for robotics and games include ODE, Bullet (PyBullet) and DART.
Exercise 2.
- 32 pendulums from random starting angles (±2.5 rad) and speeds, integrated for 10 s with each integrator at time steps of 1, 5, 10 and 20 ms; the largest relative energy error over the run.
- A ball dropped from 1 m onto a critically damped floor with stiffness 10³, 10⁴, 10⁵ and 10⁶ N/m and time steps of 0.5, 1, 2, 5 and 10 ms; the highest point after 0.5 s (a correct simulation stays on the floor) and the deepest penetration. The contact part does not depend on the seed.
Largest relative energy error over 10 s (seed 0; seeds 1 and 2 within 6%):
| time step | explicit Euler | semi-implicit Euler | RK4 |
|---|---|---|---|
| 1 ms | 0.102 | 0.0031 | 5.9e-13 |
| 5 ms | 0.624 | 0.0154 | 5.2e-10 |
| 10 ms | 1.63 | 0.0307 | 1.3e-8 |
| 20 ms | 5.76 | 0.0604 | 4.1e-7 |
Rebound height in metres of the critically damped ball (0 = stayed on the floor), with dt·√(k/m) in brackets:
| stiffness | 0.5 ms | 1 ms | 2 ms | 5 ms | 10 ms |
|---|---|---|---|---|---|
| 10³ | 0 (0.02) | 0 (0.03) | 0 (0.06) | 0 (0.16) | 0 (0.32) |
| 10⁴ | 0 (0.05) | 0 (0.10) | 0 (0.20) | 0 (0.50) | 1.86 (1.00) |
| 10⁵ | 0 (0.16) | 0 (0.32) | 0 (0.63) | 6.34 (1.58) | 64.3 (3.16) |
| 10⁶ | 0 (0.50) | 3.41 (1.00) | 30.2 (2.00) | 111 (5.00) | 546 (10.00) |
Findings.
- Explicit Euler gained energy at every step size, 10% in 10 s even at 1 ms and nearly sixfold at 20 ms; semi-implicit Euler stayed within 0.3% to 6%; RK4 within 4e-7.
- Cost against accuracy: RK4 at 20 ms needed 200 derivative evaluations per simulated second and was about 7,500 times more accurate than semi-implicit Euler at 1 ms with 1,000.
- The floor launched the ball exactly when dt·√(k/m) reached 1 or more (7 of 20 settings), up to 546 m from a 1 m drop; every setting with dt·√(k/m) of 0.63 or less stayed on the floor.
- Penetration depth at the stable settings fell from 34–54 mm at 10³ N/m to about 5 mm at 10⁵ N/m and 2 mm at 10⁶ N/m: stiffer floors are more realistic but need smaller steps.
Simulators in practice
- MuJoCo: Gymnasium’s MuJoCo environments (HalfCheetah, Hopper, Humanoid), the DeepMind Control Suite, MuJoCo Menagerie robot models, and MJX for GPUs.
- Isaac Sim and Isaac Lab: photorealistic rendering, GPU physics (PhysX) and thousands of parallel environments for locomotion and manipulation.
- Others: PyBullet, Brax (JAX), Drake (for model-based control with exact contact), Genesis and Webots.
- Validation: compare simulated and real trajectories, identify parameters, and randomise what cannot be identified (topic L7-1).
References
- E. Todorov, T. Erez and Y. Tassa (2012). “MuJoCo: a physics engine for model-based control.” IROS.
- V. Makoviychuk and colleagues (2021). “Isaac Gym: high performance GPU-based physics simulation for robot learning.” NeurIPS Datasets and Benchmarks.
- M. Mittal and colleagues (2023). “Orbit: a unified simulation framework for interactive robot learning environments.” IEEE Robotics and Automation Letters.
- E. Hairer, C. Lubich and G. Wanner (2006). Geometric Numerical Integration. Springer.
- MuJoCo documentation: mujoco.readthedocs.io (computation, solver parameters).