  Simulating quantum systems is one of the most important potential
applications of quantum computers. The high-level circuit defining the
simulation needs to be compiled into one that complies with hardware
limitations such as qubit architecture (connectivity) and instruction (gate)
set. General-purpose quantum compilers work at the gate level and have little
knowledge of the mathematical properties of quantum applications, missing
further optimization opportunities. Existing application-specific compilers
only apply advanced optimizations in the scheduling procedure and are
restricted to the CNOT or CZ gate set. In this work, we develop a compiler,
named 2QAN, to optimize quantum circuits for 2-local qubit Hamiltonian
simulation problems, a framework which includes the important quantum
approximate optimization algorithm (QAOA). In particular, we exploit the
flexibility of permuting different operators in the Hamiltonian (no matter
whether they commute) and propose permutation-aware techniques for qubit
routing, gate optimization and scheduling to minimize compilation overhead.
2QAN can target different qubit topologies and different hardware gate sets.
Compilation results on four applications (up to 50 qubits) and three quantum
computers (namely, Google Sycamore, IBMQ Montreal and Rigetti Aspen) show that
2QAN outperforms state-of-the-art general-purpose compilers and
application-specific compilers. Specifically, 2QAN can reduce the number of
inserted SWAP gates by 11.5X, reduce overhead in hardware gate count by 68.5X,
and reduce overhead in circuit depth by 21X. Experimental results on the
Montreal device demonstrate that benchmarks compiled by 2QAN achieve the
highest fidelity.
