Skip to content

Commit

Permalink
Switch to UV (#1178)
Browse files Browse the repository at this point in the history
- **Switch to UV**
- **Update CI to use UV**
  • Loading branch information
tmke8 authored Dec 5, 2024
2 parents 054d91d + 51c235b commit 6c024bf
Show file tree
Hide file tree
Showing 20 changed files with 2,720 additions and 3,420 deletions.
112 changes: 46 additions & 66 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,104 +29,86 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
run: uv python install 3.10
- name: Install ruff
run: |
poetry env use 3.10
poetry install --only lint --no-interaction --no-root
run: uv sync --no-install-project --only-group lint
- name: Lint with ruff
run: |
poetry run ruff check --output-format=github ethicml
uv run ruff check --output-format=github ethicml
- name: Lint with ruff
run: |
poetry run ruff check --output-format=github tests
uv run ruff check --output-format=github tests
format_with_black:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
run: uv python install 3.10
- name: Install ruff
run: |
poetry env use 3.10
poetry install --only lint --no-interaction --no-root
run: uv sync --no-install-project --only-group lint
- name: Format with ruff
run: |
poetry run ruff format --diff .
uv run ruff format --diff .
check_with_pydoclint:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11' # might as well use 3.11 as it's faster
run: uv python install 3.11
- name: Install pydoclint
run: |
poetry env use 3.11
poetry install --only doclint --no-interaction --no-root
run: uv sync --no-install-project --only-group doclint
- name: Check with pydoclint
run: |
poetry run pydoclint ethicml
uv run pydoclint ethicml
test_minimal_dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.10
- name: Install dependencies
run: |
poetry env use 3.10
poetry install --no-interaction --no-root --without dev,test,typecheck,lint,doclint
run: uv sync --no-install-project --no-group dev --no-group test --no-group typecheck --no-group lint --no-group doclint
- name: Test import
run: |
poetry run python -c "import ethicml"
uv run python -c "import ethicml"
test_build_docs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: '3.10'
cache: 'poetry'

enable-cache: true
- name: Set up Python
run: uv python install 3.10
- name: Install dependencies
run: |
poetry env use 3.10
poetry install --no-interaction --no-root --all-extras --with ci,torchcpu,docs --without lint,doclint
run: uv sync --no-install-project --all-extras --group ci --group torchcpu --group docs --no-group lint --no-group doclint
- name: Test import
run: |
poetry run python -c "import ethicml"
uv run python -c "import ethicml"
- name: Install pandoc
run: sudo apt-get install -y pandoc
- name: Build with sphinx
run: |
poetry run sphinx-build -W -b html ./docs ./docs/_build
uv run sphinx-build -W -b html ./docs ./docs/_build
test_with_pytest:
needs: [lint_with_ruff, format_with_black, check_with_pydoclint, test_minimal_dependencies, test_build_docs]
Expand All @@ -136,45 +118,43 @@ jobs:
#----------------------------------------------
# --- check-out repo and set-up python ---
#----------------------------------------------
- uses: actions/checkout@v3
- name: Install poetry
if: ${{ github.event_name == 'merge_group' }}
run: pipx install poetry
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Install uv
if: ${{ github.event_name == 'merge_group' }}
uses: astral-sh/setup-uv@v4
with:
python-version: '3.10'
cache: 'poetry'
enable-cache: true
- name: Set up Python
if: ${{ github.event_name == 'merge_group' }}
run: uv python install 3.10

#----------------------------------------------
# --------- install dependencies --------
#----------------------------------------------
- name: Install dependencies
if: ${{ github.event_name == 'merge_group' }}
run: |
poetry env use 3.10
poetry install --no-interaction --no-root --all-extras --with ci,torchcpu --without lint,doclint
run: uv sync --no-install-project --all-extras --group ci --group torchcpu --no-group lint --no-group doclint

#----------------------------------------------
# ----- Run MyPy -----
#----------------------------------------------
- name: Type check with mypy
if: ${{ github.event_name == 'merge_group' }}
run: |
poetry run mypy ethicml
uv run mypy ethicml
#----------------------------------------------
# ----- Run MyPy on tests -----
#----------------------------------------------
- name: Type check tests with mypy
if: ${{ github.event_name == 'merge_group' }}
run: |
poetry run mypy tests
uv run mypy tests
#----------------------------------------------
# ----- Run Tests -----
#----------------------------------------------
- name: Test with pytest
if: ${{ github.event_name == 'merge_group' }}
run: |
poetry run python -m pytest -vv -n 2 --dist loadgroup --cov=ethicml --cov-fail-under=80 tests/
uv run python -m pytest -vv -n 2 --dist loadgroup --cov=ethicml --cov-fail-under=80 tests/
18 changes: 7 additions & 11 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Pages
uses: actions/configure-pages@v3
# --- build docs ---
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set up Python
run: uv python install 3.10
- name: Install dependencies
run: |
poetry env use 3.10
poetry install --no-interaction --no-root --all-extras --with docs,torchcpu --without ci,lint,format
run: uv sync --no-install-project --all-extras --group ci --group torchcpu --group docs --no-group lint --no-group doclint
- name: Install pandoc
run: sudo apt-get install -y pandoc
- name: Build with sphinx
run: |
poetry run sphinx-build -W -b html ./docs ./docs/_build
uv run sphinx-build -W -b html ./docs ./docs/_build
# -----------------
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/dummy_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,23 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: '3.10'
cache: 'poetry'
enable-cache: true
- name: Set up Python
run: uv python install 3.10
- name: Install dependencies
run: uv sync --no-install-project --all-extras --group ci --group torchcpu --group docs --no-group lint --no-group doclint
- name: Test import
run: |
poetry env use 3.10
poetry install --no-interaction --no-root --all-extras --with torchcpu,docs --without ci,lint,doclint
uv run python -c "import ethicml"
- name: Install pandoc
run: sudo apt-get install -y pandoc
- name: Build with sphinx
run: |
poetry run sphinx-build -W -b html ./docs ./docs/_build
uv run sphinx-build -W -b html ./docs ./docs/_build
test_with_pytest:

Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
from pathlib import Path
import sys

import toml

sys.path.insert(0, os.path.abspath(".."))
sys.path.insert(0, str(Path("..").resolve()))


# -- Project information -----------------------------------------------------

project = "EthicML"
copyright = "2022, O. Thomas, T. Kehrenberg, M. Bartlett"
copyright = "2022, O. Thomas, T. Kehrenberg, M. Bartlett" # noqa: A001
author = "O. Thomas, T. Kehrenberg, M. Bartlett"

# The full version, including alpha/beta/rc tags
release = toml.load("../pyproject.toml")["tool"]["poetry"]["version"]
release = toml.load("../pyproject.toml")["project"]["version"]


# -- General configuration ---------------------------------------------------
Expand Down
23 changes: 14 additions & 9 deletions docs/tutorials/adult_dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"\n",
"adult = Adult()\n",
"data: em.DataTuple = adult.load()\n",
"assert (45222, 101) == data.x.shape\n",
"assert (45222,) == data.s.shape\n",
"assert (45222,) == data.y.shape"
"assert data.x.shape == (45222, 101)\n",
"assert data.s.shape == (45222,)\n",
"assert data.y.shape == (45222,)"
]
},
{
Expand Down Expand Up @@ -136,9 +136,9 @@
"outputs": [],
"source": [
"data: em.DataTuple = Adult(split=Adult.Splits.RACE).load()\n",
"assert (45222, 98) == data.x.shape\n",
"assert (45222,) == data.s.shape\n",
"assert (45222,) == data.y.shape"
"assert data.x.shape == (45222, 98)\n",
"assert data.s.shape == (45222,)\n",
"assert data.y.shape == (45222,)"
]
},
{
Expand Down Expand Up @@ -343,9 +343,9 @@
}
],
"source": [
"from ethicml.run import evaluate_models\n",
"from ethicml.models import LR, Reweighting, SVM, Upsampler\n",
"from ethicml.metrics import Accuracy, CV, ProbPos, TPR\n",
"from ethicml.models import LR, Reweighting, SVM, Upsampler\n",
"from ethicml.run import evaluate_models\n",
"\n",
"results = evaluate_models(\n",
" datasets=[em.data.Adult(split=Adult.Splits.RACE_BINARY)],\n",
Expand Down Expand Up @@ -1217,7 +1217,12 @@
],
"source": [
"results[\n",
" ['Accuracy', 'Accuracy_race_White_0÷race_White_1', 'TPR_race_White_0÷race_White_1', 'prob_pos_race_White_0÷race_White_1']\n",
" [\n",
" 'Accuracy',\n",
" 'Accuracy_race_White_0÷race_White_1',\n",
" 'TPR_race_White_0÷race_White_1',\n",
" 'prob_pos_race_White_0÷race_White_1',\n",
" ]\n",
"].groupby(level=[0, 1, 2, 3]).agg(['mean', 'std'])"
]
},
Expand Down
2 changes: 1 addition & 1 deletion ethicml/models/inprocess/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def select_svm(C: float, kernel: KernelType, seed: int) -> LinearSVC | SVC:
random_state = np.random.RandomState(seed=seed)
if kernel is KernelType.linear:
return LinearSVC(C=C, dual=False, tol=1e-12, random_state=random_state)
return SVC(C=C, kernel=kernel.value, gamma="auto", random_state=random_state)
return SVC(C=C, kernel=kernel.value, gamma="auto", random_state=random_state) # type: ignore[arg-type]
12 changes: 4 additions & 8 deletions ethicml/plot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,13 @@ def errorbox(

xmean: float = entry.vals[xaxis_measure].mean()
xstd: float = entry.vals[xaxis_measure].std()
if xmean + (0.5 * xstd) > max_xmean:
max_xmean = xmean + (0.5 * xstd)
if xmean - (0.5 * xstd) < min_xmean:
min_xmean = xmean - (0.5 * xstd)
max_xmean = max(xmean + (0.5 * xstd), max_xmean)
min_xmean = min(xmean - (0.5 * xstd), min_xmean)

ymean: float = entry.vals[yaxis_measure].mean()
ystd: float = entry.vals[yaxis_measure].std()
if ymean + (0.5 * ystd) > max_ymean:
max_ymean = ymean + (0.5 * ystd)
if ymean - (0.5 * ystd) < min_ymean:
min_ymean = ymean - (0.5 * ystd)
max_ymean = max(ymean + (0.5 * ystd), max_ymean)
min_ymean = min(ymean - (0.5 * ystd), min_ymean)

if use_cross:
plot.errorbar(
Expand Down
3 changes: 1 addition & 2 deletions ethicml/run/cross_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def _organize_and_compute_means(self) -> dict[str, ResultTuple]:
# we convert the hyperparameter dictionaries to strings in order to compare them
hyp_string = ", ".join(f"{key!s}={val!r}" for (key, val) in result.params.items())
grouped[hyp_string].append(result)
if result.fold_id > max_fold_id:
max_fold_id = result.fold_id
max_fold_id = max(result.fold_id, max_fold_id)

# compute the mean value of each measure within each group
mean_vals: dict[str, ResultTuple] = {}
Expand Down
Loading

0 comments on commit 6c024bf

Please sign in to comment.