Skip to content

Commit

Permalink
[FIX] Restructuring (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
elephaint authored Oct 30, 2024
1 parent 0bb272b commit bf944f2
Show file tree
Hide file tree
Showing 24 changed files with 8,330 additions and 4,572 deletions.
30 changes: 14 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
version: 2.1
jobs:
nbdev-tests:
resource_class: large
resource_class: xlarge
docker:
- image: mambaorg/micromamba:1.5-focal
- image: python:3.10-slim
steps:
- checkout
- run:
name: Install dependencies
command: |
micromamba install -n base -c conda-forge -y python=3.10
micromamba update -n base -f environment.yml
pip install uv
uv venv --python 3.10
- run:
name: Run nbdev tests
command: |
eval "$(micromamba shell hook --shell bash)"
micromamba activate base
pip install ".[dev]"
nbdev_test --do_print --timing --n_workers 0
source .venv/bin/activate
uv pip install ".[dev]"
nbdev_test --do_print --timing
test-model-performance:
resource_class: large
docker:
- image: mambaorg/micromamba:1.5-focal
- image: python:3.10-slim
steps:
- checkout
- run:
name: Install dependencies
command: |
micromamba install -n base -c conda-forge -y python=3.10
micromamba update -n base -f environment.yml
pip install uv
uv venv --python 3.10
- run:
name: Run model performance tests
command: |
eval "$(micromamba shell hook --shell bash)"
micromamba activate base
pip install ".[dev]"
source .venv/bin/activate
uv pip install ".[dev]"
cd ./action_files/test_models/
pip install -r requirements.txt
uv pip install -r requirements.txt
python -m src.models
python -m src.evaluation
cd ../../
Expand All @@ -48,4 +46,4 @@ workflows:
sample:
jobs:
- nbdev-tests
- test-model-performance
- test-model-performance
8 changes: 4 additions & 4 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ tag-template: 'v$NEXT_PATCH_VERSION'
categories:
- title: 'New Features'
label: 'feature'
- title: 'Breaking Change'
label: 'breaking change'
- title: 'Enhancement'
label: 'enhancement'
- title: 'Bug Fixes'
label: 'fix'
- title: 'Breaking Change'
label: 'breaking change'
- title: 'Documentation'
label: 'documentation'
- title: 'Dependencies'
label: 'dependencies'
- title: 'Enhancement'
label: 'enhancement'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
template: |
## Changes
Expand Down
31 changes: 21 additions & 10 deletions .github/workflows/build-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "build-docs"
on:
push:
branches: ["main"]
release:
types: [released]
pull_request:
branches: ["main"]
workflow_dispatch:
Expand All @@ -24,36 +24,43 @@ jobs:
path: docs-scripts
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # 5.3.0
with:
cache: "pip"
python-version: '3.10'
cache-dependency-path: settings.ini

- name: Install dependencies
run: pip install uv && uv pip install ".[dev]" --system

- name: Build docs
run: |
set -ux
python -m pip install --upgrade pip
pip install -Uq nbdev
pip install -e ".[dev]"
mkdir nbs/_extensions
cp -r docs-scripts/mintlify/ nbs/_extensions/
python docs-scripts/update-quarto.py
nbdev_docs
- name: Apply final formats
run: bash ./docs-scripts/docs-final-formatting.bash

- name: Copy over necessary assets
run: |
cp nbs/mint.json _docs/mint.json
cp docs-scripts/imgs/* _docs/
- name: Deploy to Mintlify Docs
if: github.event_name == 'push'
if: |
github.event_name == 'release' ||
github.event_name == 'workflow_dispatch'
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: docs
publish_dir: ./_docs
user_name: github-actions[bot]
user_email: 41898282+github-actions[bot]@users.noreply.github.com

- name: Trigger mintlify workflow
if: github.event_name == 'push'
if: |
github.event_name == 'release' ||
github.event_name == 'workflow_dispatch'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.DOCS_WORKFLOW_TOKEN }}
Expand All @@ -64,10 +71,14 @@ jobs:
workflow_id: 'mintlify-action.yml',
ref: 'main',
});
- name: Configure redirects for gh-pages
run: python docs-scripts/configure-redirects.py hierarchicalforecast

- name: Deploy to Github Pages
if: github.event_name == 'push'
if: |
github.event_name == 'release' ||
github.event_name == 'workflow_dispatch'
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/selfassign.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ repos:
hooks:
- id: mypy
args: [--ignore-missing-imports]
exclude: 'setup.py'
exclude: (experiments|setup.py)
18 changes: 13 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
* If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring.
* Be sure to add the complete error messages.

#### Did you write a patch that fixes a bug?
## Do you have a feature request?

* Open a new GitHub pull request with the patch.
* Ensure that your PR includes a test that fails without your patch, and pass with it.
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
* Ensure that it hasn't been yet implemented in the `main` branch of the repository and that there's not an Issue requesting it yet.
* Open a new issue and make sure to describe it clearly, mention how it improves the project and why its useful.

## Do you want to fix a bug or implement a feature?

Bug fixes and features are added through pull requests (PRs).

## PR submission guidelines

Expand All @@ -30,7 +33,12 @@
#### Set up a conda environment
The repo comes with an `environment.yml` file which contains the libraries needed to run all the tests. In order to set up the environment you must have `conda` installed, we recommend [miniconda](https://docs.conda.io/en/latest/miniconda.html).

Once you have `conda` go to the top level directory of the repository and run:
Once you have `conda` go to the top level directory of the repository and run the following lines:
```
conda create -n hierarchicalforecast python=3.10
conda activate hierarchicalforecast
```
Then, run one of the following commands:
```
conda env update -f environment.yml
```
Expand Down
4 changes: 2 additions & 2 deletions action_files/test_models/src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def get_data():
spec = [
['Country'],
['Country', 'State'],
['Country', 'Purpose'],
# ['Country', 'Purpose'],
['Country', 'State', 'Region'],
['Country', 'State', 'Purpose'],
# ['Country', 'State', 'Purpose'],
['Country', 'State', 'Region', 'Purpose']
]

Expand Down
7 changes: 3 additions & 4 deletions action_files/test_models/src/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pickle
import numpy as np
import pandas as pd
from itertools import product

from hierarchicalforecast.evaluation import HierarchicalEvaluation

Expand All @@ -16,8 +15,8 @@ def mase(y, y_hat, y_insample, seasonality=4):


def evaluate():
execution_times = pd.read_csv(f'data/execution_times.csv')
models = [f'{x[0]} ({x[1]:.2f} secs)' for x in execution_times.values]
execution_times = pd.read_csv('data/execution_times.csv')
models = [f"{x[0]} ({x[1]:.2f} secs)" for x in execution_times.values]

Y_rec_df = pd.read_csv('data/Y_rec.csv')
Y_test_df = pd.read_csv('data/Y_test.csv')
Expand All @@ -32,7 +31,7 @@ def evaluate():

eval_tags = {}
eval_tags['Total'] = tags['Country']
eval_tags['Purpose'] = tags['Country/Purpose']
# eval_tags['Purpose'] = tags['Country/Purpose']
eval_tags['State'] = tags['Country/State']
eval_tags['Regions'] = tags['Country/State/Region']
eval_tags['Bottom'] = tags['Country/State/Region/Purpose']
Expand Down
29 changes: 25 additions & 4 deletions action_files/test_models/src/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os
import time

import fire
import numpy as np
import pandas as pd

from hierarchicalforecast.core import HierarchicalReconciliation
from hierarchicalforecast.methods import (
BottomUp, MinTrace,
BottomUp, BottomUpSparse, TopDown, TopDownSparse, MiddleOut, MiddleOutSparse,
MinTrace,
MinTraceSparse,
OptimalCombination,
ERM,
)

from src.data import get_data
Expand All @@ -17,8 +19,27 @@ def main():
Y_train_df, Y_test_df, Y_hat_df, Y_fitted_df, S_df, tags = get_data()

reconcilers = [BottomUp(),
BottomUpSparse(),
TopDown(method="average_proportions"),
TopDownSparse(method="average_proportions"),
TopDown(method="proportion_averages"),
TopDownSparse(method="proportion_averages"),
MiddleOut(middle_level="Country/State", top_down_method="average_proportions"),
MiddleOutSparse(middle_level="Country/State", top_down_method="average_proportions"),
MinTrace(method='ols'),
MinTrace(method='wls_struct'),
MinTrace(method='wls_var'),
MinTrace(method='mint_cov'),
MinTrace(method='mint_shrink'),
MinTrace(method='ols')]
MinTraceSparse(method='ols'),
MinTraceSparse(method='wls_struct'),
MinTraceSparse(method='wls_var'),
OptimalCombination(method='ols'),
OptimalCombination(method='wls_struct'),
ERM(method='closed'),
# ERM(method='reg'), # This is so insanely slow that we don't run it
# ERM(method='reg_bu'), # This is so insanely slow that we don't run it
]
hrec = HierarchicalReconciliation(reconcilers=reconcilers)
Y_rec_df = hrec.reconcile(Y_hat_df=Y_hat_df,
Y_df=Y_fitted_df, S=S_df, tags=tags)
Expand Down
Loading

0 comments on commit bf944f2

Please sign in to comment.