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

Implements the LineInititialMapper strategy #5831

Merged
merged 72 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
62100c1
added abstract initial mapper and identity initial mapper
ammareltigani Aug 15, 2022
9df051b
added __str__ and __repr__ for MappingManager
ammareltigani Aug 15, 2022
8610ae2
minor bug
ammareltigani Aug 15, 2022
d9a7a3c
made MappingManager not serializable
ammareltigani Aug 16, 2022
c774674
removed unused import
ammareltigani Aug 16, 2022
a06c240
merging with mapping-manager repr and str PR #5828
ammareltigani Aug 16, 2022
c12cc03
pushed AbstractInitialMapping and IdentityInitialMapping name to 'cir…
ammareltigani Aug 16, 2022
83e976f
minor lint fix
ammareltigani Aug 16, 2022
24acc3d
addressed comments
ammareltigani Aug 16, 2022
2e1cec7
Merge branch 'add-str-and-repr-to-mapping_manager' into routing-initi…
ammareltigani Aug 16, 2022
79061de
addressed comments
ammareltigani Aug 16, 2022
dfe80a9
fixed bug with edges not being sorted for graph equality testing
ammareltigani Aug 16, 2022
cb798dc
Merge branch 'add-str-and-repr-to-mapping_manager' into routing-initi…
ammareltigani Aug 16, 2022
6ee60a9
fixed bug with digraphs repr method in MappingManager and added test …
ammareltigani Aug 16, 2022
0c6de8b
Merge branch 'add-str-and-repr-to-mapping_manager' into routing-initi…
ammareltigani Aug 16, 2022
ecadfdb
addressed some comments
ammareltigani Aug 16, 2022
7819263
added grid testing device
ammareltigani Aug 17, 2022
5dd4577
added grid routing testing device
ammareltigani Aug 16, 2022
cc79064
formatting
ammareltigani Aug 16, 2022
fecc4b0
added line_initial_mapper and some tests; needs more testing
ammareltigani Aug 16, 2022
b3a1445
merged with device setup
ammareltigani Aug 17, 2022
9bcf54f
formatting
ammareltigani Aug 17, 2022
f4dae72
formatting
ammareltigani Aug 17, 2022
9ecb52a
changed interface for LineInitialMapper and added better tests; test …
ammareltigani Aug 17, 2022
719b284
addressed comments and added ring device
ammareltigani Aug 17, 2022
8cbbe8f
Merge branch 'routing-initial_mapping_device_setup' into routing-line…
ammareltigani Aug 17, 2022
735cba8
added test for supportin directed graphs
ammareltigani Aug 17, 2022
9ba9cef
changed interface for AbstractInitialMapper
ammareltigani Aug 17, 2022
211bb2d
Merge branch 'routing-initial_mapping_setup' into routing-line_initia…
ammareltigani Aug 17, 2022
82cdbc0
formatting
ammareltigani Aug 17, 2022
632dfe6
Merge branch 'master' into routing-initial_mapping_device_setup
ammareltigani Aug 19, 2022
fca9052
changed RoutingTestingDevice interface; need to change is_isomorphic …
ammareltigani Aug 19, 2022
34ef897
added hard-coded isomorphism tests
ammareltigani Aug 19, 2022
67546d8
fixed type issue
ammareltigani Aug 19, 2022
e120be2
Merge branch 'master' into routing-line_initial_mapper
ammareltigani Aug 19, 2022
0d2345c
removed redundant imports
ammareltigani Aug 19, 2022
209cc35
Merge branch 'routing-initial_mapping_device_setup' into routing-line…
ammareltigani Aug 19, 2022
2544069
merged with routing testing device PR #5830
ammareltigani Aug 19, 2022
4493826
simplified _value_equalit_values_
ammareltigani Aug 19, 2022
8827b91
addressed comments
ammareltigani Aug 19, 2022
70de81e
Merge branch 'routing-initial_mapping_device_setup' into routing-line…
ammareltigani Aug 19, 2022
60ed0ac
removed unused import
ammareltigani Aug 19, 2022
eefc089
Merge branch 'routing-initial_mapping_device_setup' into routing-line…
ammareltigani Aug 19, 2022
c7506bd
fixed nits
ammareltigani Aug 20, 2022
d92f515
Merge branch 'routing-initial_mapping_device_setup' into routing-line…
ammareltigani Aug 20, 2022
d41cedb
Merge branch 'master' into routing-line_initial_mapper
tanujkhattar Aug 20, 2022
7509aa9
addressed comments
ammareltigani Aug 23, 2022
c21eae2
formatting
ammareltigani Aug 23, 2022
854e867
Merge branch 'routing-line_initial_mapper' of https://github.com/amma…
ammareltigani Aug 23, 2022
bad20d3
small fixes
ammareltigani Aug 23, 2022
26f14bd
removed unused import
ammareltigani Aug 23, 2022
4170236
modified test file
ammareltigani Aug 23, 2022
6bed99a
debugging
ammareltigani Aug 23, 2022
5f4b848
removed print statements
ammareltigani Aug 23, 2022
e1de30a
debugging statement
ammareltigani Aug 23, 2022
3237bd7
debugging statement
ammareltigani Aug 24, 2022
64f6ba8
fix
ammareltigani Aug 24, 2022
a2d8d2d
fix
ammareltigani Aug 24, 2022
1b8c315
print statement
ammareltigani Aug 24, 2022
06ab64e
edges sorting
ammareltigani Aug 24, 2022
80b1f0e
addressed comments; ready for review
ammareltigani Aug 24, 2022
0f1454d
fixed type bug
ammareltigani Aug 24, 2022
7c4ebbd
cleanup
ammareltigani Aug 24, 2022
9835eb1
ready for review
ammareltigani Aug 25, 2022
c72de13
type and lint fixes
ammareltigani Aug 25, 2022
2ecb278
slightly modified _make_circuit_graph()
ammareltigani Aug 25, 2022
54e96ca
Merge branch 'master' into routing-line_initial_mapper
tanujkhattar Aug 25, 2022
6989acc
added test for testing valid circuits and fixed bug in _make_circuit_…
ammareltigani Aug 25, 2022
6c8a661
Merge branch 'routing-line_initial_mapper' of https://github.com/amma…
ammareltigani Aug 25, 2022
b6c4bb3
Merge branch 'master' into routing-line_initial_mapper
ammareltigani Aug 26, 2022
cfe8704
fixed nits
ammareltigani Aug 27, 2022
c69a0db
Merge branch 'routing-line_initial_mapper' of https://github.com/amma…
ammareltigani Aug 27, 2022
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
Prev Previous commit
Next Next commit
added test for supportin directed graphs
  • Loading branch information
ammareltigani committed Aug 17, 2022
commit 735cba8200ea7ffe56c4a84e88b851f64ff68e3e
2 changes: 1 addition & 1 deletion cirq-core/cirq/transformers/routing/line_initial_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _closest_unmapped_qubit(self, source: 'cirq.Qid') -> 'cirq.Qid':
# by MappingManager too (and likely subsequent initial mapping strategies)? Particularly,
# since there is no good way of representating a graph using a hashable object, the
# 'graph_equality' bit here can become standard or we can file an issue for it.
def _value_equality_values_(self) -> None:
def _value_equality_values_(self):
"""Two LineInitialMapper(s) are equal if they execute on the same device graph."""
if nx.is_directed(self.device_graph):
return (
Expand Down
34 changes: 25 additions & 9 deletions cirq-core/cirq/transformers/routing/line_initial_mapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_line_breaking_on_grid_device():
# -if # of physical qubits <= # of logical qubits then strategy should succeed

step_circuit = construct_step_circuit(49)
device = cirq.testing.construct_grid_device(7)
device = cirq.testing.construct_square_device(7)
device_graph = device.metadata.nx_graph
mapper = cirq.LineInitialMapper(device_graph)
mapping = mapper.initial_mapping(step_circuit)
Expand All @@ -64,7 +64,7 @@ def test_line_breaking_on_grid_device():
def test_small_circuit_on_grid_device():
circuit = construct_small_circuit()

device_graph = cirq.testing.construct_grid_device(7).metadata.nx_graph
device_graph = cirq.testing.construct_square_device(7).metadata.nx_graph
mapper = cirq.LineInitialMapper(device_graph)
mapping = mapper.initial_mapping(circuit)

Expand Down Expand Up @@ -97,7 +97,7 @@ def test_random_circuits_grid_device(
c_orig = cirq.testing.random_circuit(
qubits=qubits, n_moments=n_moments, op_density=op_density, random_state=random_state
)
device = cirq.testing.construct_grid_device(7)
device = cirq.testing.construct_square_device(7)
device_graph = device.metadata.nx_graph
mapper = cirq.LineInitialMapper(device_graph)
mapping = mapper.initial_mapping(c_orig)
Expand All @@ -116,24 +116,40 @@ def test_value_equality():
small_circuit = construct_small_circuit()
step_circuit = construct_step_circuit(5)

# undirected case
mapper_one = cirq.LineInitialMapper(cirq.testing.construct_grid_device(7).metadata.nx_graph)
# undirected
mapper_one = cirq.LineInitialMapper(cirq.testing.construct_square_device(7).metadata.nx_graph)
mapper_one.initial_mapping(small_circuit)
mapper_two = cirq.LineInitialMapper(cirq.testing.construct_grid_device(7).metadata.nx_graph)
mapper_two = cirq.LineInitialMapper(cirq.testing.construct_square_device(7).metadata.nx_graph)
mapper_one.initial_mapping(step_circuit)
equals_tester.add_equality_group(mapper_one, mapper_two)

mapper_three = cirq.LineInitialMapper(cirq.testing.construct_grid_device(6).metadata.nx_graph)
mapper_three = cirq.LineInitialMapper(cirq.testing.construct_square_device(6).metadata.nx_graph)
equals_tester.add_equality_group(mapper_three)

# directed
mapper_one = cirq.LineInitialMapper(
cirq.testing.construct_ring_device(7, directed=True).metadata.nx_graph
)
mapper_one.initial_mapping(small_circuit)
mapper_two = cirq.LineInitialMapper(
cirq.testing.construct_ring_device(7, directed=True).metadata.nx_graph
)
mapper_two.initial_mapping(step_circuit)
equals_tester.add_equality_group(mapper_one, mapper_two)

mapper_three = cirq.LineInitialMapper(
cirq.testing.construct_ring_device(6, directed=True).metadata.nx_graph
)
equals_tester.add_equality_group(mapper_three)


def test_str():
device_graph = cirq.testing.construct_grid_device(7).metadata.nx_graph
device_graph = cirq.testing.construct_square_device(7).metadata.nx_graph
mapper = cirq.LineInitialMapper(device_graph)
assert str(mapper) == f'cirq.LineInitialMapper(nx.Graph({dict(device_graph.adjacency())}))'


def test_repr():
device_graph = cirq.testing.construct_grid_device(7).metadata.nx_graph
device_graph = cirq.testing.construct_square_device(7).metadata.nx_graph
mapper = cirq.LineInitialMapper(device_graph)
cirq.testing.assert_equivalent_repr(mapper, setup_code='import cirq\nimport networkx as nx')