From 8680a1314597a8bc214e35321f25288ddd6c6176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Morales?= Date: Tue, 19 Nov 2024 13:14:36 -0600 Subject: [PATCH] ci: efficiency tests (#942) --- .github/workflows/ci.yaml | 22 +++++++++++++++++++++- action_files/test_efficiency.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 action_files/test_efficiency.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c19355ccd..fa981ba80 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -59,7 +59,7 @@ jobs: CIBW_TEST_COMMAND: > uv pip install -r {project}/setup.py --extra all && nbdev_test --path {project}/nbs/ --skip_file_re "(distributed|prophet).*.ipynb" --pause 1.0 --do_print --timing && - pytest --durations=0 {project}/action_files + pytest --durations=0 {project}/action_files -k "not efficiency" - name: Build wheels and run local tests if: matrix.os-platform[0] != 'ubuntu-latest' @@ -126,3 +126,23 @@ jobs: python -m src.experiment python -m src.evaluation --test working-directory: ./experiments/m3 + + efficiency-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + submodules: "true" + + - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 + with: + python-version: "3.12" + + - name: Install dependencies + run: pip install uv && uv pip install --system . pytest-codspeed pytest-xdist + + - name: Run benchmarks + uses: CodSpeedHQ/action@fa1dcde8d58f2ab0b407a6a24d6cc5a8c1444a8c # 3.1.0 + with: + token: ${{ secrets.CODESPEED_TOKEN }} + run: pytest action_files/test_efficiency.py --codspeed -n 2 diff --git a/action_files/test_efficiency.py b/action_files/test_efficiency.py new file mode 100644 index 000000000..31974c7f9 --- /dev/null +++ b/action_files/test_efficiency.py @@ -0,0 +1,33 @@ +import inspect + +import numpy as np +import pytest + +import statsforecast.models + + +models = [ + statsforecast.models.AutoARIMA, + statsforecast.models.AutoCES, + statsforecast.models.AutoETS, + statsforecast.models.AutoTheta, + statsforecast.models.TBATS, + statsforecast.models.GARCH, +] + + +@pytest.fixture(scope="module") +def y(): + return np.arange(24)[np.arange(200) % 24] + + +@pytest.mark.parametrize("model_cls", models) +def test_efficiency(benchmark, y, model_cls): + if model_cls is statsforecast.models.AutoCES: + # fails to fit without model="N" + model = model_cls(season_length=24, model="N") + elif "season_length" in inspect.signature(model_cls).parameters: + model = model_cls(season_length=24) + else: + model = model_cls() + benchmark(model.forecast, y=y, h=48)