ProjectQ-Framework / ProjectQ

ProjectQ: An open source software framework for quantum computing
https://projectq.ch
Apache License 2.0
876 stars 271 forks source link

New implementation of a general graph mapper for ProjectQ #340

Open Takishima opened 4 years ago

Takishima commented 4 years ago

This supersedes #324.

This implementation of a mapper for arbitrary graphs relies on storing the gates in a directed acyclic graph and then generating the swap operations in order to maximise the number of 2-qubit gates that can be applied simultaneously, while ensuring a minimal number of swaps.

Example of a use-case:

import networkx as nx
from projectq.cengines import GraphMapper

# Example of a 3x3 grid graph
mygraph = nx.Graph()
# Add horizontal edges
mygraph.add_edges_from((0, 1), (1, 2),  (3, 4), (4, 5),  (6, 7), (7, 8))
# Add vertical edges
mygraph.add_edges_from((0, 3), (3, 6),   (1, 4), (4, 7),  (2, 5), (5, 8))

mapper = GraphMapper(graph=mygraph)

# use as any other mapper