  Ternary or more complex hydrogen-rich hydrides are the main hope of reaching
room-temperature superconductivity at high pressures. Their chemical space is
vast and its exploration is challenging. Here we report the investigation of
the La-Mg-H ternary system using the evolutionary algorithm USPEX at pressures
on the range 150-300 GPa. Several ternary superconducting hydrides were found,
including thermodynamically stable $P6/mmm$-LaMg$_{3}$H$_{28}$ with
$T_{\mathrm{C}}=164$ K at 200 GPa, $P/2m$-LaMgH$_8$, $C2/m$-La$_2$MgH$_{12}$
and $P2/m$-La$_3$MgH$_{16}$. In addition, novel binary hydrides were predicted
to be stable at various pressures, such as $Cm$-Mg$_6$H$_{11}$,
$P1$-MgH$_{26}$, $Fmm2$-MgH$_{30}$, $P1$-MgH$_{38}$ and
$R\overline{3}m$-LaH$_{13}$. We also report several novel low-enthalpy
metastable phases, both ternary and binary ones. Finally, we demonstrate
important methods of exploring very large chemical spaces and show how they can
improve crystal structure prediction.
