Skip to content

Commit 20df3be

Browse files
fix(pypi): stricter requirements for dependencies (#76)
- update mathy_core and mathy_envs to latest version that pin gym to the required range
1 parent 776ac52 commit 20df3be

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

libraries/mathy_python/mathy/api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from dataclasses import dataclass
2+
from typing import Optional
23

34
from fragile.core.swarm import Swarm
45

@@ -16,15 +17,18 @@ class Mathy:
1617
state: MathyAPISwarmState
1718

1819
def __init__(
19-
self, *, config: SwarmConfig = None, silent: bool = False,
20+
self,
21+
*,
22+
config: Optional[SwarmConfig] = None,
23+
silent: bool = False,
2024
):
2125
if config is None:
2226
config = SwarmConfig()
2327
if not isinstance(config, SwarmConfig):
2428
raise ValueError("config must be a SwarmConfig instance")
2529
self.state = MathyAPISwarmState(config=config)
2630

27-
def simplify(self, *, problem: str, max_steps: int = None) -> Swarm:
31+
def simplify(self, *, problem: str, max_steps: Optional[int] = None) -> Swarm:
2832
if max_steps is not None:
2933
return swarm_solve(problem, self.state.config, max_steps=max_steps)
3034
return swarm_solve(problem, self.state.config)

libraries/mathy_python/mathy/solver.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Use Fractal Monte Carlo search in order to solve mathy problems without a
22
trained neural network."""
3-
from typing import Dict, List, Optional, Union
3+
from typing import Any, Dict, List, Optional, Union
44

55
import numpy as np
66
from fragile.core.env import DiscreteEnv
@@ -70,7 +70,7 @@ def __init__(
7070
name: str,
7171
environment: str = "poly",
7272
difficulty: str = "easy",
73-
problem: str = None,
73+
problem: Optional[str] = None,
7474
max_steps: int = 64,
7575
**kwargs,
7676
):
@@ -122,7 +122,7 @@ def __init__(
122122
name: str,
123123
environment: str = "poly",
124124
difficulty: str = "normal",
125-
problem: str = None,
125+
problem: Optional[str] = None,
126126
max_steps: int = 64,
127127
**kwargs,
128128
):
@@ -132,10 +132,9 @@ def __init__(
132132

133133
self._env: MathyGymEnv = gym.make(
134134
f"mathy-{environment}-{difficulty}-v0",
135-
np_observation=True,
136-
mask_as_probabilities=True,
137135
invalid_action_response="terminal",
138136
env_problem=problem,
137+
mask_as_probabilities=True,
139138
**kwargs,
140139
)
141140
self.observation_space = spaces.Box(
@@ -148,7 +147,7 @@ def __init__(
148147

149148
def get_state(self) -> np.ndarray:
150149
assert self._env.state is not None, "env required to get_state"
151-
return self._env.state.to_np()
150+
return self._env.state.to_np(768)
152151

153152
def set_state(self, state: np.ndarray):
154153
assert self._env is not None, "env required to set_state"
@@ -165,7 +164,7 @@ def step(self, action: int, state: np.ndarray = None) -> tuple:
165164
return new_state, obs, reward, oob, info
166165

167166
def step_batch(
168-
self, actions, states=None, n_repeat_action: Union[int, np.ndarray] = None
167+
self, actions, states:Optional[Any]=None, n_repeat_action: Optional[Union[int, np.ndarray]] = None
169168
) -> tuple:
170169
data = [self.step(action, state) for action, state in zip(actions, states)]
171170
new_states, observs, rewards, terminals, infos = [], [], [], [], []
@@ -212,7 +211,7 @@ def mathy_swarm(config: SwarmConfig, env_callable=None) -> Swarm:
212211
def swarm_solve(
213212
problems: Union[List[str], str],
214213
config: SwarmConfig,
215-
max_steps: Union[List[int], int] = 128,
214+
max_steps: Union[List[int], int] = 256,
216215
silent: bool = False,
217216
) -> Swarm:
218217
single_problem: bool = isinstance(problems, str)

libraries/mathy_python/requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mypy
22
pytest
33
pytest-cov
4-
black
4+
black<22.2.0
55
isort
66
autoflake
77
flake8

libraries/mathy_python/requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Core library
2-
numpy<1.19.0,>=1.16.0
2+
numpy<1.23.0,>=1.22.0
33
colr
44
srsly
55
pydantic>=1.0.0
6-
typer<0.4.0,>=0.3.2
6+
typer<0.7.0,>=0.6.1
77
wasabi
8-
mathy_core>=0.8.4,<0.9.0
9-
mathy_envs[gym]>=0.10.0,<0.11.0
8+
mathy_core>=0.8.6,<0.9.0
9+
mathy_envs[gym]>=0.11.3,<0.12.0
1010
fragile==0.0.47
1111
tqdm>=4.43.0
1212
# new python feature backports

0 commit comments

Comments
 (0)