  Motivated by recent discovery of yttrium-based high-temperature ternary
superconducting hydrides (e.g., CaYH$_{12}$, LaYH$_{12}$, and ScYH$_{6}$), we
have employed evolutionary algorithm and first-principles calculations to
comprehensively examine the structural stability and superconductivity of the
YMgH$_{x}$ system at high pressure. The hydrogen content $x$ and the pressure
are both important factors in the stability of these candidate structures. We
find that the stability of hydrogen-rich materials frequently necessitates
higher pressure. For instance, the pressures to stabilize $P4/mmm$-YMgH$_{8}$
and $Cmmm$-YMgH$_{12}$ are both more than 250 GPa. Hydrogen-less materials,
such as $I4_{1}/amd$-YMgH$_{2}$ and $P6_{3}/mmc$-YMgH$_{3}$, can be stable at
pressures as low as 100 GPa. In addition, we find a metastable structure for
YMgH$_{6}$ with the same space group as the $P4/mmm$-YMgH$_{8}$. A metastable
sodalite-like face-centered cubic (FCC) structure is also found in YMgH$_{12}$.
These four clathrate structures of $P4/mmm$-YMgH$_{6}$, $P4/mmm$-YMgH$_{8}$,
$Cmmm$-YMgH$_{12}$, and $Fd\bar{3}m$-YMgH$_{12}$ is made up of H14, H18, H24,
and H24 cages, respectively, in which the H-H pair exhibits weak covalent
bonding. According to phonon calculations, $P4/mmm$-YMgH$_{6}$ and
$P4/mmm$-YMgH$_{8}$ require a pressure of 300 GPa to maintain dynamic
stability, however $Cmmm$-YMgH$_{12}$ and $Fd\bar{3}m$-YMgH$_{12}$ can maintain
dynamic stability at pressures of 200 GPa and 250 GPa, respectively.
Electron-phonon coupling calculations indicate that they might be potential
high-temperature superconductors, with superconductivity intimately linked to
the H cage structure. The sodalite structure $Fd\bar{3}m$-YMgH$_{12}$ has a
$T_\mathrm{c}$ value of 190 K and a strong electron-phonon coupling constant of
2.18.
