Skip to content

Commit

Permalink
Major dependencies upgrades (#18)
Browse files Browse the repository at this point in the history
* Major dependencies upgrades

* Move from gym to gymnasium since gym is no longer maintained
* Remove support for stable-baselines and ray rllib with tensorflow
* Update all environments and tests to reflect dependencies changes
* Update all workflow files to use latest actions versions
* Remove unnecessary debug actions in the integration workflow (workflow disabled manually through the UI)
  • Loading branch information
OryJonay authored Jun 17, 2024
1 parent b694015 commit 4161573
Show file tree
Hide file tree
Showing 30 changed files with 231 additions and 229 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/createrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4.1.6
- name: Create Release
id: create_release
uses: actions/create-release@v1.0.1
uses: actions/create-release@v1.14.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/deploydocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4.1.6
with:
persist-credentials: false
- name: Set up Python 3.8
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v5.1.0
with:
python-version: 3.8
python-version: "3.11"
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
Expand All @@ -27,7 +27,8 @@ jobs:
run: |
make html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_build/html/
if: ${{ !env.ACT }}
31 changes: 6 additions & 25 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rl-implementation: [rllib, stable_baselines_v3]
python-version: [3.6, 3.7, 3.8]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4.1.6
name: Checkout code
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Install integration tests apt dependencies
Expand All @@ -22,31 +21,13 @@ jobs:
sudo apt-get install -y cmake libopenmpi-dev python3-dev zlib1g-dev
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
pip install --upgrade pip
- name: Install package
run: |
pip install .[tests]
- name: Install integration tests dependencies
run: |
pip install tensorflow torch
- name: Install rllib
env:
PY_VER: ${{ matrix.python-version }}
run: |
if [ $PY_VER = "3.6" ]; then
pip install "https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-2.0.0.dev0-cp36-cp36m-manylinux2014_x86_64.whl"
elif [ $PY_VER = "3.7" ]; then
pip install "https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-2.0.0.dev0-cp37-cp37m-manylinux2014_x86_64.whl"
else
pip install "https://s3-us-west-2.amazonaws.com/ray-wheels/latest/ray-2.0.0.dev0-cp38-cp38-manylinux2014_x86_64.whl"
fi
pip install "ray[rllib]"
if: matrix.rl-implementation == 'rllib'
- name: Install stable-baselines-v3
run: |
pip install stable-baselines3
if: matrix.rl-implementation == 'stable_baselines_v3'
pip install torch "ray[rllib]"
- name: Run integration tests
run: |
pytest -v tests -k "integration and ${{ matrix.rl-implementation }}" -W ignore::UserWarning -W ignore::DeprecationWarning -W ignore::RuntimeWarning
pytest -vvv -s tests -k "integration"
10 changes: 5 additions & 5 deletions .github/workflows/pypipublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
uses: actions/checkout@v4.1.6
- name: Set up Python 3.11
uses: actions/setup-python@v5.1.0
with:
python-version: 3.8
python-version: 3.11
- name: Install setuptools
run: |
pip install -U setuptools
- name: Build source archive
run: |
python setup.py sdist
- name: Publish 📦 PyPi
uses: pypa/gh-action-pypi-publish@v1.1.0
uses: pypa/gh-action-pypi-publish@v1.8.14
with:
password: ${{ secrets.pypi_password }}
15 changes: 6 additions & 9 deletions .github/workflows/testpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@ name: build
on: [push]

jobs:
build:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4.1.6
name: Checkout code
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Install integration tests apt dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake libopenmpi-dev python3-dev zlib1g-dev
- name: Upgrade pip
run: |
python -m pip install --upgrade pip
Expand All @@ -38,5 +34,6 @@ jobs:
- name: Post to Coveralls.io
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
if: ${{ !env.ACT }}
run: |
coveralls
coveralls
4 changes: 2 additions & 2 deletions examples/3-Way Soccer example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
"env.reset()\n",
"for _ in range(1, max_steps_limit):\n",
" print(env.render())\n",
" obs, reward, done, info = env.step(1)\n",
" obs, reward, done, truncated, info = env.step(1)\n",
" if done:\n",
" break"
]
Expand Down Expand Up @@ -596,7 +596,7 @@
"env.reset()\n",
"for _ in range(1, max_steps_limit):\n",
" print(env.render())\n",
" obs, reward, done, info = env.step(env.action_space.sample())\n",
" obs, reward, done, truncated, info = env.step(env.action_space.sample())\n",
" if done:\n",
" break"
]
Expand Down
12 changes: 6 additions & 6 deletions oddsgym/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gym
import gymnasium as gym

from .base import BaseOddsEnv
from .base_percentage import BasePercentageOddsEnv
Expand Down Expand Up @@ -30,11 +30,11 @@

# register the *-data.co.uk environments in ray, only if ray is installed
try:
from ray.tune.registry import register_env
from ray import tune
except ImportError: # pragma: no cover
pass
else: # pragma: no cover
register_env('FootballDataDaily-ray-v0', lambda env_config: FootballDataDailyEnv(**env_config))
register_env('FootballDataDailyPercent-ray-v0', lambda env_config: FootballDataDailyPercentageEnv(**env_config))
register_env('TennisDataDaily-ray-v0', lambda env_config: TennisDataDailyEnv(**env_config))
register_env('TennisDataDailyPercent-ray-v0', lambda env_config: TennisDataDailyPercentageEnv(**env_config))
tune.register_env('FootballDataDaily-ray-v0', lambda env_config: gym.wrappers.FlattenObservation(FootballDataDailyEnv(env_config)))
tune.register_env('FootballDataDailyPercent-ray-v0', lambda env_config: gym.wrappers.FlattenObservation(FootballDataDailyPercentageEnv(env_config)))
tune.register_env('TennisDataDaily-ray-v0', lambda env_config: gym.wrappers.FlattenObservation(TennisDataDailyEnv(env_config)))
tune.register_env('TennisDataDailyPercent-ray-v0', lambda env_config: gym.wrappers.FlattenObservation(TennisDataDailyPercentageEnv(env_config)))
24 changes: 16 additions & 8 deletions oddsgym/envs/base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import gym
import gymnasium as gym
import numpy
import numexpr
from itertools import compress
from pandas import DataFrame
from tabulate import tabulate
from infi.traceback import pretty_traceback_and_exit_decorator
from typing import Any
# from infi.traceback import pretty_traceback_and_exit_decorator


class ActionsDict(dict):
Expand Down Expand Up @@ -56,7 +57,7 @@ class BaseOddsEnv(gym.Env):
metadata = {'render.modes': ['human']}
HEADERS = ['Current Step', 'Odds', 'Verbose Action', 'Action', 'Balance', 'Reward', 'Results', 'Done']

def __init__(self, odds, odds_column_names, results=None, starting_bank=10):
def __init__(self, odds, odds_column_names, results=None, starting_bank=300):
"""Initializes a new environment
Parameters
Expand All @@ -83,6 +84,12 @@ def __init__(self, odds, odds_column_names, results=None, starting_bank=10):

def _get_current_index(self):
return self.current_step % self._odds.shape[0]

def _get_maximum_reward(self):
"""Returns the maximum reward possible for this environment"""
results = numpy.zeros(shape=self._odds.shape)
results[numpy.arange(self._odds.shape[0]), numpy.array(self._results)] = 1
return (results * self._odds).sum().sum()

def get_odds(self):
"""Returns the odds for the current step.
Expand Down Expand Up @@ -110,7 +117,7 @@ def get_bet(self, action):
"""
return numpy.array([[bit for bit in numpy.binary_repr(action, width=self._odds.shape[1])]]).astype(int)

@pretty_traceback_and_exit_decorator
# @pretty_traceback_and_exit_decorator
def step(self, action):
"""Run one timestep of the environment's dynamics. When end of episode is reached,
you are responsible for calling reset() to reset this environment's state.
Expand All @@ -137,6 +144,7 @@ def step(self, action):
odds = self.get_odds()
reward = 0
done = False
truncated = False
info = self.create_info(action)
if self.balance < 1: # no more money :-(
done = True
Expand All @@ -158,7 +166,7 @@ def step(self, action):
else:
odds = self.get_odds()
info.update(done=done)
return odds, reward, done, info
return odds, reward, done, truncated, info

def get_reward(self, bet, odds, results):
""" Calculates the reward
Expand All @@ -180,7 +188,7 @@ def get_reward(self, bet, odds, results):
expense = numexpr.evaluate('sum(bet * bet_size_matrix)')
return reward - expense

def reset(self):
def reset(self, *, seed=None, options=None):
"""Resets the state of the environment and returns an initial observation.
Returns
Expand All @@ -190,7 +198,7 @@ def reset(self):
"""
self.balance = self.starting_bank
self.current_step = 0
return self.get_odds()
return self.get_odds(), {}

def render(self, mode='human'):
"""Outputs the current balance and the current step.
Expand Down Expand Up @@ -265,7 +273,7 @@ def create_info(self, action):
info : dict
The info dictionary.
"""
return {'current_step': self.current_step, 'odds': self.get_odds(), 'verbose_action': self._verbose_actions[action],
return {'current_step': self.current_step, 'odds': self.get_odds().tolist(), 'verbose_action': self._verbose_actions[action],
'action': action, 'balance': self.balance, 'reward': 0,
'legal_bet': False, 'results': None, 'done': False}

Expand Down
2 changes: 1 addition & 1 deletion oddsgym/envs/base_percentage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
from gym import spaces
from gymnasium import spaces
from .base import BaseOddsEnv


Expand Down
8 changes: 4 additions & 4 deletions oddsgym/envs/daily_bets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gym
import gymnasium as gym
import numpy
import numexpr
from pandas import DataFrame
from pandas import DataFrame, concat as concat_dataframes
from .base import BaseOddsEnv


Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(self, odds, odds_column_names, results=None, max_number_of_games='a
super().__init__(odds.drop('date', axis='columns'), odds_column_names, results, *args, **kwargs)
self._odds_with_dates = odds.copy()
self.days = odds['date'].unique()
self.days.sort()
self.days = self.days[self.days.argsort()]
self._max_number_of_games = None
if max_number_of_games == 'auto':
self.max_number_of_games = odds.set_index('date').groupby(by='date').size().max()
Expand Down Expand Up @@ -114,7 +114,7 @@ def get_odds(self):
filler_odds = DataFrame(numpy.zeros(numpy.array([self.max_number_of_games, self._odds.shape[1]]) -
numpy.array([current_odds.shape[0], 0])),
columns=self._odds_columns_names)
return current_odds.append(filler_odds, ignore_index=True).values
return concat_dataframes([current_odds, filler_odds], ignore_index=True).values

def get_bet(self, action):
"""Returns the betting matrix for the action provided.
Expand Down
Loading

0 comments on commit 4161573

Please sign in to comment.