Skip to content

Commit cdae41b

Browse files
committed
addressed some comments
1 parent 388fff4 commit cdae41b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

cirq-core/cirq/transformers/routing/initial_mapper.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
from typing import TYPE_CHECKING, Dict
1616
import abc
1717

18-
from cirq.value import value_equality
18+
from cirq import value
1919

2020
if TYPE_CHECKING:
2121
import cirq
2222

2323

24-
@value_equality
2524
class AbstractInitialMapper(metaclass=abc.ABCMeta):
2625
"""Base class for creating custom initial mapping strategies.
2726
@@ -45,26 +44,27 @@ def initial_mapping(self) -> Dict['cirq.Qid', 'cirq.Qid']:
4544
qubit_map: the initial mapping of logical qubits to physical qubits.
4645
"""
4746

48-
def __str__(self) -> str:
49-
return f'{self.initial_mapping()}'
50-
51-
def _value_equality_values_(self):
52-
return self.initial_mapping()
53-
5447

48+
@value.value_equality
5549
class HardCodedInitialMapper(AbstractInitialMapper):
5650
"""Initial Mapper class takes a hard-coded mapping and returns it."""
5751

5852
def __init__(self, _map: Dict['cirq.Qid', 'cirq.Qid']) -> None:
5953
self._map = _map
6054

6155
def initial_mapping(self) -> Dict['cirq.Qid', 'cirq.Qid']:
62-
"""Takes a hard-coded initial mapping and returns it.
56+
"""Returns the hard-coded initial mapping.
6357
6458
Returns:
6559
the hard-codded initial mapping.
6660
"""
6761
return self._map
6862

63+
def _value_equality_values_(self):
64+
return tuple(sorted(self._map.items()))
65+
66+
def __str__(self) -> str:
67+
return f'{self._map}'
68+
6969
def __repr__(self) -> str:
70-
return f'cirq.HardCodedInitialMapper({self.initial_mapping()})'
70+
return f'cirq.HardCodedInitialMapper({self._map})'

0 commit comments

Comments
 (0)