Skip to content

Conversation

@rares1609
Copy link
Contributor

No description provided.

@elenbaasc elenbaasc changed the title [CQT-421]Implement QGymMapper mapper pass [CQT-421] Implement QGymMapper mapper pass Nov 13, 2025
@rares1609 rares1609 requested a review from elenbaasc November 15, 2025 14:26
Copy link
Collaborator

@juanboschero juanboschero left a comment

Choose a reason for hiding this comment

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

Good stuff

@@ -0,0 +1,69 @@
The [Qgym](https://github.com/QuTech-Delft/qgym) package functions in a manner similar
to the well known gym package, in the sense that it provides a number of environments
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
to the well known gym package, in the sense that it provides a number of environments
to the well known gym package, in the sense that it provides a number of environments

well as a `TRPO.zip` file containing the weights of a trained agent in your working
directory.

```python
Copy link
Collaborator

Choose a reason for hiding this comment

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

The example below should be in the test_docs file

return interaction_graph

def _get_mapping(self, mapping_data: Any, qubit_register_size: int) -> Mapping:
"""Convert QGym's physical-to-logical mapping to OpenSquirrel's logical-to-physical mapping."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing args and return in docstring

mapping_data = self._extract_mapping_data(last_obs)
return self._get_mapping(mapping_data, qubit_register_size)

def _ir_to_interaction_graph(self, ir: IR) -> nx.Graph:
Copy link
Collaborator

Choose a reason for hiding this comment

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

docstring args + return

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.

Looks good, thanks for the effort 😄!

Some small refactors required, but no major changes of functionality (I think)

- [Hardcoded Mapper](hardcoded-mapper.md) (`HardcodedMapper`)
- [Identity Mapper](identity-mapper.md) (`IdentitiyMapper`)
- [Random Mapper](random-mapper.md) (`RandomMapper`)
- [Qgym Mapper](qgym-mapper.md) (`QGymMapper`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it Qgym or QGym? We should be consistent. If it is Qgym, then we should also call the pass the QgymMapper, or leave it as is if it is QGym, but then adjust the text.

@@ -0,0 +1,69 @@
The [Qgym](https://github.com/QuTech-Delft/qgym) package functions in a manner similar
to the well known gym package, in the sense that it provides a number of environments
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
to the well known gym package, in the sense that it provides a number of environments
to the well-known gym package, in the sense that it provides a number of environments

@@ -0,0 +1,69 @@
The [Qgym](https://github.com/QuTech-Delft/qgym) package functions in a manner similar
to the well known gym package, in the sense that it provides a number of environments
on which reinforcement learning (RL) agents can be applied. The main purpose of qgym is
Copy link
Collaborator

Choose a reason for hiding this comment

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

New sentences are always on new lines. (change here and in other places)

Suggested change
on which reinforcement learning (RL) agents can be applied. The main purpose of qgym is
on which reinforcement learning (RL) agents can be applied.
The main purpose of qgym is

Comment on lines +48 to +49
with open('connectivities.json', 'r') as file:
connectivities = json.load(file)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this needs to be a JSON, can you not simply provide a connectivity (dict[str, list[int]]) as we defined it for example for the routers?

Comment on lines +53 to +57
connection_graph = nx.Graph()
connection_graph.add_edges_from(hardware_connectivity)

qgym_mapper = QGymMapper(agent_class = "TRPO", agent_path = "TRPO.zip",
connection_graph=connection_graph)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would rather pass the connectivity and then define what a connection_graph is in in the QgymMapper.

assert str(circuit1) != initial_circuit


def test_check_not_many_logical_as_physical_qubits(mapper1: QGymMapper, circuit2: Circuit) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def test_check_not_many_logical_as_physical_qubits(mapper1: QGymMapper, circuit2: Circuit) -> None:
def test_unequal_number_logical_and_physical_qubits(mapper1: QGymMapper, circuit2: Circuit) -> None:


@pytest.mark.parametrize(
"mapper, circuit, expected_mapping_length", # noqa: PT006
[("mapper1", "circuit1", 5), ("mapper2", "circuit2", 7)],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
[("mapper1", "circuit1", 5), ("mapper2", "circuit2", 7)],
[
("mapper1", "circuit1", 5),
("mapper2", "circuit2", 7)
],

@pytest.mark.parametrize(
"mapper, circuit, expected_mapping_length", # noqa: PT006
[("mapper1", "circuit1", 5), ("mapper2", "circuit2", 7)],
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
)
ids=["tuna-5-mapping", "starmon-7-mapping"],
)

mapper = request.getfixturevalue(mapper) # type: ignore[arg-type]
mapping = mapper.map(circuit.ir, circuit.qubit_register_size)
assert isinstance(mapping, Mapping)
assert len(mapping) == expected_mapping_length
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we test more than just the length? Or will the resultant mapping be different each time?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should put these (*.zips) and the qgym_mapper.py module in a separate folder qgym_mapper.

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.

4 participants