Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Cleanup #47

Merged
merged 10 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
groups:
actions:
patterns:
- "*"
7 changes: 6 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
branches: [main, github-actions-test]
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

permissions:
contents: write

Expand Down Expand Up @@ -43,4 +48,4 @@ jobs:
token: ${{ secrets.DOCUMENTATION_KEY }}
repository-name: pyt-team/pyt-team.github.io
target-folder: topoembedx
clean: true
clean: true
10 changes: 7 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ name: Linting

on:
push:
branches: [ main,github-actions-test ]
branches: [main, github-actions-test]
pull_request:
branches: [ main ]
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
24 changes: 13 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ name: "Test"

on:
push:
branches: [main,github-actions-test]
branches: [main, github-actions-test]
paths-ignore:
- 'docs/**'
- 'README.md'
- 'LICENSE.txt'
- '.gitignore'
- "docs/**"
- "README.md"
- "LICENSE.txt"
- ".gitignore"

pull_request:
branches: [main]
paths-ignore:
- 'docs/**'
- 'README.md'
- 'LICENSE.txt'
- '.gitignore'
- "docs/**"
- "README.md"
- "LICENSE.txt"
- ".gitignore"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:

pytest:
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -52,4 +54,4 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.xml
fail_ci_if_error: false
fail_ci_if_error: false
34 changes: 24 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
default_language_version:
python: python3.10

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.6.0
hooks:
- id: fix-byte-order-marker
- id: check-case-conflict
Expand All @@ -16,18 +13,35 @@ repos:
args:
- --maxkb=2048
- id: trailing-whitespace
- id: requirements-txt-fixer

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
rev: v0.4.10
hooks:
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix ]
types_or: [python, pyi, jupyter]
args: ["--fix", "--show-fixes"]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
types_or: [python, pyi, jupyter]

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==24.*]

- repo: https://github.com/numpy/numpydoc
rev: v1.6.0
rev: v1.7.0
hooks:
- id: numpydoc-validation

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0"
hooks:
- id: prettier

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
30 changes: 24 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -64,7 +64,6 @@ homepage="https://github.com/pyt-team/TopoEmbedX"
repository="https://github.com/pyt-team/TopoEmbedX"

[tool.ruff]
target-version = "py310"
extend-include = ["*.ipynb"]

[tool.ruff.format]
Expand All @@ -77,16 +76,23 @@ select = [
"W", # warnings
"I", # import order
"UP", # pyupgrade rules
"B", # bugbear rules
"PIE", # pie rules
"Q", # quote rules
"RET", # return rules
"SIM", # code simplifications
"NPY", # numpy rules
"PERF", # performance rules
"RUF", # miscellaneous rules
]
ignore = ["E501"] # line too long

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "F403"]

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401", "F403"]

[tool.setuptools.dynamic]
version = {attr = "topoembedx.__version__"}

Expand All @@ -104,4 +110,16 @@ disable_error_code = ["import-untyped"]
plugins = "numpy.typing.mypy_plugin"

[tool.pytest.ini_options]
addopts = "--capture=no"
minversion = "7.0"
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
filterwarnings = [
"error",
"ignore::FutureWarning",
"ignore::scipy.sparse._base.SparseEfficiencyWarning",
]
log_cli_level = "info"
testpaths = ["test"]

[tool.coverage.report]
exclude_lines = ["pragma: not covered", "@overload"]
2 changes: 1 addition & 1 deletion test/classes/test_cell2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TestCell2Vec:
def test_fit_and_get_embedding(self):
"""Test get_embedding."""
# Create a small complex
cx = tnx.classes.CellComplex([[1, 2, 3, 4], [3, 4, 5, 6, 7, 8]], ranks=2)
cx = tnx.CellComplex([[1, 2, 3, 4], [3, 4, 5, 6, 7, 8]], ranks=2)

# Create a Cell2Vec object
dc = Cell2Vec(dimensions=5)
Expand Down
10 changes: 6 additions & 4 deletions topoembedx/classes/cell2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import toponetx as tnx
from karateclub import Node2Vec
from scipy.sparse import csr_matrix

from topoembedx.neighborhood import neighborhood_from_complex

Expand Down Expand Up @@ -50,14 +51,14 @@ class Cell2Vec(Node2Vec):
Random seed value.
"""

A: np.ndarray
A: csr_matrix
ind: list

def fit(
self,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
neighborhood_dim=None,
) -> None:
"""Fit a Cell2Vec model.

Expand Down Expand Up @@ -93,7 +94,8 @@ def fit(
complex, neighborhood_type, neighborhood_dim
)

g = nx.from_numpy_matrix(self.A)
g = nx.from_numpy_array(self.A)
g.add_edges_from((index, index) for index in range(g.number_of_nodes()))

super().fit(g)

Expand All @@ -112,5 +114,5 @@ def get_embedding(self, get_dict: bool = False) -> dict | np.ndarray:
"""
emb = super().get_embedding()
if get_dict:
return dict(zip(self.ind, emb))
return dict(zip(self.ind, emb, strict=True))
return emb
12 changes: 8 additions & 4 deletions topoembedx/classes/cell_diff2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import toponetx as tnx
from karateclub import Diff2Vec
from scipy.sparse import csr_matrix

from topoembedx.neighborhood import neighborhood_from_complex

Expand Down Expand Up @@ -35,14 +36,14 @@
Random seed value.
"""

A: np.ndarray
A: csr_matrix
ind: list

def fit(
self,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
neighborhood_dim=None,
) -> None:
"""Fit a CellDiff2Vec model.

Expand Down Expand Up @@ -78,11 +79,14 @@
complex, neighborhood_type, neighborhood_dim
)

g = nx.from_numpy_matrix(self.A)
self.A.setdiag(1)
g = nx.from_numpy_array(self.A)

if self.diffusion_cover > g.number_of_nodes():
raise ValueError(
"The diffusion_cover is too large for the size of the graph."
)

super().fit(g)

def get_embedding(self, get_dict: bool = False) -> dict | np.ndarray:
Expand All @@ -100,5 +104,5 @@
"""
emb = super().get_embedding()
if get_dict:
return dict(zip(self.ind, emb))
return dict(zip(self.ind, emb, strict=True))

Check warning on line 107 in topoembedx/classes/cell_diff2vec.py

View check run for this annotation

Codecov / codecov/patch

topoembedx/classes/cell_diff2vec.py#L107

Added line #L107 was not covered by tests
return emb
10 changes: 6 additions & 4 deletions topoembedx/classes/deepcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import toponetx as tnx
from karateclub import DeepWalk
from scipy.sparse import csr_matrix

from topoembedx.neighborhood import neighborhood_from_complex

Expand Down Expand Up @@ -35,14 +36,14 @@ class DeepCell(DeepWalk):
Random seed to use for reproducibility.
"""

A: np.ndarray
A: csr_matrix
ind: list

def fit(
self,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
neighborhood_dim=None,
) -> None:
"""Fit the model.

Expand Down Expand Up @@ -78,7 +79,8 @@ def fit(
complex, neighborhood_type, neighborhood_dim
)

g = nx.from_numpy_matrix(self.A)
self.A.setdiag(1)
g = nx.from_numpy_array(self.A)

super().fit(g)

Expand All @@ -97,5 +99,5 @@ def get_embedding(self, get_dict: bool = False) -> dict | np.ndarray:
"""
emb = super().get_embedding()
if get_dict:
return dict(zip(self.ind, emb))
return dict(zip(self.ind, emb, strict=True))
return emb
10 changes: 6 additions & 4 deletions topoembedx/classes/higher_order_laplacian_eigenmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
import toponetx as tnx
from karateclub import LaplacianEigenmaps
from scipy.sparse import csr_matrix

from topoembedx.neighborhood import neighborhood_from_complex

Expand All @@ -23,7 +24,7 @@ class HigherOrderLaplacianEigenmaps(LaplacianEigenmaps):
Random seed value.
"""

A: np.ndarray
A: csr_matrix
ind: list

def __init__(
Expand All @@ -39,7 +40,7 @@ def fit(
self,
complex: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim={"rank": 0, "via_rank": -1},
neighborhood_dim=None,
) -> None:
"""Fit a Higher Order Laplacian Eigenmaps model.

Expand Down Expand Up @@ -75,7 +76,8 @@ def fit(
complex, neighborhood_type, neighborhood_dim
)

g = nx.from_numpy_matrix(self.A)
self.A.setdiag(1)
g = nx.from_numpy_array(self.A)

super().fit(g)

Expand All @@ -94,5 +96,5 @@ def get_embedding(self, get_dict: bool = False) -> dict | np.ndarray:
"""
emb = super().get_embedding()
if get_dict:
return dict(zip(self.ind, emb))
return dict(zip(self.ind, emb, strict=True))
return emb
Loading
Loading