Skip to content

Commit

Permalink
cap numpy version
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Linde committed Jan 7, 2025
1 parent 99551c4 commit 13fdb8e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ keywords =[
dependencies = [
"gymnasium>=0.28.1",
"networkx[default]>=2.6.3",
"numpy>=1.21.6, !=2.2.0",
"numpy>=1.21.6, <2.2.0",
"pygame",
"qiskit>=1.0.0",
]
Expand Down
8 changes: 3 additions & 5 deletions qgym/envs/routing/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
from __future__ import annotations

from copy import deepcopy
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Union

import numpy as np
from numpy.typing import ArrayLike, NDArray
Expand Down Expand Up @@ -113,11 +113,9 @@
)


class Routing(Environment[dict[str, NDArray[np.int_]], int]):
class Routing(Environment[dict[str, Union[NDArray[np.int_], NDArray[np.int8]]], int]):
"""RL environment for the routing problem of OpenQL."""

_state: RoutingState # type: ignore[assignment]

def __init__( # noqa: PLR0913
self,
connection_graph: nx.Graph | ArrayLike | Gridspecs,
Expand Down Expand Up @@ -220,7 +218,7 @@ def reset(
*,
seed: int | None = None,
options: Mapping[str, Any] | None = None,
) -> tuple[dict[str, NDArray[np.int_]], dict[str, Any]]:
) -> tuple[dict[str, NDArray[np.int_] | NDArray[np.int8]], dict[str, Any]]:
r"""Reset the state and set/create a new interaction circuit.
To be used after an episode is finished.
Expand Down
9 changes: 5 additions & 4 deletions qgym/envs/scheduling/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@

from collections.abc import Mapping
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Union, cast
from typing import TYPE_CHECKING, Any, Union

import numpy as np
from numpy.typing import NDArray
Expand All @@ -185,6 +185,8 @@ class Scheduling(
):
"""RL environment for the scheduling problem."""

_state: SchedulingState

def __init__( # noqa: PLR0913
self,
machine_properties: Mapping[str, Any] | str | MachineProperties,
Expand Down Expand Up @@ -297,13 +299,12 @@ def get_circuit(self, mode: str = "human") -> list[Gate]:
Human or encoded quantum circuit.
"""
mode = check_string(mode, "mode", lower=True)
state = cast("SchedulingState", self._state)
encoded_circuit = state.circuit_info.encoded
encoded_circuit = self._state.circuit_info.encoded
if mode == "encoded":
return deepcopy(encoded_circuit)

if mode == "human":
gate_encoder = state.utils.gate_encoder
gate_encoder = self._state.utils.gate_encoder
return gate_encoder.decode_gates(encoded_circuit)

msg = f"mode must be 'human' or 'encoded', but was {mode}"
Expand Down
2 changes: 1 addition & 1 deletion qgym/envs/scheduling/scheduling_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _update_dependencies(self) -> None:
self.circuit_info.dependencies = np.zeros_like(self.circuit_info.dependencies)

for gate_idx, blocking_row in enumerate(self.circuit_info.blocking_matrix):
blocking_gates = blocking_row[gate_idx:].nonzero()[0]
blocking_gates: NDArray[np.int_] = blocking_row[gate_idx:].nonzero()[0]
for depth in range(
min(self.circuit_info.dependencies.shape[0], blocking_gates.shape[0])
):
Expand Down

0 comments on commit 13fdb8e

Please sign in to comment.