Skip to content

Commit

Permalink
feat(package): fewer dependencies with fewer version pins (#95)
Browse files Browse the repository at this point in the history
* feat(cli): add builtin fragile swarm solver

 - drop dependency on fragile library since we need a fixed version, and its deps are OOOOOOOOLD.

* feat(package): drop pydantic dependency

 - we aren't using it for anything (useful)

* chore: fragile relative imports 🎉

 - tests pass and CLI works and no more numpy/gym heck

* chore: fix up numpy errors and test suite

 - we can swarm with no fragile dep or numpy version pinning :)

* chore: drop unused fragile code

* chore: fix tests

* chore: drop lots more unused fragile code

* chore: drop more unused fragile code

* chore: more unused code

* chore: drop networkx requirement and autoformat code

 - had to drop history tree 😭 but it will be fine

* chore: drop data generation swarm example

* feat(ci): add cron builds and matrix testing

* chore: update codecov range for mathy repo
  • Loading branch information
justindujardin committed Nov 30, 2023
1 parent 145612e commit 699d40e
Show file tree
Hide file tree
Showing 27 changed files with 4,377 additions and 138 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Expand Up @@ -7,12 +7,23 @@ on:
pull_request:
branches:
- "*"
schedule:
# Every Monday at 1PM UTC (9AM EST)
- cron: "0 13 * * 1"

jobs:
build:
strategy:
matrix:
os: [ubuntu-20.04]
python-version: [3.7, 3.8, 3.9, 3.10.6, 3.11]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Graphviz
run: sudo apt-get install graphviz
- name: Setup Packages
Expand Down
5 changes: 4 additions & 1 deletion codecov.yml
@@ -1,3 +1,6 @@
coverage:
status:
patch: off
patch: off
precision: 2
round: down
range: "50...100"
9 changes: 6 additions & 3 deletions libraries/mathy_python/mathy/api.py
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from typing import Optional

from fragile.core.swarm import Swarm
from .fragile.core.swarm import Swarm

from .solver import SwarmConfig, swarm_solve

Expand All @@ -22,6 +22,7 @@ def __init__(
config: Optional[SwarmConfig] = None,
silent: bool = False,
):
self.silent = silent
if config is None:
config = SwarmConfig()
if not isinstance(config, SwarmConfig):
Expand All @@ -30,5 +31,7 @@ def __init__(

def simplify(self, *, problem: str, max_steps: Optional[int] = None) -> Swarm:
if max_steps is not None:
return swarm_solve(problem, self.state.config, max_steps=max_steps)
return swarm_solve(problem, self.state.config)
return swarm_solve(
problem, self.state.config, max_steps=max_steps, silent=self.silent
)
return swarm_solve(problem, self.state.config, silent=self.silent)
4 changes: 2 additions & 2 deletions libraries/mathy_python/mathy/cli.py
Expand Up @@ -78,11 +78,11 @@ def cli_print_problems(environment: str, difficulty: str, number: int):
This is useful if you when developing new environment types for
verifying that the problems you're generating take the form you
expect. """
import gym
import gymnasium as gym
from mathy_envs.gym import MathyGymEnv

env_name = f"mathy-{environment}-{difficulty}-v0"
env: MathyGymEnv = gym.make(env_name) # type:ignore
env: MathyGymEnv = gym.make(env_name).unwrapped # type:ignore
msg.divider(env_name)
with msg.loading(f"Generating {number} problems..."):
header = ("Complexity", "Is Valid", "Text")
Expand Down
38 changes: 38 additions & 0 deletions libraries/mathy_python/mathy/fragile/__init__.py
@@ -0,0 +1,38 @@
"""Framework for FAI algorithms development."""

import warnings

warnings.filterwarnings(
"ignore",
message=(
"Using or importing the ABCs from 'collections' instead of from 'collections.abc' "
"is deprecated since Python 3.3,and in 3.9 it will stop working"
),
)
warnings.filterwarnings(
"ignore",
message=(
"the imp module is deprecated in favour of importlib; see the module's "
"documentation for alternative uses"
),
)
warnings.filterwarnings(
"ignore",
message=(
"Using or importing the ABCs from 'collections' instead of from "
"'collections.abc' is deprecated, and in 3.8 it will stop working"
),
)
warnings.filterwarnings(
"ignore",
message=(
"The set_clim function was deprecated in Matplotlib 3.1 "
"and will be removed in 3.3. Use ScalarMappable.set_clim "
"instead."
),
)
warnings.filterwarnings("ignore", message="Gdk.Cursor.new is deprecated")

from .core.states import States # noqa: E402
from .core.walkers import Walkers # noqa: E402
from .version import __version__ # noqa: E402
15 changes: 15 additions & 0 deletions libraries/mathy_python/mathy/fragile/core/__init__.py
@@ -0,0 +1,15 @@
"""Core base classes for developing FAI algorithms."""
from .base_classes import BaseCritic, BaseWrapper
from .bounds import Bounds
from .env import DiscreteEnv, Environment
from .models import (
BinarySwap,
ContinuousUniform,
DiscreteUniform,
Model,
NormalContinuous,
)
from .states import OneWalker, States, StatesEnv, StatesModel, StatesWalkers
from .swarm import Swarm
from .walkers import Walkers
from .wrappers import EnvWrapper

0 comments on commit 699d40e

Please sign in to comment.