Loop boundary optimization is a technique that extends pattern-based optimization to work across loop boundaries. Catalyst's cancel_inverses and merge_rotations transforms are examples of passes that take advantage of loop boundary optimization in structured programs.
Inputs
High-level program description (with loop structures)
Outputs
High-level program description (with loop structures)
Example
Consider the following simple quantum program.
defq_program1(angles):for i inrange(3):
qml.Hadamard(0)
qml.T(0)
qml.Hadamard(0)
This program can be optimized with a "cancel inverses" pass, recognizing that the Hadamards are adjacent to each other across the loop boundary. We can therefore remove both gates, with a small correction added outside the loop to account for the "single" Hadamards at the beginning of the first iteration and the end of the last iteration.
defq_program1_optimized(): qml.Hadamard(0)
for i inrange(3):
qml.T(0)
qml.Hadamard(0)
Typical usage
This technique can be incorporated into other pattern-based quantum optimizations whenever there is a loop structure in a quantum program.
Catalyst's cancel_inverses and merge_rotations transforms are examples of passes that take advantage of loop boundary optimization in structured programs.
References
[1] "Enabling Dataflow Optimization for Quantum Programs", David Ittah, Thomas Häner, Vadym Kliuchnikov, Torsten Hoefler, arXiv:2101.11030, 2021