[CQT-414] mip mapper maps circuits that do not need to be remapped#659
[CQT-414] mip mapper maps circuits that do not need to be remapped#659
Conversation
…not need to be remapped
elenbaasc
left a comment
There was a problem hiding this comment.
Thanks for the effort! It seems it was a bit more work that I had anticipated :)
Mostly minor comments. Mainly in regards to the implementation of the map method where you default to using numpy arrays, when simple objects would suffice or are expected in the end anyway, e.g. creating a numpy array and at the end converting it to a list.
| def _get_cost( | ||
| self, ir: IR, distance: list[list[int]], num_virtual_qubits: int, num_physical_qubits: int | ||
| ) -> list[list[int]]: | ||
| def _get_reference_counter(self, ir: IR, num_virtual_qubits: int) -> list[list[int]]: |
There was a problem hiding this comment.
This is a static method:
| def _get_reference_counter(self, ir: IR, num_virtual_qubits: int) -> list[list[int]]: | |
| @staticmethod | |
| def _get_reference_counter(ir: IR, num_virtual_qubits: int) -> list[list[int]]: |
There was a problem hiding this comment.
This is still not a static method.
There was a problem hiding this comment.
Sorry about that, could have sworn I made it static before commiting 😢
| def test_get_mapping(self, mapper: IdentityMapper, circuit: Circuit) -> None: | ||
| mapping = mapper.map(circuit.ir, circuit.qubit_register_size) | ||
| assert mapping == Mapping([0, 1, 2]) | ||
| assert mapping.items() == Mapping([0, 1, 2]).items() |
There was a problem hiding this comment.
Is this still needed, now that you updated the Mapping.__eq__ method? Maybe this condition self.data == other.data should not be part of that method.
There was a problem hiding this comment.
Indeed this is no longer needed, so i removed the .items() from the assertions, in both test_simple_mappers.py and test_mip_mapper.py. Regarding the condition in Mapping.__eq__ what should be done about it? Should this be part of a different issue?
There was a problem hiding this comment.
Good :)
Removing the following lines from the Mapping.__eq__:
if self.data != other.data:
return False
should do the trick. (Fingers crossed that the tests succeed...)
There was a problem hiding this comment.
Thankfully they work 😆
There was a problem hiding this comment.
I see that you removed:
for key in self.data:
if self.data[key] != other.data[key]:
return Falsebut that the following is still there:
return self.data == other.dataThe first one should be there, i.e., you are checking if all values match. The second one should not be there, because you don't want to say that the object self.data must be equal to the object other.data, for one mapping to be equal to another.
There was a problem hiding this comment.
I replaced the statement checking if all values match with return all(self.data[key] == other.data[key] for key in self.data).
elenbaasc
left a comment
There was a problem hiding this comment.
Thanks for the effort! Almost there :)
Some comments not fully resolved yet and a small comments about the placement of the docstring.
| reference_counter[q_1.index][q_0.index] += 1 | ||
| return reference_counter | ||
|
|
||
| def _get_linearized_formulation( |
There was a problem hiding this comment.
Shouldn't these docstring be part of the map method (as it is the only public method of this class)? It might even be the docstring of the class... docstrings in private classes are not published in the user docs, and are only there for the developers.
| def test_get_mapping(self, mapper: IdentityMapper, circuit: Circuit) -> None: | ||
| mapping = mapper.map(circuit.ir, circuit.qubit_register_size) | ||
| assert mapping == Mapping([0, 1, 2]) | ||
| assert mapping.items() == Mapping([0, 1, 2]).items() |
There was a problem hiding this comment.
I see that you removed:
for key in self.data:
if self.data[key] != other.data[key]:
return Falsebut that the following is still there:
return self.data == other.dataThe first one should be there, i.e., you are checking if all values match. The second one should not be there, because you don't want to say that the object self.data must be equal to the object other.data, for one mapping to be equal to another.
No description provided.