Augmenting Differentiable Simulators with Neural Networks to Close the Sim2Real Gap
Eric Heiden, David Millard, Erwin Coumans, Gaurav S. Sukhatme
I Introduction and Related Work
Simulators are crucial tools for planning and control algorithms to tackle difficult real world robotics problems. In many cases, however, such models diverge from reality in important ways, leading to algorithms that work well in simulation and fail in reality. Closing the sim2real gap has gained significant interest, and various dynamics modeling approaches have been proposed (Figure 2 left).
Various methods learn system dynamics from time series data of a real system. Such “intuitive physics” models often use deep graph neural networks to discover constraints between particles or bodies . We propose a general-purpose hybrid simulation approach that combines analytical models of dynamical systems with data-driven residual models that learn parts of the dynamics unaccounted for by the analytical simulation models.
Originating from traditional physics engines , differentiable simulators have been introduced that leverage automatic, symbolic or implicit differentiation to calculate parameter gradients through the analytical physics models for rigid-body dynamics , light propagation , and other phenomena .
Residual physics models augment physics engines with learned models to reduce the sim2real gap. Most of them introduce residual learning applied to the output of the physics engine, while we propose a more fine-grained approach, similar to Hwangbo et al. , where only at some parts in the simulator data-driven models are introduced. While in the network for actuator dynamics is trained through supervised learning, our end-to-end differentiable model allows backpropagation of gradients from high-level states to any part of the computation graph, including neural network weights, so that these parameters can be optimized efficiently, for example from end-effector trajectories.
II Approach
We propose a technique for hybrid simulation that leverages differentiable physics models and neural networks to allow for efficient system identification, design optimization, and gradient-based trajectory planning. By enabling any part of the simulation to be replaced or augmented by neural networks, we can learn unmodeled effects from data. Through template meta-programming, our open-source C++ implementationhttps://github.com/google-research/tiny-differentiable-simulator allows any variable participating in the simulation to be augmented by neural networks that accept input connections from any other variable. In the simulation code, such neural scalars (Figure 2 right) are assigned a unique name, so that in a separate experiment code a “neural blueprint” is defined that declares the neural network architectures and sets the network weights. We compute gradients of the weights and analytical simulation parameters using the multi-dimensional dual number implementation from Ceres and have support for many other automatic differentiation libraries.
III System Identification
Given the state trajectory from the target system, we optimize the following loss for system identification:
where is the discrete dynamics function mapping from the previous simulation state to the current state which is implemented by our physics engine given the parameter vector that consists of the parameters for the analytical model, plus the parameters that correspond to the weights of the neural networks in the simulation. To ensure the residual dynamics learned by the neural networks are minimal, we regularize the network weights by factor which penalizes large state contributions.
IV Overcoming Local Optima
We solve the nonlinear least squares problem from Equation 1 using the Levenberg-Marquardt algorithm (LMA). Such a gradient-based optimization method quickly finds local optima, but due to the highly nonconvex loss landscapes commonly encountered in system identification problems for nonlinear dynamics, the resulting parameter estimates often exhibit a poor fit to the real world data. To escape such poor local minima, we adapt a random search strategy, parallel basin hopping (PBH) , that, in our instantiation, runs multiple LMA solver and simulation instances in parallel while continuously randomizing the initial parameters from which the local solvers are restarted after convergence criteria, time limits, or maximum iteration counts are met.
V Results
We present preliminary results for sim2sim transfer to match the hybrid dynamics model to richer analytical simulations. Additionally, we demonstrate our system identification approach on a real-world dataset.
In our first experiment, we transfer rigid-body contact dynamics simulated using a velocity-level contact model formulated as a linear complementarity problem . Our hybrid simulator uses a point-based nonlinear-spring contact model where the normal force is solved analytically through the Hunt-Crossley model and the friction force is learned by a neural network that receives the relative velocities, contact normal force and penetration depth as input. Before optimizing the analytical and neural model parameters, the trajectories of a cube thrown horizontally on the ground differ dramatically. After system identification using PBH applied on Equation 1 given trajectories of positions and velocities from the target system, the gap is significantly reduced (Figure 1 left).
In the next experiment, we apply our approach to a real-world dynamical system. Given joint position trajectories from the double-pendulum dataset provided by Asseman et al. , we optimize inertia, masses, and link lengths of our simulated model and achieve a minimal sim2real gap (Figure 1 right).
VI Conclusion
We have demonstrated a simulation architecture that allows us to insert neural networks at any place in a differentiable physics engine to augment analytical models with the ability to learn dynamical effects from data. In our preliminary experiments, efficient gradient-based optimizers quickly converge to simulations that closely follow the observed trajectories from the target systems, while poor local minima are overcome through a random search strategy.
Future research is directed towards more automated ways to identify where such extra degrees of freedom are needed to close the sim2real gap given a few trajectories from the real system. Our loss function in Equation 1 regularizes the contributions of the neural networks to the overall system dynamics. Nonetheless, this approach does not prevent violating basic laws of physics, such as energy and momentum preservation. Hamiltonian and (Deep) Lagrangian neural networks explicitly constrain the solution space to remain consistent with such principles but need to be further investigated in the context of residual models in hybrid simulators.