The correct option is D electrolysis
Magnesium metal is high up in the reactivity series, is very reactive, and cannot be obtained from its compounds by heating with carbon. This is because it has more affinity for oxygen than carbon. Thus, it is obtained by electrolytic reduction.