Skip to content

Commit 71eaa8a

Browse files
committed
Improved CI, updated info. Minor fixes to tests
1 parent fecf896 commit 71eaa8a

12 files changed

Lines changed: 67 additions & 32 deletions

File tree

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore = E203, W503
4+
exclude =
5+
docs

.github/workflows/test-bench.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,38 @@ name: test-bench
33
on:
44
push:
55
branches:
6-
- develop
7-
- main
6+
- main
7+
pull_request:
8+
branches:
9+
- main
810

911
jobs:
1012
test-bench-job:
1113
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1217
steps:
1318
- name: Check out repository code
1419
uses: actions/checkout@v4
20+
21+
- name: Cache pip
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.cache/pip
25+
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
26+
restore-keys: |
27+
${{ runner.os }}-pip-
28+
1529
- name: Install Python
1630
uses: actions/setup-python@v5
1731
with:
18-
python-version: '3.10'
32+
python-version: ${{ matrix.python-version }}
33+
1934
- name: Install dependencies
2035
run: |
2136
python -m pip install -e .[dev]
37+
2238
- name: Run benchmarks
2339
run: |
2440
python -m unittest discover -s tests -p 'test_bench_*.py'

.github/workflows/test-unit.yml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,44 @@ name: test-unit
22

33
on:
44
push:
5-
branches:
6-
- develop
7-
- main
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
810

911
jobs:
1012
test-unit-job:
1113
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1217
steps:
1318
- name: Check out repository code
1419
uses: actions/checkout@v4
20+
21+
- name: Cache pip
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.cache/pip
25+
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
26+
restore-keys: |
27+
${{ runner.os }}-pip-
28+
1529
- name: Install Python
1630
uses: actions/setup-python@v5
1731
with:
18-
python-version: '3.10'
32+
python-version: ${{ matrix.python-version }}
33+
1934
- name: Install dependencies
2035
run: |
2136
python -m pip install -e .[dev]
37+
2238
- name: Run tests and code coverage
2339
run: |
2440
coverage run --source=src -m unittest discover -s tests -p 'test_unit_*.py'
2541
coverage report -m
42+
2643
- name: Upload coverage reports to Codecov
2744
uses: codecov/codecov-action@v4
2845
env:

CONTRIBUTING.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ removed whenever required by a new jump in major version.
112112
113113
We follow [PEP 8](https://peps.python.org/pep-0008/) for Python code style.
114114
You can run a linter to check your code. The dev dependencies of **tda-mapper**
115-
include `black` and `isort` to help you manage that.
115+
include `flake8`, `black` and `isort` to help you manage code style.
116+
117+
```bash
118+
flake8
119+
```
116120
117121
```bash
118122
black .

benchmarks/benchmark.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ def run_gm(X, n, p):
7474
cover=gm.CubicalCover(n_intervals=n, overlap_frac=p),
7575
clusterer=TrivialEstimator(),
7676
)
77-
mapper_graph = pipe.fit_transform(X)
77+
pipe.fit_transform(X)
7878
t1 = time.time()
7979
return t1 - t0
8080

8181

8282
def run_tm(X, n, p):
8383
t0 = time.time()
84-
mapper_graph = tm.core.MapperAlgorithm(
84+
tm.core.MapperAlgorithm(
8585
cover=tm.cover.CubicalCover(
8686
n_intervals=n,
8787
overlap_frac=p,
@@ -99,7 +99,7 @@ def run_tm(X, n, p):
9999
def run_km(X, n, p):
100100
t0 = time.time()
101101
mapper = km.KeplerMapper(verbose=0)
102-
graph = mapper.map(
102+
mapper.map(
103103
lens=X,
104104
X=X,
105105
cover=km.Cover(n_cubes=n, perc_overlap=p),

docs/source/notebooks/digits.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from sklearn.datasets import load_digits
4545
from sklearn.decomposition import PCA
4646

47-
from tdamapper.clustering import FailSafeClustering
4847
from tdamapper.cover import CubicalCover
4948
from tdamapper.learn import MapperAlgorithm
5049
from tdamapper.plot import MapperPlot

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ dev = [
4040
"coverage[toml]",
4141
"pandas",
4242
"scikit-learn<1.6.0",
43-
"flake8",
4443
"black[jupyter]",
45-
"isort"
44+
"isort",
45+
"flake8",
4646
]
4747

4848
[project.urls]
@@ -80,4 +80,3 @@ include_trailing_comma = true
8080
force_grid_wrap = 0
8181
combine_as_imports = true
8282
skip = ["venv", ".venv", "build", "dist"]
83-

tests/test_bench_cover.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ def cover(self, vpt, X, r):
3838

3939
def run_bench(self, X, r, dist, vp, **kwargs):
4040
XX = np.array([[i] + [xi for xi in x] for i, x in enumerate(X)])
41-
d = lambda x, y: dist(x[1:], y[1:])
4241
t0 = time.time()
43-
vpt = vp(XX, metric=d, **kwargs)
42+
vpt = vp(XX, metric=lambda x, y: dist(x[1:], y[1:]), **kwargs)
4443
list(self.cover(vpt, XX, r))
4544
t1 = time.time()
4645
self.logger.info(f"time: {t1 - t0}")
4746

4847
def test_cover_random(self):
4948
for r in [1.0, 10.0, 100.0]:
5049
for n in [100, 1000, 10000]:
51-
self.logger.info(f"============ Cover Bench Random ==========")
50+
self.logger.info("============ Cover Bench Random ==========")
5251
self.logger.info(f"[n: {n}, r: {r}]")
5352
X = dataset(num=n)
5453
self.logger.info(">>>>>>> HVPT >>>>>>")
@@ -66,7 +65,7 @@ def test_cover_digits(self):
6665
X, _ = load_digits(return_X_y=True)
6766
# X = PCA(n_components=3).fit_transform(X)
6867
for r in [1.0, 10.0, 100.0]:
69-
self.logger.info(f"======= Cover Bench Digits =======")
68+
self.logger.info("======= Cover Bench Digits =======")
7069
self.logger.info(f"[r: {r}]")
7170
self.logger.info(">>>>>>> HVPT >>>>>>")
7271
self.run_bench(X, r, dist, HVPT, leaf_radius=r, pivoting="random")

tests/test_bench_vptree.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ def _test_ball_search_naive(self, data, name):
7777
d(np.array([0.0]), np.array([0.0])) # jit-compile numba
7878
t0 = time()
7979
for val in data:
80-
neigh = [x for x in data if d(val, x) <= self.eps]
80+
[x for x in data if d(val, x) <= self.eps]
8181
t1 = time()
8282
self.logger.info(f"{name}: {t1 - t0}")
8383

8484
def _test_ball_search(self, data, name, vpt):
8585
t0 = time()
8686
for val in data:
87-
neigh = vpt.ball_search(val, self.eps)
87+
vpt.ball_search(val, self.eps)
8888
t1 = time()
8989
self.logger.info(f"{name}: {t1 - t0}")
9090

@@ -94,13 +94,13 @@ def _test_knn_search_naive(self, data, name):
9494
t0 = time()
9595
for val in data:
9696
data.sort(key=lambda x: d(x, val))
97-
neigh = [x for x in data[: self.k]]
97+
[x for x in data[: self.k]]
9898
t1 = time()
9999
self.logger.info(f"{name}: {t1 - t0}")
100100

101101
def _test_knn_search(self, data, name, vpt):
102102
t0 = time()
103103
for val in data:
104-
neigh = vpt.knn_search(val, self.k)
104+
vpt.knn_search(val, self.k)
105105
t1 = time()
106106
self.logger.info(f"{name}: {t1 - t0}")

tests/test_unit_learn.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22

33
import networkx as nx
44
import numpy as np
5-
from sklearn.cluster import DBSCAN
65
from sklearn.utils.estimator_checks import check_estimator
76

87
from tdamapper.core import TrivialClustering, TrivialCover
98
from tdamapper.cover import BallCover
10-
from tdamapper.learn import (
11-
MapperAlgorithm,
12-
MapperClustering,
13-
)
9+
from tdamapper.learn import MapperAlgorithm, MapperClustering
1410

1511

1612
def euclidean(x, y):

0 commit comments

Comments
 (0)