Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flexible-layer mapper (FlexlayerSwap) pass #1803

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
42db44d
add Register
itoko Feb 12, 2019
cd13703
add undirected_neighbors
itoko Feb 12, 2019
566cb30
WIP: add flexlayer swapper pass
itoko Feb 12, 2019
2d04837
fix #1791
itoko Feb 12, 2019
3f65ed6
Merge remote-tracking branch 'upstream/master' into pr-flexlayer
itoko Feb 13, 2019
b702400
add comments and lint
itoko Feb 13, 2019
7c03055
lint
itoko Feb 13, 2019
4450eb0
lint
itoko Feb 13, 2019
f432021
fix #1791
itoko Feb 13, 2019
6560757
add comments and refactor variable names
itoko Feb 13, 2019
18f08d2
linting
itoko Feb 13, 2019
7c7274b
Merge remote-tracking branch 'upstream/master' into pr-flexlayer
itoko Feb 14, 2019
c04d7d0
pylint for test_dependency_graph.py and test_flexlayer_heuristics.py
a-matsuo Feb 14, 2019
eb4252a
modified test_dependenchy_graph.py and test_flexlayer_heuristics.py
a-matsuo Feb 14, 2019
16a3c32
Merge pull request #1 from itoko/pylint-matsuo
itoko Feb 14, 2019
87e9c1f
merge master
itoko Jul 5, 2019
5b0a716
update aligning changes in basic classes
itoko Jul 5, 2019
e119d1d
remove initial_layout from constructor's argument
itoko Jul 9, 2019
37c1817
lint and replace crlf to lf
itoko Jul 9, 2019
4470ebe
increase human readability of print
itoko Jul 10, 2019
cf85e93
remove unused lines
itoko Jul 10, 2019
ccb0a3d
add more tests
itoko Jul 10, 2019
7c4e089
change to return iterator
itoko Jul 12, 2019
f02cc96
remove layer-type dependency graph
itoko Jul 12, 2019
6e783cb
increase readability
itoko Jul 12, 2019
46081ea
add type hint
itoko Jul 12, 2019
2d1a577
update comments
itoko Jul 12, 2019
ac4ec1d
expose dependency_graph_type parameter
itoko Jul 12, 2019
001d725
lint
itoko Jul 12, 2019
504c8a6
simplify cache algorithm
itoko Jul 12, 2019
8e79ae5
add FlexlayerSwap to swapper common test
itoko Jul 16, 2019
6d8d04a
move ancestors to dependency_graph
itoko Jul 17, 2019
31a9890
improve performance
itoko Jul 17, 2019
32cef83
fix RecursionError in ancestors for large circuits
itoko Jul 17, 2019
c42a381
lint
itoko Jul 17, 2019
ccc65ea
improve performance without ancestors
itoko Jul 17, 2019
4fd0103
add comments and do some renames
itoko Jul 24, 2019
44cf705
rename private classes and remove unused private method
itoko Jul 24, 2019
e341920
remove useless lines
itoko Jul 24, 2019
2ebb56b
tweak default parameter
itoko Aug 5, 2019
6867a21
Merge remote-tracking branch 'upstream/master' into pr-flexlayer
itoko Aug 8, 2019
7effabd
update pickles for test
itoko Aug 8, 2019
a762392
consider reset in dependency graph
itoko Aug 8, 2019
a8e0162
Merge remote-tracking branch 'upstream/master' into pr-flexlayer
itoko Aug 27, 2019
b04dd0c
consider id gate in dependency graph
itoko Aug 28, 2019
9ec90d1
add release note
itoko Aug 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions qiskit/transpiler/coupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ def shortest_undirected_path(self, physical_qubit1, physical_qubit2):
raise CouplingError(
"Nodes %s and %s are not connected" % (str(physical_qubit1), str(physical_qubit2)))

def undirected_neighbors(self, physical_qubit):
itoko marked this conversation as resolved.
Show resolved Hide resolved
"""List up neighbors of the `physical_qubit` in the undirected coupling graph.

Args:
physical_qubit (int): A physical qubit whose neighors should be listed up

Returns:
iterator: The neighbors of the physical qubit
"""
return self.graph.to_undirected().neighbors(physical_qubit)

@property
def is_symmetric(self):
"""
Expand Down
1 change: 1 addition & 0 deletions qiskit/transpiler/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __repr__(self):
for key, val in self._p2v.items():
str_list.append("{k}: {v},".format(k=key, v=val))
if str_list:
str_list.sort()
str_list[-1] = str_list[-1][:-1]
return "Layout({\n" + "\n".join(str_list) + "\n})"

Expand Down
1 change: 1 addition & 0 deletions qiskit/transpiler/passes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@
from .mapping.lookahead_swap import LookaheadSwap
from .remove_diagonal_gates_before_measure import RemoveDiagonalGatesBeforeMeasure
from .mapping.stochastic_swap import StochasticSwap
from .mapping.flexlayer_swap import FlexlayerSwap
15 changes: 15 additions & 0 deletions qiskit/transpiler/passes/mapping/algorithm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2019.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Module containing algorithms used in transpiler pass."""
49 changes: 49 additions & 0 deletions qiskit/transpiler/passes/mapping/algorithm/ancestors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

# This code is part of Qiskit.
#
# (C) Copyright IBM 2019.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
Utility for speeding up a function to find ancestors in DAG.
"""

from functools import lru_cache

import networkx as nx

CACHE_SIZE = 2 ** 10


class Ancestors:
itoko marked this conversation as resolved.
Show resolved Hide resolved
"""
Utility class for speeding up a function to find ancestors in DAG.
"""

def __init__(self, G: nx.DiGraph):
self._graph = G.reverse()

@lru_cache(maxsize=CACHE_SIZE)
def ancestors(self, n: int) -> set:
"""
Ancestor nodes of the node `n`
Args:
n: Index of the node in the `self._graph`
Returns:
Set of indices of the ancestor nodes.
"""
ret = set()
for n_succ in self._graph.successors(n):
if n_succ in ret:
continue
ret.add(n_succ)
ret.update(self.ancestors(n_succ))
return ret
Loading