Skip to content

Commit 546363c

Browse files
committed
Merge remote-tracking branch 'upstream/main'
# Conflicts: # docs/source/notebooks/language_notebooks/language_model_game.ipynb # docs/source/notebooks/vision_notebooks/vision_transformer.ipynb # shapiq/approximator/__init__.py # shapiq/approximator/_base.py # shapiq/game_theory/indices.py # shapiq/games/benchmark/_setup/_vit_setup.py # shapiq/games/benchmark/local_xai/benchmark_image.py
2 parents 1cc05dd + e6e7a2e commit 546363c

240 files changed

Lines changed: 11392 additions & 4057 deletions

File tree

Some content is hidden

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

.coveragerc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.dev-pre-commit-config.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/CONTRIBUTING.md

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
# ✌️ Contributing Guidelines
22

3-
This document outlines the guidelines for contributing to the project. It should enable contributors
4-
to understand the process for applying changes to the project and how to interact with the community.
3+
This document outlines how to easily contribute to the project.
54
For the code of conduct, please refer to the [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md).
65

76
## 🗺️ What to Work On
8-
First, we welcome contributions from everyone in every form. If you feel that something is missing
9-
or could be improved, feel free to change it. However, to streamline the process of contributing
10-
higher-tier changes or features to the project, we maintain an open
11-
[roadmap](https://github.com/users/mmschlk/projects/4/views/4). There, we collect ideas and features
12-
that we want to add to the project. If you want to work on something, please check the roadmap first
13-
to see if the feature is already planned or if there is a similar feature that you could contribute
14-
to.
15-
16-
### 🙏 Discussions
7+
First, we welcome contributions **from everyone** in **every form**. If you feel that something is
8+
missing or could be improved, feel free to change it. However, to streamline the process of
9+
contributing higher-tier changes or features to the project, we maintain an open
10+
[roadmap](https://github.com/users/mmschlk/projects/4/views/4) which is just storing all the ideas
11+
and problems found on shapiq's [issues page](https://github.com/mmschlk/shapiq/issues). If you want
12+
to work on something, check out the roadmap or issues first to see if the feature is already
13+
planned or if there is a similar feature that you could contribute to.
14+
15+
Here are some examples of what we are very happy to receive contributions for:
16+
17+
### Approximators
18+
We are always looking for new approximators to add to `shapiq`. Approximators are always extending
19+
the base class `Approximator` and implementing `approximate` method. Make sure to create unit tests
20+
for the new approximator.
21+
22+
### Explainers
23+
If you want to add a new explainer, you can extend the base class `Explainer` and implement the
24+
`explain_function` method. Make sure to create unit tests for the new explainer. Note that
25+
explainers are quite elaborate, so it is a very good idea to open a discussion before starting to
26+
work on a new explainer.
27+
28+
### Model Support
29+
You like a particular machine learning model and it is not yet supported by `shapiq`? Maybe you can
30+
add support in the [transformation code](https://github.com/mmschlk/shapiq/blob/56e1ea4a41d185b8364ca8e6370a01646dd792c6/shapiq/explainer/utils.py#L1) or [tree/validation](https://github.com/mmschlk/shapiq/blob/56e1ea4a41d185b8364ca8e6370a01646dd792c6/shapiq/explainer/tree/validation.py).
31+
Make sure to add tests for the new model as part of the unit tests (you can find the tests of the
32+
other model types).
33+
34+
### Visualizations
35+
If you have a nice idea to visualize Shapley values or Shapley interaction values, you can add a new
36+
visualization to the `shapiq.plot` package. Make sure that plots are also available through the
37+
`InteractionValues` object like the other plots (e.g. `InteractionValues.plot_force`). Make sure to
38+
add tests for the new visualization.
39+
40+
### 🙏 Discussions and Issues
1741
If you have an idea for a new feature or a change, we encourage everyone to open a discussion in the
18-
[Discussions](https://github.com/mmschlk/shapiq/discussions/new/choose) section.
42+
[Discussions](https://github.com/mmschlk/shapiq/discussions/new/choose) section or open an [issues](https://github.com/mmschlk/shapiq/issues).
1943
We encourage you to open a discussion so that we can align on the work to be done. It's generally a
2044
good idea to have a quick discussion before opening a pull request that is potentially out-of-scope.
2145

@@ -39,52 +63,37 @@ git clone https://github.com/mmschlk/shapiq/
3963
```
4064

4165
Next you need a python environment with a supported version of python. We recommend using
42-
[pyenv](https://github.com/pyenv/pyenv-installer). Once you have pyenv, you can install the latest
43-
Python version `shapiq` supports:
66+
[uv](https://docs.astral.sh/uv/getting-started/installation), which works extremely fast and helps
67+
to stay up-to-date with the latest Python versions. With `uv`, you can set up your development
68+
environment with the following command:
4469

4570
```sh
46-
pyenv install 3.10
71+
uv sync --all-extras --dev
4772
```
4873

49-
Then, create a virtual environment and install the development dependencies:
74+
Now you are all set up and ready to go.
5075

51-
```sh
52-
cd shapiq
53-
python -m venv .venv
54-
source .venv/bin/activate
55-
pip install -e .[dev]
56-
```
5776

58-
---
59-
> 📝 **Note**: Since `shapiq` uses the `requests` library, you might need to install the
77+
> 📝 **Note**: `shapiq` uses the `requests` library, you might need to install the
6078
> certificates on your MacOS system ([more information](https://stackoverflow.com/a/53310545)).
6179
```sh
6280
/Applications/Python\ 3.x/Install\ Certificates.command
6381
```
64-
---
6582

66-
Finally, install the [pre-commit](https://pre-commit.com/) push hooks. This will run some code
67-
quality checks every time you push to GitHub.
83+
### 🛠️ Pre-Commit Hooks
84+
To ensure that the code quality is maintained, we use `pre-commit` hooks. You need to install the
85+
[pre-commit](https://pre-commit.com/) hooks. This will run some code quality checks every time
86+
you push to GitHub. You can view the checks in the `.pre-commit-config.yaml` file and the setup in
87+
the `pyproject.toml` file.
6888

6989
```sh
70-
pre-commit install --hook-type pre-push
90+
uv run pre-commit install
7191
```
7292

7393
If you want, you can optionally run `pre-commit` at any time as so:
7494

7595
```sh
76-
pre-commit run --all-files
77-
```
78-
79-
## 📝 Commit Messages
80-
81-
We do not enforce a strict commit message format, but we encourage you to follow good practices.
82-
We recommend to use action-words to automatically close issues or pull requests (example: `closes #123`).
83-
For example, start the commit message with a verb in the imperative mood, and keep the message short
84-
and concise. For example:
85-
86-
```
87-
add feature-xyz and closes #123
96+
uv run pre-commit run --all-files
8897
```
8998

9099
## 🛠️ Making Changes
@@ -102,7 +111,7 @@ To build the documentation on your end and to check if your changes are document
102111
need to install the documentation dependencies:
103112

104113
```sh
105-
pip install -e .[docs]
114+
uv sync --all-extras --dev --docs
106115
```
107116

108117
Then, you can build the documentation from the root of the repository with:
@@ -116,18 +125,18 @@ in your browser to see the rendered documentation.
116125

117126
### 🎯 Testing Changes
118127

119-
We use `pytest` for running unit tests and coverage. In the near future we will add `mypy` to the
120-
static type checking.
128+
We use `pytest` for running unit tests and coverage.
121129

122130
#### Unit Tests
123131

124132
Unit tests **absolutely need to pass**. Write unit tests for your changes. If you are adding a new
125133
feature, you need to add tests for the new feature. If you are fixing a bug it is a good idea to add
126134
a test that shows the bug and that your fix works.
127-
Unit tests are located in the `tests` directory. To run the tests, you can use the following command:
135+
Unit tests are located in the `tests` directory. To run the tests with `pytest`, you can use the
136+
following command and replace `n_jobs` with the number of jobs you want to run in parallel:
128137

129138
```sh
130-
pytest
139+
uv run pytest -n n_jobs
131140
```
132141

133142
#### Coverage
@@ -138,7 +147,7 @@ We use `pytest-cov` to measure the test coverage. To run the tests with coverage
138147
following command:
139148

140149
```sh
141-
pytest --cov=shapiq
150+
uv run pytest --cov=shapiq
142151
```
143152

144153
#### Static Type Checking and Code Quality
@@ -147,14 +156,5 @@ Currently, we do not have static type checking in place. We use `pre-commit` to
147156
checks. These checks **absolutely need to pass**. You can run the checks with the following command:
148157

149158
```sh
150-
pre-commit run --all-files
151-
```
152-
153-
In the near future we aim to use `mypy` for type checking. Once added this will also be part of the
154-
pre-commit pipeline and hence **absolutely need to pass**.
155-
156-
If you want, you can run `mypy` with the following command:
157-
158-
```sh
159-
mypy shapiq
159+
uv run pre-commit run --all-files
160160
```

.github/dependabot.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ updates:
88
- package-ecosystem: "pip"
99
directory: "/"
1010
schedule:
11-
interval: "monthly"
11+
interval: "weekly"
1212
open-pull-requests-limit: 12
1313
groups:
1414
pip-all-updates:
1515
patterns:
1616
- "*"
17+
1718
- package-ecosystem: "github-actions"
1819
directory: "/"
1920
schedule:
20-
interval: "monthly"
21+
interval: "weekly"
2122
open-pull-requests-limit: 12

.github/workflows/code-quality.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@ jobs:
1717

1818
steps:
1919
- uses: actions/checkout@v4
20+
2021
- name: Set up Python
2122
uses: actions/setup-python@v5
2223
with:
2324
python-version: "3.10"
24-
cache: 'pip'
25-
- name: Install dependencies
26-
run: |
27-
python -m pip install --upgrade pip
28-
pip install -r requirements.txt
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v6
28+
with:
29+
enable-cache: true
30+
2931
- name: Install pre-commit
3032
run: |
31-
pip install pre-commit
32-
pre-commit install
33+
uv sync --only-group lint
34+
uv run pre-commit install
35+
3336
- name: Run code-quality checks
34-
run: SKIP=mypy pre-commit run --all-files
37+
run: uv run pre-commit run --all-files
Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,31 @@ jobs:
1919

2020
steps:
2121
- uses: actions/checkout@v4
22+
2223
- name: Set up Python
2324
uses: actions/setup-python@v5
2425
with:
25-
python-version: "3.10"
26-
cache: 'pip'
26+
python-version: "3.11"
27+
28+
- name: Install uv
29+
uses: astral-sh/setup-uv@v6
30+
with:
31+
enable-cache: true
32+
33+
- name: Cache UV packages
34+
uses: actions/cache@v4
35+
with:
36+
path: ~/.cache/uv
37+
key: uv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'uv.lock') }}
38+
restore-keys: |
39+
uv-${{ runner.os }}-${{ matrix.python-version }}-
40+
2741
- name: Install dependencies
28-
run: |
29-
python -m pip install --upgrade pip
30-
pip install -r requirements.txt
31-
- name: Test with pytest
32-
run: |
33-
pip install pytest pytest-cov
34-
pytest --cov=shapiq --cov-report=xml
42+
run: uv sync --all-extras --dev
43+
44+
- name: Measure coverage
45+
run: uv run pytest --cov=shapiq --cov-report=xml -n logical
46+
3547
- name: Coveralls
3648
uses: coverallsapp/github-action@v2
3749
with:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Install & Import shapiq
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
install-and-import:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Install uv and Python
19+
uses: astral-sh/setup-uv@v6
20+
with:
21+
python-version: "3.11"
22+
activate-environment: true
23+
- name: Install package using uv
24+
run: uv pip install .
25+
26+
- name: Test import
27+
run: uv run python -c "import shapiq; print('✅ shapiq imported successfully')"

.github/workflows/python-publish.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ jobs:
2323

2424
steps:
2525
- uses: actions/checkout@v4
26+
2627
- name: Set up Python
2728
uses: actions/setup-python@v5
2829
with:
2930
python-version: '3.10'
31+
3032
- name: Install dependencies
3133
run: |
3234
python -m pip install --upgrade pip
3335
pip install build
36+
3437
- name: Build package
3538
run: python -m build
39+
3640
- name: Publish package
37-
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc
41+
uses: pypa/gh-action-pypi-publish@v1.12.4
3842
with:
3943
user: __token__
4044
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/unit-tests-current.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)