Robust quantum compilation and circuit optimisation via energy minimisation

We explore a method for automatically recompiling a quantum circuit <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow class="MJX-TeXAtom-ORD"><mml:mi class="MJX-tex-caligraphic" mathvariant="script">A</mml:mi></mml:mrow></mml:math> into a target circuit <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow class="MJX-TeXAtom-ORD"><mml:mi class="MJX-tex-caligraphic" mathvariant="script">B</mml:mi></mml:mrow></mml:math>, with the goal that both circuits have the same action on a specific input i.e. <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow class="MJX-TeXAtom-ORD"><mml:mi class="MJX-tex-caligraphic" mathvariant="script">B</mml:mi></mml:mrow><mml:mrow class="MJX-TeXAtom-ORD"><mml:mo stretchy="false">&amp;#x2223;</mml:mo><mml:mrow class="MJX-TeXAtom-ORD"><mml:mi>i</mml:mi><mml:mi>n</mml:mi></mml:mrow><mml:mo fence="false" stretchy="false">&amp;#x27E9;</mml:mo></mml:mrow><mml:mo>=</mml:mo><mml:mrow class="MJX-TeXAtom-ORD"><mml:mi class="MJX-tex-caligraphic" mathvariant="script">A</mml:mi></mml:mrow><mml:mrow class="MJX-TeXAtom-ORD"><mml:mo stretchy="false">&amp;#x2223;</mml:mo><mml:mrow class="MJX-TeXAtom-ORD"><mml:mi>i</mml:mi><mml:mi>n</mml:mi></mml:mrow><mml:mo fence="false" stretchy="false">&amp;#x27E9;</mml:mo></mml:mrow></mml:math>. This is of particular relevance to hybrid, NISQ-era algorithms for dynamical simulation or eigensolving. The user initially specifies <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow class="MJX-TeXAtom-ORD"><mml:mi class="MJX-tex-caligraphic" mathvariant="script">B</mml:mi></mml:mrow></mml:math> as a blank template: a layout of parameterised unitary gates configured to the identity. The compilation then proceeds using quantum hardware to perform an isomorphic energy-minimisation task, and an optional gate elimination phase to compress the circuit. If <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow class="MJX-TeXAtom-ORD"><mml:mi class="MJX-tex-caligraphic" mathvariant="script">B</mml:mi></mml:mrow></mml:math> is insufficient for perfect recompilation then the method will result in an approximate solution. We optimise using imaginary time evolution, and a recent extension of quantum natural gradient for noisy settings. We successfully recompile a <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mn>7</mml:mn></mml:math>-qubit circuit involving <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mn>186</mml:mn></mml:math> gates of multiple types into an alternative form with a different topology, far fewer two-qubit gates, and a smaller family of gate types. Moreover we verify that the process is <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mi>r</mml:mi><mml:mi>o</mml:mi><mml:mi>b</mml:mi><mml:mi>u</mml:mi><mml:mi>s</mml:mi><mml:mi>t</mml:mi></mml:math>, finding that per-gate noise of up to <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mn>1</mml:mn><mml:mi mathvariant="normal">&amp;#x0025;</mml:mi></mml:math> can still yield near-perfect recompilation. We test the scaling of our algorithm on up to <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mn>20</mml:mn></mml:math> qubits, recompiling into circuits with up to <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mn>400</mml:mn></mml:math> parameterized gates, and incorporate a custom adaptive timestep technique. We note that a classical simulation of the process can be useful to optimise circuits for today's prototypes, and more generally the method may enable `blind' compilation i.e. harnessing a device whose response to control parameters is deterministic but unknown.The code and resources used to generate our results are openly available online \cite{githubLink} \cite{mmaGithubLink}. A simple Mathematica demonstration of our algorithm can be found at questlink.qtechtheory.org.