qat.pbo.PatternGroup

class qat.pbo.PatternGroup

A PatternGroup is a set of equivalent patterns. You can create a pattern group:

  • by calling the method new_group() of PatternManager

  • by instantiating this class manually (without passing any argument to the constructor) and then by linking this group to a PatternManager (use of groups or collections arguments in the constructor of PatternManager)

For instance, the following code block links a PatternGroup to a PatternManager:

from qat.pbo import PatternManager
from qat.pbo.collections import INVOLUTIONS

# The INVOLUTIONS object is a list of PatternGroup
# This collection is used to remove patterns H-H, CNOT-CNOT, ...
print("The collection 'INVOLUTIONS' is", INVOLUTIONS)

# Defines a plugin removing H-H, CNOT-CNOT, ...
plugin = PatternManager(collections=[INVOLUTIONS])
The collection 'INVOLUTIONS' is [<libcpp_pbo.PatternGroup object at 0x152e5fdbe3d0>]
add_pattern()

Add a pattern to this group

from qat.pbo import PatternGroup

# Define a group of equivalent patterns
group_swap = PatternGroup()

# Add items to this group
group_swap.add_pattern([("SWAP", {0, 1})])
group_swap.add_pattern([("CNOT", [0, 1]), ("CNOT", [1, 0]), ("CNOT", [0, 1])])

If the gate is undirected, use a set to describe qubits instead of a list: all the directed patterns will be iterated

Warning

Each undirected gate will increase the number of pattern by \(q!\) where \(q\) is the number of qubits of the gate

Parameters

pattern (pattern like) – Please refer to Writing patterns

pattern_to_remove()

Define a pattern to this group which have to be removed

from qat.pbo import PatternGroup

# Define a group of equivalent patterns
group_swap = PatternGroup()

# Add items to this group
group_swap.pattern_to_remove([("SWAP", {0, 1})])  # Pattern that should disappear in the final circuit
group_swap.add_pattern([("CNOT", [0, 1]), ("CNOT", [1, 0]), ("CNOT", [0, 1])])

If the gate is undirected, use a set to describe qubits instead of a list: all the directed patterns will be iterated

Warning

Each undirected gate will increase the number of pattern by \(q!\) where \(q\) is the number of qubits of the gate

Parameters

pattern (pattern like) – Please refer to Writing patterns