Skip to content

Commit 62c9f0e

Browse files
committed
Merge branch 'main' into release
2 parents 6588125 + f2bc752 commit 62c9f0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+684
-714
lines changed

.github/workflows/continuous_integration.yml

+25-12
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,43 @@ jobs:
3030

3131
steps:
3232
- uses: actions/checkout@v3
33+
- name: Install poetry
34+
run: pipx install poetry
3335
- name: Set up Python
3436
uses: actions/setup-python@v4
3537
with:
3638
python-version: '3.8'
3739
- name: Install ruff
3840
run: |
39-
python -m pip install --upgrade pip
40-
pip install ruff
41+
poetry env use 3.8
42+
poetry install --only lint --no-interaction --no-root
4143
- name: Lint with ruff
4244
run: |
43-
ruff check --format=github ethicml
45+
poetry run ruff check --format=github ethicml
4446
- name: Lint with ruff
4547
run: |
46-
ruff check --format=github tests
48+
poetry run ruff check --format=github tests
4749
4850
format_with_black:
4951

5052
runs-on: ubuntu-latest
5153

5254
steps:
5355
- uses: actions/checkout@v3
56+
- name: Install poetry
57+
run: pipx install poetry
5458
- name: Set up Python
5559
uses: actions/setup-python@v4
5660
with:
5761
python-version: '3.8'
5862
- name: Install black
5963
run: |
60-
python -m pip install --upgrade pip
61-
pip install 'black<=23'
64+
poetry env use 3.8
65+
poetry install --only format --no-interaction --no-root
6266
- name: Format with black
6367
run: |
64-
python -m black --check -l 100 -t py38 -S ethicml/
65-
python -m black --check -l 100 -t py38 -S tests/
68+
poetry run black --check -l 100 -t py38 -S ethicml/
69+
poetry run black --check -l 100 -t py38 -S tests/
6670
6771
check_docstrings:
6872

@@ -135,7 +139,7 @@ jobs:
135139
run: |
136140
# keep the following in sync with `test_with_pytest`!
137141
poetry env use 3.8
138-
poetry install --no-interaction --no-root -E all --with ci --with torchcpu
142+
poetry install --no-interaction --no-root -E all --with ci --with torchcpu --without lint --without format
139143
- name: Test import
140144
run: |
141145
poetry run python -c "import ethicml"
@@ -166,16 +170,25 @@ jobs:
166170
run: |
167171
# keep the following in sync with `test_full_dependencies`!
168172
poetry env use 3.8
169-
poetry install --no-interaction --no-root -E all --with ci --with torchcpu
173+
poetry install --no-interaction --no-root -E all --with ci --with torchcpu --without lint --without format
170174
171175
#----------------------------------------------
172176
# ----- Run MyPy -----
173177
#----------------------------------------------
174178
- name: Type check with mypy
175179
if: ${{ github.event_name == 'merge_group' }}
176180
run: |
177-
poetry run python run_mypy.py
178-
poetry run python run_mypy_tests.py
181+
poetry run mypy ethicml
182+
poetry run mypy --warn-unused-ignores ethicml || true
183+
184+
#----------------------------------------------
185+
# ----- Run MyPy on tests -----
186+
#----------------------------------------------
187+
- name: Type check tests with mypy
188+
if: ${{ github.event_name == 'merge_group' }}
189+
run: |
190+
poetry run mypy tests
191+
poetry run mypy --warn-unused-ignores tests || true
179192
180193
#----------------------------------------------
181194
# ----- Run Tests -----

.github/workflows/dependabot_auto.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Dependabot auto-merge
22
on:
33
pull_request_target:
4-
branches:
5-
- 'main'
4+
branches:
5+
# !! deactivated for now !!
6+
- 'mainx'
67

78
permissions:
89
pull-requests: write

.github/workflows/docs.yml

+52-26
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,62 @@
1-
name: Build docs
1+
name: Deploy sphinx with GitHub Pages
22

33
on:
44
release:
55
types:
66
- published
77

8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
18+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: false
22+
823
jobs:
9-
docs:
24+
# Build job
25+
build:
1026
runs-on: ubuntu-latest
1127
steps:
12-
#----------------------------------------------
13-
# check-out repo and set-up python
14-
#----------------------------------------------
15-
- name: Check out repository
16-
uses: actions/checkout@v2
17-
- name: Set up python
18-
uses: actions/setup-python@v2
19-
with:
20-
python-version: "3.10"
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
- name: Setup Pages
31+
uses: actions/configure-pages@v3
32+
# --- build docs ---
33+
- name: Set up python
34+
uses: actions/setup-python@v4
35+
with:
36+
python-version: "3.10"
37+
- name: Install sphinx
38+
run: |
39+
pip install wheel
40+
pip install -r docs/requirements.txt
41+
- name: Install pandoc
42+
run: sudo apt-get install -y pandoc
43+
- name: Build docs
44+
run: |
45+
sphinx-build -b html ./docs ./docs/_build
46+
# -----------------
47+
- name: Upload artifact
48+
uses: actions/upload-pages-artifact@v2
49+
with:
50+
path: './docs/_build'
2151

22-
- name: Install sphinx
23-
run: |
24-
pip install wheel
25-
pip install -r docs/requirements.txt
26-
- name: Install pandoc
27-
run: sudo apt-get install -y pandoc
28-
- name: Build docs
29-
run: |
30-
sphinx-build -b html ./docs ./docs/_build
31-
32-
- name: Deploy
33-
uses: peaceiris/actions-gh-pages@v3
34-
with:
35-
publish_dir: ./docs/_build
36-
github_token: ${{ secrets.GITHUB_TOKEN }}
52+
# Deployment job
53+
deploy:
54+
environment:
55+
name: github-pages
56+
url: ${{ steps.deployment.outputs.page_url }}
57+
runs-on: ubuntu-latest
58+
needs: build
59+
steps:
60+
- name: Deploy to GitHub Pages
61+
id: deployment
62+
uses: actions/deploy-pages@v2

ethicml/data/tabular_data/acs.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# pylint: skip-file
77
# Pylint will go crazy as we're reimplementing the Dataset Init.
88
from __future__ import annotations
9-
from collections.abc import Sequence
109
import contextlib
1110
import os
1211
from pathlib import Path
@@ -322,7 +321,7 @@ def __init__(
322321
)
323322

324323
@staticmethod
325-
def cat_lookup(key: str) -> Sequence[int]:
324+
def cat_lookup(key: str) -> list[int]:
326325
"""Look up categories."""
327326
table = {
328327
"COW": range(1, 9),
@@ -333,7 +332,7 @@ def cat_lookup(key: str) -> Sequence[int]:
333332
'PINCP': range(2),
334333
}
335334

336-
return table[key]
335+
return list(table[key])
337336

338337
@override
339338
def load(
@@ -471,7 +470,7 @@ def __init__(
471470
)
472471

473472
@staticmethod
474-
def cat_lookup(key: str) -> Sequence[int]:
473+
def cat_lookup(key: str) -> list[int]:
475474
"""Look up categories."""
476475
table = {
477476
'SCHL': range(1, 25),
@@ -492,7 +491,7 @@ def cat_lookup(key: str) -> Sequence[int]:
492491
'ESR': range(1, 7),
493492
}
494493

495-
return table[key]
494+
return list(table[key])
496495

497496
@override
498497
def load(

ethicml/implementations/agarwal.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ def main() -> None:
123123
import cloudpickle # pyright: ignore
124124

125125
# Need to install cloudpickle for now. See https://github.com/fairlearn/fairlearn/issues/569
126+
126127
except ImportError as e:
127128
raise RuntimeError("In order to use Agarwal, install fairlearn and cloudpickle.") from e
128129

129130
if in_algo_args["mode"] == "run":
130131
random.seed(in_algo_args["seed"])
131132
np.random.seed(in_algo_args["seed"])
132-
train, test = DataTuple.from_file(Path(in_algo_args["train"])), SubgroupTuple.from_file(
133-
Path(in_algo_args["test"])
134-
)
133+
train = DataTuple.from_file(Path(in_algo_args["train"]))
134+
test = SubgroupTuple.from_file(Path(in_algo_args["test"]))
135135
Prediction(
136136
hard=train_and_predict(train, test, flags, in_algo_args["seed"])["preds"]
137137
).save_to_file(Path(in_algo_args["predictions"]))

ethicml/implementations/beutel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def backward(ctx: Any, grad_output: Tensor) -> Any: # type: ignore[override]
251251

252252

253253
def _grad_reverse(features: Tensor, lambda_: float) -> Tensor:
254-
return GradReverse.apply(features, lambda_)
254+
return GradReverse.apply(features, lambda_) # pyright: ignore
255255

256256

257257
class Encoder(nn.Module):

ethicml/implementations/dro_modules/dro_classifier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DROClassifier(nn.Module):
1616
def __init__(self, in_size: int, out_size: int, network_size: list[int], eta: float) -> None:
1717
super().__init__()
1818

19-
self.loss = DROLoss(loss_module=CrossEntropyLoss, eta=eta)
19+
self.loss = DROLoss(loss_module=CrossEntropyLoss, eta=eta) # type: ignore[arg-type]
2020

2121
self.seq = nn.Sequential()
2222
if not network_size: # In the case that encoder size [] is specified

ethicml/implementations/dro_tabular.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ def train_model(
4747
optimizer.step()
4848
train_loss += loss.item()
4949
if batch_idx % 100 == 0:
50+
num_epochs = len(train_loader.dataset) # type: ignore[arg-type]
5051
print(
51-
f"train Epoch: {epoch} [{batch_idx * len(data_x)}/{len(train_loader.dataset)}"
52+
f"train Epoch: {epoch} [{batch_idx * len(data_x)}/{num_epochs}"
5253
f"\t({100. * batch_idx / len(train_loader):.0f}%)]"
5354
f"\tLoss: {loss.item() / len(data_x):.6f}"
5455
)
5556

56-
print(f"====> Epoch: {epoch} Average loss: {train_loss / len(train_loader.dataset):.4f}")
57+
num_epochs = len(train_loader.dataset) # type: ignore[arg-type]
58+
print(f"====> Epoch: {epoch} Average loss: {train_loss / num_epochs:.4f}")
5759

5860

5961
def fit(train: DataTuple, args: DroArgs, seed: int) -> DROClassifier:

ethicml/implementations/fair_dummies_modules/model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def __init__(
483483
def fit(self, train: DataTuple, seed: int) -> Self:
484484
"""Fit."""
485485
# The features are X[:,1:]
486-
p_success, dummy = density_estimation(y=train.y.to_numpy(), a=train.s.to_numpy())
486+
p_success, _ = density_estimation(y=train.y.to_numpy(), a=train.s.to_numpy())
487487

488488
rng = np.random.default_rng(seed)
489489

@@ -633,7 +633,7 @@ def __init__(
633633
def fit(self, train: DataTuple, seed: int) -> None:
634634
"""Fit."""
635635
fast_loader = self.batch_size >= train.x.shape[0]
636-
p_success, dummy = density_estimation(y=train.y.to_numpy(), a=train.s.to_numpy())
636+
p_success, _ = density_estimation(y=train.y.to_numpy(), a=train.s.to_numpy())
637637

638638
x = torch.from_numpy(train.x.to_numpy()).float()
639639
y = torch.from_numpy(train.y.to_numpy()).float()

ethicml/implementations/fair_dummies_modules/utility_functions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def density_estimation(
1212
if y_test is None:
1313
y_test = np.array([])
1414
assert y_test is not None
15-
bandwidth = np.sqrt(max(np.median(np.abs(y)), 0.01))
15+
bandwidth = np.sqrt(max(np.median(np.abs(y)).item(), 0.01))
1616

1717
kde_0 = KernelDensity(kernel='linear', bandwidth=bandwidth).fit(y[a == 0][:, np.newaxis])
1818
kde_1 = KernelDensity(kernel='linear', bandwidth=bandwidth).fit(y[a == 1][:, np.newaxis])

ethicml/implementations/fair_dummies_romano.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ def main() -> None:
6363
flags: FairDummiesArgs = json.loads(sys.argv[2])
6464

6565
if in_algo_args["mode"] == "run":
66-
train, test = DataTuple.from_file(Path(in_algo_args["train"])), SubgroupTuple.from_file(
67-
Path(in_algo_args["test"])
68-
)
66+
train = DataTuple.from_file(Path(in_algo_args["train"]))
67+
test = SubgroupTuple.from_file(Path(in_algo_args["test"]))
6968
SoftPrediction(
7069
soft=train_and_predict(train, test, flags, in_algo_args["seed"])
7170
).save_to_file(Path(in_algo_args["predictions"]))

ethicml/implementations/hgr_method.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ def main() -> None:
6565
flags: HgrArgs = json.loads(sys.argv[2])
6666

6767
if in_algo_args["mode"] == "run":
68-
train, test = DataTuple.from_file(Path(in_algo_args["train"])), SubgroupTuple.from_file(
69-
Path(in_algo_args["test"])
70-
)
68+
train = DataTuple.from_file(Path(in_algo_args["train"]))
69+
test = SubgroupTuple.from_file(Path(in_algo_args["test"]))
7170
SoftPrediction(
7271
soft=train_and_predict(train, test, flags, in_algo_args["seed"])
7372
).save_to_file(Path(in_algo_args["predictions"]))

ethicml/implementations/hgr_modules/facl_hgr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def hgr(x: torch.Tensor, y: torch.Tensor, density: Type[Kde], damping: float = 1
4949
return torch.svd(Q)[1][1]
5050

5151

52-
def chi_2(x: torch.Tensor, y: torch.Tensor, density: Type[Kde], damping: float = 0) -> float:
52+
def chi_2(x: torch.Tensor, y: torch.Tensor, density: Type[Kde], damping: float = 0) -> torch.Tensor:
5353
r"""The :math:`\chi^2` divergence between the joint distribution and the product of marginals.
5454
5555
This is know to be the square of an upper-bound on the Hirschfeld-Gebelein-Renyi maximum

0 commit comments

Comments
 (0)