  Quantum circuits are time dependent diagrams describing the process of
quantum computation. Usually, a quantum algorithm must be mapped into a quantum
circuit. Optimal synthesis of quantum circuits is intractable and heuristic
methods must be employed. With the use of heuristics, the optimality of
circuits is no longer guaranteed. In this paper, we consider a local
optimization technique based on templates to simplify and reduce the depth of
non-optimal quantum circuits. We present and analyze templates in the general
case, and provide particular details for the circuits composed of NOT, CNOT and
controlled-sqrt-of-NOT gates. We apply templates to optimize various common
circuits implementing multiple control Toffoli gates and quantum Boolean
arithmetic circuits. We also show how templates can be used to compact the
number of levels of a quantum circuit. The runtime of our implementation is
small while the reduction in number of quantum gates and number of levels is
significant.
