  We demonstrate a fast adjoint-based method to optimize tokamak and
stellarator equilibria against a pressure-driven instability known as the
infinite-$n$ ideal ballooning mode. We present three finite-$\beta$ (the ratio
of thermal to magnetic pressure) equilibria: one tokamak equilibrium and two
stellarator equilibria that are unstable against the ballooning mode. Using the
self-adjoint property of ideal MHD, we construct a technique to rapidly
calculate the change in the growth rate, a measure of ideal ballooning
instability. Using the~\texttt{SIMSOPT} framework, we then implement our fast
adjoint gradient-based optimizer to minimize the growth rate and find stable
equilibria for each of the three initially unstable equilibria.
