Graph rewriting is a popular tool for the optimisation and modification of graph expressions in domains such as compilers, machine learning and quantum computing. The underlying data structures are often port graphs - graphs with labels at edge endpoints. A pre-requisite for graph rewriting is the ability to find graph patterns. We propose a new solution to pattern matching in port graphs. Its novelty lies in the use of a pre-computed data structure that makes the pattern matching runtime complexity independent of the number of patterns. This offers a significant advantage over existing solutions for use cases with large sets of small patterns. Our approach is particularly well-suited for quantum superoptimisation. We provide an implementation and benchmarks showing that our algorithm offers a 20x speedup over current implementations on a dataset of 10000 real world patterns describing quantum circuits.
翻译:图重写是编译器、机器学习和量子计算等领域中用于优化和修改图表达式的一种常用工具。其底层数据结构通常是端口图——即在边端点处带有标签的图。图重写的一个先决条件是能够查找图模式。我们提出了一种针对端口图模式匹配的新解决方案。其新颖之处在于使用了一种预计算的数据结构,使得模式匹配的运行时复杂度与模式数量无关。对于具有大量小型模式的使用场景,这相比现有解决方案提供了显著优势。我们的方法特别适用于量子超优化。我们提供了实现和基准测试,结果表明在包含10000个描述量子电路的实际模式数据集上,我们的算法相比当前实现提供了20倍的加速。