Skip to content

[CQT-414] mip mapper maps circuits that do not need to be remapped#659

Open
rares1609 wants to merge 12 commits intodevelopfrom
CQT-414-MIP-mapper-maps-circuits-that-do-not-need-to-be-remapped
Open

[CQT-414] mip mapper maps circuits that do not need to be remapped#659
rares1609 wants to merge 12 commits intodevelopfrom
CQT-414-MIP-mapper-maps-circuits-that-do-not-need-to-be-remapped

Conversation

@rares1609
Copy link
Contributor

No description provided.

@rares1609 rares1609 requested a review from elenbaasc January 16, 2026 14:11
Copy link
Collaborator

@elenbaasc elenbaasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a static method:

Suggested change
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]]:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not a static method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankfully they work 😆

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you removed:

for key in self.data:
    if self.data[key] != other.data[key]:
        return False

but that the following is still there:

return self.data == other.data

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the statement checking if all values match with return all(self.data[key] == other.data[key] for key in self.data).

Copy link
Collaborator

@elenbaasc elenbaasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you removed:

for key in self.data:
    if self.data[key] != other.data[key]:
        return False

but that the following is still there:

return self.data == other.data

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants