Skip to content

Commit 174d34c

Browse files
authoredJul 19, 2024··
88 numpy20 compatibility (#90)
* Add numpy2.0 compatibility * bump version * Add qhack talk to the readme
1 parent 962b6cb commit 174d34c

File tree

8 files changed

+24
-19
lines changed

8 files changed

+24
-19
lines changed
 

‎README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Please feel free to contact us via <s.feld@tudelft.nl> if you have any questions
1111
What follows are some simple steps to get you running.
1212
You could also have a look at some [Jupyter Notebooks](https://github.com/QuTech-Delft/qgym/tree/master/notebooks) that we have created for a tutorial at the [IEEE International Conference on Quantum Computing and Engineering (QCE’22)](https://qce.quantum.ieee.org/2022/tutorials-program/).
1313

14+
We also gave an talk about the package at qhack 2024, which you can find by clicking the image below.
15+
[![qgym: A Gym for RL-based Quantum Compilation](https://img.youtube.com/vi/4copOSHxwSA/0.jpg)](https://www.youtube.com/watch?v=4copOSHxwSA "qgym: A Gym for RL-based Quantum Compilation")
16+
1417
### Installing with pip
1518
To install the `qgym` use
1619
```terminal
@@ -22,7 +25,7 @@ In this case, use
2225
pip install qgym[tutorial]
2326
```
2427

25-
Currently `qgym` has support for Python 3.7, 3.8, 3.9, 3.10 and 3.11.
28+
Currently `qgym` has support for Python 3.8, 3.9, 3.10, 3.11 and 3.12.
2629

2730

2831
## Publication

‎qgym/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
2626
"""
2727

28-
__version__ = "0.3.0"
28+
__version__ = "0.3.1"

‎qgym/envs/initial_mapping/initial_mapping_state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666

6767
connection = {
6868
"graph": deepcopy(connection_graph),
69-
"matrix": nx.to_numpy_array(connection_graph, dtype=np.float_),
69+
"matrix": nx.to_numpy_array(connection_graph, dtype=np.float64),
7070
}
7171

7272
self.graphs = {

‎qgym/envs/initial_mapping/initial_mapping_visualiser.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def render(self, state: InitialMappingState) -> None | NDArray[np.int_]:
137137
return self._display()
138138

139139
def _get_mapped_graph(
140-
self, mapping: dict[int, int], interaction_graph_matrix: NDArray[np.float_]
140+
self, mapping: dict[int, int], interaction_graph_matrix: NDArray[np.float64]
141141
) -> nx.Graph:
142142
"""Construct a mapped graph.
143143
@@ -177,7 +177,7 @@ def _get_mapped_graph(
177177
def _add_colored_edge(
178178
self,
179179
graph: nx.Graph,
180-
mapped_adjacency_matrix: NDArray[np.float_],
180+
mapped_adjacency_matrix: NDArray[np.float64],
181181
edge: tuple[int, int],
182182
) -> None:
183183
"""Give an edge of the graph a color based on the mapping.
@@ -253,10 +253,12 @@ def _draw_mapped_graph(self, screen: Surface, mapped_graph: nx.Graph) -> None:
253253
pos_v = self.graphs["mapped"]["render_positions"][v]
254254
if mapped_graph.edges[u, v]["color"] == "red":
255255
color = self.colors["missing_edge"]
256-
if mapped_graph.edges[u, v]["color"] == "green":
256+
elif mapped_graph.edges[u, v]["color"] == "green":
257257
color = self.colors["used_edge"]
258-
if mapped_graph.edges[u, v]["color"] == "gray":
258+
elif mapped_graph.edges[u, v]["color"] == "gray":
259259
color = self.colors["unused_edge"]
260+
else:
261+
raise ValueError("Unknow color")
260262
draw_wide_line(screen, color, pos_u, pos_v)
261263

262264
for pos in self.graphs["mapped"]["render_positions"].values():
@@ -278,7 +280,7 @@ def _draw_header(self, text: str, subscreen: pygame.Rect, screen: Surface) -> No
278280
@staticmethod
279281
def _get_render_positions(
280282
graph: nx.Graph, subscreen: pygame.Rect
281-
) -> dict[Any, NDArray[np.float_]]:
283+
) -> dict[Any, NDArray[np.float64]]:
282284
"""Give the positions of the nodes of a graph on a given subscreen.
283285
284286
Args:
@@ -289,7 +291,7 @@ def _get_render_positions(
289291
A dictionary where the keys are the names of the nodes, and the values are
290292
the coordinates of these nodes.
291293
"""
292-
node_positions: dict[Any, NDArray[np.float_]]
294+
node_positions: dict[Any, NDArray[np.float64]]
293295
node_positions = nx.spring_layout(graph, threshold=1e-6)
294296

295297
# Scale and move the node positions to be centered on the subscreen

‎qgym/envs/routing/routing_state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__( # pylint: disable=too-many-arguments
103103
if observe_connection_graph:
104104
if has_fidelity(connection_graph):
105105
self.connection_matrix = nx.to_numpy_array(
106-
connection_graph, dtype=np.float_
106+
connection_graph, dtype=np.float64
107107
).flatten()
108108
else:
109109
self.connection_matrix = nx.to_numpy_array(

‎qgym/envs/routing/routing_visualiser.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _draw_circuit_lines( # pylint: disable=too-many-arguments
146146
x_text: float,
147147
x_left: float,
148148
x_right: float,
149-
y_lines: NDArray[np.float_],
149+
y_lines: NDArray[np.float64],
150150
) -> None:
151151
"""Draw the circuit lines on the 'circuit' screen and label them.
152152
@@ -177,8 +177,8 @@ def _draw_interaction_gates(
177177
screen: Surface,
178178
*,
179179
state: RoutingState,
180-
x_gates: NDArray[np.float_],
181-
y_lines: NDArray[np.float_],
180+
x_gates: NDArray[np.float64],
181+
y_lines: NDArray[np.float64],
182182
) -> None:
183183
"""Draw the interaction gates on the 'circuit' screen.
184184
@@ -245,8 +245,8 @@ def _draw_mapping(
245245
screen: Surface,
246246
*,
247247
state: RoutingState,
248-
x_gates: NDArray[np.float_],
249-
y_lines: NDArray[np.float_],
248+
x_gates: NDArray[np.float64],
249+
y_lines: NDArray[np.float64],
250250
) -> None:
251251
"""Draw the mapping on the 'circuit' screen.
252252
@@ -357,7 +357,7 @@ def _draw_header(self, text: str, screen: Surface) -> None:
357357

358358
def _get_render_positions(
359359
self, graph: nx.Graph, padding: int = 20
360-
) -> dict[Any, NDArray[np.float_]]:
360+
) -> dict[Any, NDArray[np.float64]]:
361361
"""Give the positions of the nodes of a graph on a given screen.
362362
363363
Args:
@@ -368,7 +368,7 @@ def _get_render_positions(
368368
Dictionary where the keys are the names of the nodes, and the values are the
369369
coordinates of these nodes.
370370
"""
371-
node_positions: dict[Any, NDArray[np.float_]]
371+
node_positions: dict[Any, NDArray[np.float64]]
372372
node_positions = nx.spring_layout(graph, threshold=1e-6)
373373

374374
# Scale and move the node positions to be centered on the graph subscreen

‎qgym/spaces/box.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__( # pylint: disable=too-many-arguments
3232
low: SupportsFloat | ArrayLike,
3333
high: SupportsFloat | ArrayLike,
3434
shape: Sequence[int] | None = None,
35-
dtype: type[np.floating[Any]] | type[np.integer[Any]] = np.float_,
35+
dtype: type[np.floating[Any]] | type[np.integer[Any]] = np.float64,
3636
*,
3737
rng: Generator | None = None,
3838
) -> None:

‎tests/envs/initial_mapping/test_initial_mapping_rewarders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_episode_rewarder(
216216
"""
217217

218218
fidelity_graph = np.array(
219-
([[0, 0.2, 0.6], [0.2, 0, 0.74], [0.6, 0.74, 0]]), dtype=np.float_
219+
([[0, 0.2, 0.6], [0.2, 0, 0.74], [0.6, 0.74, 0]]), dtype=np.float64
220220
)
221221

222222

0 commit comments

Comments
 (0)
Please sign in to comment.