Imitation Learning via Differentiable Physics

Siwei Chen, Xiao Ma, Zhongwen Xu

Abstract

Existing imitation learning (IL) methods such as inverse reinforcement learning (IRL) usually have a double-loop training process, alternating between learning a reward function and a policy and tend to suffer long training time and high variance. In this work, we identify the benefits of differentiable physics simulators and propose a new IL method, i.e., Imitation Learning via Differentiable Physics (ILD), which gets rid of the double-loop design and achieves significant improvements in final performance, convergence speed, and stability. The proposed ILD incorporates the differentiable physics simulator as a physics prior into its computational graph for policy learning. It unrolls the dynamics by sampling actions from a parameterized policy, simply minimizing the distance between the expert trajectory and the agent trajectory, and back-propagating the gradient into the policy via temporal physics operators. With the physics prior, ILD policies can not only be transferable to unseen environment specifications but also yield higher final performance on a variety of tasks. In addition, ILD naturally forms a single-loop structure, which significantly improves the stability and training speed. To simplify the complex optimization landscape induced by temporal physics operations, ILD dynamically selects the learning objectives for each state during optimization. In our experiments, we show that ILD outperforms state-of-the-art methods in a variety of continuous control tasks with Brax, requiring only one expert demonstration. In addition, ILD can be applied to challenging deformable object manipulation tasks and can be generalized to unseen configurations.

Introduction

Imitation Learning (IL) aims to teach agents complex behaviors by leveraging expert demonstrations. Traditionally, this is approached via Behavioral Cloning (BC) or Inverse Reinforcement Learning (IRL). However, BC suffers from covariate shift, where small errors accumulate and lead the agent into unfamiliar states. IRL and its adversarial counterparts (AIL) attempt to solve this by learning a reward function alongside the policy. This "double-loop" process is notoriously unstable, computationally expensive, and often results in high variance as the reward function becomes a "moving target" for the policy.

Researchers have identified a missed opportunity in these frameworks: the use of differentiable physics simulators (DPS). By treating the laws of physics as a differentiable component of the learning process, we can provide the agent with analytical gradients that explain why certain actions lead to specific outcomes, rather than just what the expert did.

The ILD Framework: Physics as a Prior

Imitation Learning via Differentiable Physics (ILD) replaces the unstable double-loop architecture with a streamlined, single-loop process. By incorporating a DPS directly into the computational graph, ILD uses the physics engine as a prior. The agent unrolls its dynamics by sampling actions from a parameterized policy and directly minimizes the distance between its own trajectory and the expert's demonstration.

Comparison of standard MDP and ILD computation graphs.

This integration allows gradients to be back-propagated through time via temporal physics operators, providing a direct signal for policy improvement. This "physics-aware" approach makes the learned policies more robust and transferable to unseen environment configurations.

Overcoming Optimization Challenges

While differentiable physics provides rich gradients, standard Backpropagation Through Time (BPTT) over long horizons can lead to a jagged optimization landscape. Strict time-step matching (L2 loss) often causes agents to get stuck in local minima. To address this, ILD introduces a dynamic learning objective based on the Chamfer-$\alpha$ distance, which treats trajectories as sets of points rather than rigid sequences.

Comparison of L2, Deviation, and Coverage losses for trajectory matching.

This objective consists of two primary components:

  1. Deviation Loss: Ensures the agent's states stay close to any point in the expert's trajectory, preventing the agent from wandering off-course.
  2. Coverage Loss: Ensures the agent's trajectory eventually covers all parts of the expert's demonstration, preventing "state collapse" where an agent might otherwise remain stationary near a single expert point.

Experimental Results

The researchers evaluated ILD against state-of-the-art (SOTA) methods like DAC and PWIL across eight standard Brax MuJoCo benchmarks and a complex Robot Cloth Manipulation task.

Key findings include:

  • Efficiency: ILD achieved SOTA results using only one single expert demonstration.
  • Performance: In a fixed one-hour training window, ILD achieved a 36% higher normalized score across all Brax tasks compared to baselines.
  • Stability: Unlike adversarial methods that exhibit wild performance swings, ILD's training curves are remarkably smooth with low variance.
  • Generalization: In cloth manipulation—a task with a 1,736-dimensional observation space—ILD successfully adapted to environments where testing dynamics differed from training demonstrations, a scenario where traditional baselines failed.

Conclusion

ILD demonstrates that incorporating differentiable physics into the imitation learning loop significantly enhances training speed, stability, and final performance. While the method currently requires a differentiable environment, it sets a new standard for sample-efficient imitation in continuous control and complex deformable object manipulation. Future work will look toward managing even longer horizons and exploring non-differentiable or multi-agent physics environments.

Summary updated

BibTeX
@misc{chen2022imitation,
  author = {Siwei Chen and Xiao Ma and Zhongwen Xu},
  title = {{Imitation Learning via Differentiable Physics}},
  year = {2022},
  eprint = {2206.04873},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2206.04873},
}
Figure