From 2c8cd79abc4627e52cfcad104c1ba07bbfeae73e Mon Sep 17 00:00:00 2001 From: Tianyi Hao Date: Wed, 3 Apr 2024 23:21:50 +0800 Subject: [PATCH] add workflows --- .github/dependabot.yml | 11 ++++++ .github/workflows/conda.yml | 48 +++++++++++++++++++++++++ .github/workflows/pip.yml | 70 ++++++++++++++++++++++++++++++++++++ .github/workflows/wheels.yml | 4 +++ README.md | 15 +++++++- conda.recipe/meta.yaml | 35 ++++++++++++++++++ setup.py | 2 +- tests/test_whr.py | 13 +++++++ whr/evaluate.py | 8 ++--- 9 files changed, 200 insertions(+), 6 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/conda.yml create mode 100644 .github/workflows/pip.yml create mode 100644 conda.recipe/meta.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6c4b369 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + groups: + actions: + patterns: + - "*" diff --git a/.github/workflows/conda.yml b/.github/workflows/conda.yml new file mode 100644 index 0000000..a20d312 --- /dev/null +++ b/.github/workflows/conda.yml @@ -0,0 +1,48 @@ +name: Conda + +on: + workflow_dispatch: + push: + branches: + - master + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + strategy: + fail-fast: false + matrix: + platform: [ubuntu-latest, windows-latest, macos-latest] + python-version: ["3.8", "3.10"] + + runs-on: ${{ matrix.platform }} + + # The setup-miniconda action needs this to activate miniconda + defaults: + run: + shell: "bash -l {0}" + + steps: + - uses: actions/checkout@v4 + + - name: Get conda + uses: conda-incubator/setup-miniconda@v3.0.3 + with: + python-version: ${{ matrix.python-version }} + channels: conda-forge + + - name: Prepare + run: conda install conda-build conda-verify + + - name: Build + run: conda build conda.recipe + + - name: Install + run: conda install -c ${CONDA_PREFIX}/conda-bld/ whr + + - name: Test + run: python tests/test_whr.py diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml new file mode 100644 index 0000000..ef2507d --- /dev/null +++ b/.github/workflows/pip.yml @@ -0,0 +1,70 @@ +name: Pip + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + strategy: + fail-fast: false + matrix: + platform: [windows-latest, macos-latest, ubuntu-latest] + python-version: ["3.7", "3.11"] + + runs-on: ${{ matrix.platform }} + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Add requirements + run: python -m pip install --upgrade wheel setuptools + + - name: Build and install + run: pip install --verbose . + + - name: Test + run: python tests/test_whr.py + + build-mingw64: + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - uses: msys2/setup-msys2@v2 + with: + update: true + install: >- + mingw-w64-x86_64-gcc + mingw-w64-x86_64-python-pip + mingw-w64-x86_64-python-wheel + + - uses: actions/checkout@v4 + + - name: Install pybind11 + # This is required because --no-build-isolation disable dependences + # installation + run: pip install pybind11 + + - name: Build and install + # --no-build-isolation is required because the vanilla setuptool does not + # support Mingw64.See patches here: + # https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-python-setuptools + # Without those patches build_ext fails with: + # error: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64') + run: pip install --no-build-isolation . + + - name: Test + run: python tests/test_whr.py diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 13be462..98e15d6 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -2,6 +2,10 @@ name: Wheels on: workflow_dispatch: + pull_request: + push: + branches: + - master release: types: - published diff --git a/README.md b/README.md index c6313b7..435fdf1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,19 @@ Whole History Rating ==================== +| CI | status | +|----------------------|--------| +| conda.recipe | [![Conda Actions Status][actions-conda-badge]][actions-conda-link] | +| pip builds | [![Pip Actions Status][actions-pip-badge]][actions-pip-link] | +| cibuildwheel | [![Wheels Actions Status][actions-wheels-badge]][actions-wheels-link] | + +[actions-conda-link]: https://github.com/wind23/whole_history_rating/actions?query=workflow%3AConda +[actions-conda-badge]: https://github.com/wind23/whole_history_rating/workflows/Conda/badge.svg +[actions-pip-link]: https://github.com/wind23/whole_history_rating/actions?query=workflow%3APip +[actions-pip-badge]: https://github.com/wind23/whole_history_rating/workflows/Pip/badge.svg +[actions-wheels-link]: https://github.com/wind23/whole_history_rating/actions?query=workflow%3AWheels +[actions-wheels-badge]: https://github.com/wind23/whole_history_rating/workflows/Wheels/badge.svg + ## Description A Python interface incorporating a C++ implementation of the [Whole History Rating](http://remi.coulom.free.fr/WHR/WHR.pdf) algorithm proposed by [RĂ©mi Coulom](http://remi.coulom.free.fr/). @@ -50,7 +63,7 @@ Here is an easy example about how to use the package: In [3]: print(base.get_ordered_ratings()) [('Carol', [[0, 103.9187774903099, 108.03027219107216], [60, 107.30695193277161, 111.12369929419124]]), ('Alice', [[0, 78.50976252870765, 114.0890917675107], [30, 79.47183295485291, 116.02912272478814]]), ('Bob', [[10, -15.262552175731381, 108.50075126605397], [60, -18.08603087778281, 111.07152016073245]]), ('Dave', [[10, -176.6773935927304, 134.07989121465133], [30, -177.31877387682724, 135.25422816732765]])] -To learn more about the detailed usage, please refer to the docstrings of `whr.Base` and `whr.Evaluate`. +To learn more about the detailed usage, please refer to the docstrings of [`whr.Base`](https://github.com/wind23/whole_history_rating/blob/master/whr/base.py) and [`whr.Evaluate`](https://github.com/wind23/whole_history_rating/blob/master/whr/evaluate.py). ## References diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml new file mode 100644 index 0000000..99c7c80 --- /dev/null +++ b/conda.recipe/meta.yaml @@ -0,0 +1,35 @@ +package: + name: whr + version: 2.0.3 + +source: + path: .. + +build: + number: 0 + script: {{ PYTHON }} -m pip install . -vvv + +requirements: + build: + - {{ compiler('cxx') }} + + host: + - python + - pip + - pybind11 >=2.10.0 + + run: + - python + + +test: + imports: + - whr + source_files: + - tests + commands: + - python tests/test_whr.py + +about: + summary: A Python interface incorporating a C++ implementation of the Whole History Rating algorithm + license_file: LICENSE \ No newline at end of file diff --git a/setup.py b/setup.py index e025382..0cb87f7 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from pybind11.setup_helpers import Pybind11Extension, build_ext -__version__ = "2.0.2" +__version__ = "2.0.3" this_directory = Path(__file__).parent long_description = (this_directory / "README.md").read_text(encoding="utf-8") diff --git a/tests/test_whr.py b/tests/test_whr.py index 6714a87..2122e7e 100644 --- a/tests/test_whr.py +++ b/tests/test_whr.py @@ -20,10 +20,23 @@ def test_output(self): map(lambda x: list(map(round, x)), self.whr.ratings_for_player("shusai")) ) + def test_evaluate(self): + test_games = [ + ["shusaku", "shusai", "B", 1], + ["shusaku", "shusai", "W", 2], + ["shusaku", "shusai", "W", 3, 0], + ["shusaku", "shusai", "W", 4, 0], + ["shusaku", "shusai", "W", 4, 0], + ] + evaluate = whr.Evaluate(self.whr) + test_log_likelihood = evaluate.evaluate_ave_log_likelihood_games(test_games) + assert round(test_log_likelihood * 100000) == -50215 + def test_whr_class(): whrt = WholeHistoryRatingTest() whrt.test_output() + whrt.test_evaluate() if __name__ == "__main__": diff --git a/whr/evaluate.py b/whr/evaluate.py index 76b65f8..f349a9c 100644 --- a/whr/evaluate.py +++ b/whr/evaluate.py @@ -58,10 +58,10 @@ def evaluate_ave_log_likelihood_games( A list of games as the test dataset. Example: ``` - [('Carol', [[0, 103.91877749030998, 180.55812567296852], [60, 107.30695193277168, 183.1250043094528]]), - ('Alice', [[0, 78.50976252870765, 185.55230942797314], [30, 79.47183295485291, 187.12327376311526]]), - ('Bob', [[10, -15.262552175731392, 180.95086989932025], [60, -18.086030877782818, 183.0820052639819]]), - ('Dave', [[10, -176.67739359273045, 201.15282077913983], [30, -177.3187738768273, 202.03179750776144]])] + [['Alice', 'Carol', 'D', 0], + ['Bob', 'Dave', 'B', 10], + ['Dave', 'Alice', 'W', 30, 10.], + ['Bob', 'Carol', 'W', 60, 20.]] ``` ignore_null_players : bool, optional