  Motivated by their central role in fault-tolerant quantum computation, we
study the sets of gates of the third-level of the Clifford hierarchy and their
distinguished subsets of `nearly diagonal' semi-Clifford gates. The Clifford
hierarchy gates can be implemented via gate teleportation given appropriate
magic states. The vast quantity of these resource states required for achieving
fault-tolerance is a significant bottleneck for the practical realisation of
universal quantum computers. Semi-Clifford gates are important because they can
be implemented with far more efficient use of these resource states.
  We prove that every third-level gate of up to two qudits is semi-Clifford. We
thus generalise results of Zeng-Chen-Chuang (2008) in the qubit case and of the
second author (2020) in the qutrit case to the case of qudits of arbitrary
prime dimension $d$.
  Earlier results relied on exhaustive computations whereas our present work
leverages tools of algebraic geometry. Specifically, we construct two schemes
corresponding to the sets of third-level Clifford hierarchy gates and
third-level semi-Clifford gates. We then show that the two algebraic sets
resulting from reducing these schemes modulo $d$ share the same set of rational
points.
