-
Notifications
You must be signed in to change notification settings - Fork 13
Modernize tooling, migrate metadata, refactor run(), make Louvain RNG deterministic #108
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e71a193
Add CLAUDE.md and apply minor cleanups
claude e963dfc
Migrate linting and formatting to ruff
claude 34f2a27
Migrate project metadata from setup.py to pyproject.toml (PEP 621)
claude e500a21
Add type hints to public API
claude 04c73ee
Loosen flaky RNG-dependent equality asserts in test_pygenstability
claude b0f7ac2
Ignore results.pkl run artifact
claude 75c2eda
Assorted cleanups: numpy warnings, URLs, PDF, spectral inverse
claude 55a6fef
Refactor run() into smaller helpers
claude d500e31
Finish remaining backlog: upper bounds, warnings, lint CI
claude a43390c
Speed up _assign_increasing_ids; explicit __all__; py.typed; pre-commit
claude 0361d7a
Make Louvain RNG deterministic end-to-end
72abccb
Fix E501 line-length on _optimise signature
55b6c09
Bump submodule to portable Fisher-Yates, regenerate fixtures
347d284
Stop plots from popping during tests
835d0a8
Re-enable strict dataclustering fixtures and add determinism regressi…
f012b7c
Point submodule at upstream now that the RNG fix has merged
67a282e
Address PR review: trim Claude-style comments, type graph, rename _fi…
a2431fa
Address review nits: typo, n_workers param test, gitignore, regen com…
cec2162
Add user-controllable seed to run() and DataClustering, fix typos
ef49c47
Wire test fixtures to the new seed parameter
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| repos: | ||
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| rev: v0.15.8 | ||
| hooks: | ||
| - id: ruff | ||
| args: [--fix] | ||
| - id: ruff-format | ||
|
|
||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v5.0.0 | ||
| hooks: | ||
| - id: trailing-whitespace | ||
| - id: end-of-file-fixer | ||
| - id: check-yaml | ||
| - id: check-toml | ||
| - id: check-added-large-files | ||
| args: [--maxkb=1024] |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # CLAUDE.md | ||
|
|
||
| Orientation for Claude Code sessions working in this repo. | ||
|
|
||
| ## Project | ||
|
|
||
| PyGenStability is a Python package for multiscale community detection via | ||
| **generalized Markov Stability**. The core loop scans a range of Markov times, | ||
| runs many generalized-Louvain (or Leiden) optimizations per scale, and | ||
| post-processes the partitions (robustness, NVI, optimal scale selection). | ||
|
|
||
| A C++ Louvain implementation is shipped as a pybind11 extension. | ||
|
|
||
| ## Layout | ||
|
|
||
| - `src/pygenstability/` — package source | ||
| - `tests/` — pytest suite (100% coverage enforced, see `tox.ini`) | ||
| - `examples/` — notebooks and scripts, including `real_examples/` (powergrid, protein) | ||
| - `docs/` — Sphinx + nbsphinx | ||
| - `extra/lemon/`, `generalizedLouvain/` — C++ headers / sources used by the extension | ||
|
|
||
| ## Key modules (`src/pygenstability/`) | ||
|
|
||
| - `pygenstability.py` — `run()` orchestrates the scale scan, parallelism, and post-processing | ||
| - `constructors.py` — quality-matrix / null-model builders (linearized, continuous, directed, signed, …) | ||
| - `optimal_scales.py` — robustness-based optimal scale selection | ||
| - `plotting.py` — matplotlib plots; optional plotly/networkx branches | ||
| - `data_clustering.py` — end-to-end data-to-graph clustering workflow | ||
| - `app.py` — Click CLI; console script `pygenstability=pygenstability.app:cli` | ||
| - `io.py` — pickle save/load helpers | ||
| - `contrib/sankey.py` — interactive Sankey diagram (optional plotly) | ||
|
|
||
| ## Build / test | ||
|
|
||
| ```bash | ||
| pip install -e . # builds pybind11 C++ extension (-std=c++11) | ||
| pytest # needs the extension built first | ||
| tox # full matrix | ||
| tox -e py310 | py311 | py312 # single interpreter | ||
| tox -e lint # pylint + pycodestyle + pydocstyle + isort + black --check | ||
| tox -e format # black + isort (writes) | ||
| tox -e docs # Sphinx build | ||
| ``` | ||
|
|
||
| Supported Python: **3.10 / 3.11 / 3.12** (see `tox.ini`). | ||
|
|
||
| ## Gotchas | ||
|
|
||
| - The C++ extension is declared `optional=True` in `setup.py`. If it fails to | ||
| compile, `import pygenstability.generalized_louvain` silently fails and | ||
| Louvain is unavailable; Leiden fallback only kicks in if `leidenalg` is | ||
| installed (see `_check_method` in `pygenstability.py`). | ||
| - BLAS/OpenMP thread counts are pinned to 1 inside worker processes | ||
| (`_limit_numpy` in `constructors.py`) to avoid multiprocessing contention. | ||
| Don't remove this without understanding the parallelism model. | ||
| - Optional extras: `[plotly]`, `[leiden]` (igraph + leidenalg), `[networkx]`, | ||
| `[all]`. | ||
| - Tests write expected-output YAMLs under `tests/data/`. When changing | ||
| numerics, regenerate fixtures deliberately rather than blindly accepting | ||
| diffs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule generalizedLouvain
updated
9 files
| +20 −9 | CPP/cliques/Makefile | |
| +89 −26 | CPP/cliques/graphhelpers.h | |
| +23 −46 | CPP/cliques/linearised_internals_comb.h | |
| +22 −57 | CPP/cliques/linearised_internals_generic.h | |
| +22 −39 | CPP/cliques/linearised_internals_norm.h | |
| +177 −171 | CPP/cliques/louvain_gen.h | |
| +7 −7 | CPP/cliques/run_gen_louvain.cpp | |
| +11 −28 | CPP/cliques/stability_gen.h | |
| +28 −41 | CPP/cliques/vector_partition.h |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,96 @@ | ||
| [build-system] | ||
| requires = ["setuptools", "numpy", "cython", "pybind11>=2.6.0", "wheel"] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| [project] | ||
| name = "PyGenStability" | ||
| version = "0.2.7" | ||
| description = "Python binding of generalised Louvain with Markov Stability" | ||
| readme = "README.md" | ||
| requires-python = ">=3.10" | ||
| authors = [ | ||
| {name = "Alexis Arnaudon", email = "alexis.arnaudon@epfl.ch"}, | ||
| {name = "Juni Schindler", email = "juni.schindler19@imperial.ac.uk"}, | ||
| ] | ||
| dependencies = [ | ||
| "numpy>=1.18.1,<3", | ||
| "scipy>=1.4.1,<2", | ||
| "matplotlib>=3.1.3", | ||
| "scikit-learn", | ||
| "cmake>=3.16.3", | ||
| "click>=7.0", | ||
| "tqdm>=4.45.0", | ||
| "pybind11>=2.10.0", | ||
| "pandas>=1.0.0", | ||
| "threadpoolctl", | ||
| ] | ||
|
|
||
| [project.urls] | ||
| Homepage = "https://github.com/barahona-research-group/PyGenStability" | ||
|
|
||
| [project.optional-dependencies] | ||
| plotly = ["plotly>=3.6.0"] | ||
| leiden = ["igraph", "leidenalg"] | ||
| networkx = ["networkx>=3.0"] | ||
| all = [ | ||
| "plotly>=3.6.0", | ||
| "igraph", | ||
| "leidenalg", | ||
| "networkx>=3.0", | ||
| "pyyaml", | ||
| "dictdiffer", | ||
| "pytest", | ||
| "pytest-cov", | ||
| "pytest-html", | ||
| "diff-pdf-visually", | ||
| "ipython!=8.7.0", | ||
| ] | ||
|
|
||
| [project.scripts] | ||
| pygenstability = "pygenstability.app:cli" | ||
|
|
||
| [tool.setuptools] | ||
| zip-safe = false | ||
| include-package-data = true | ||
|
|
||
| [tool.setuptools.packages.find] | ||
| where = ["src"] | ||
| namespaces = true | ||
|
|
||
| [tool.setuptools.package-dir] | ||
| "" = "src" | ||
|
|
||
| [tool.ruff] | ||
| line-length = 100 | ||
| target-version = "py310" | ||
|
|
||
| [tool.ruff.lint] | ||
| select = [ | ||
| "E", # pycodestyle errors | ||
| "W", # pycodestyle warnings | ||
| "F", # pyflakes | ||
| "I", # isort | ||
| "D", # pydocstyle | ||
| "PLE", # pylint errors | ||
| ] | ||
| ignore = [ | ||
| "E731", # do not assign a lambda expression | ||
| "E741", # ambiguous variable name | ||
| "E203", # whitespace before ':' (black-compatible) | ||
| "W605", # invalid escape sequence | ||
| "D102", # missing docstring in public method | ||
| "D105", # missing docstring in magic method | ||
| "D107", # missing docstring in __init__ | ||
| "D416", # section name should end with a colon (numpy-style headers used) | ||
| ] | ||
|
|
||
| [tool.ruff.lint.pydocstyle] | ||
| convention = "google" | ||
|
|
||
| [tool.ruff.lint.isort] | ||
| force-single-line = true | ||
|
|
||
| [tool.ruff.lint.per-file-ignores] | ||
| "tests/**" = ["D"] | ||
| "docs/**" = ["D"] | ||
| "examples/**" = ["D", "E", "F"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,20 @@ | ||
| """Setup.""" | ||
| """Setup for the pybind11 C++ extension. | ||
|
|
||
| from pybind11.setup_helpers import Pybind11Extension | ||
| from setuptools import find_namespace_packages, setup | ||
|
|
||
| __version__ = "0.2.7" | ||
| All project metadata lives in pyproject.toml (PEP 621). This file | ||
| only declares the optional C++ extension. | ||
| """ | ||
|
|
||
| ext_modules = [ | ||
| Pybind11Extension( | ||
| "pygenstability.generalized_louvain", | ||
| ["src/pygenstability/generalized_louvain/generalized_louvain.cpp"], | ||
| include_dirs=["extra", "generalizedLouvain"], | ||
| extra_compile_args=["-std=c++11"], | ||
| optional=True, | ||
| ), | ||
| ] | ||
| plotly_require = ["plotly>=3.6.0"] | ||
|
|
||
| test_require = [ | ||
| "pyyaml", | ||
| "dictdiffer", | ||
| "pytest", | ||
| "pytest-cov", | ||
| "pytest-html", | ||
| "diff-pdf-visually", | ||
| "ipython!=8.7.0", # see https://github.com/spatialaudio/nbsphinx/issues/687 | ||
| ] | ||
| install_requires = [ | ||
| "numpy>=1.18.1", | ||
| "scipy>=1.4.1", | ||
| "matplotlib>=3.1.3", | ||
| "scikit-learn", | ||
| "cmake>=3.16.3", | ||
| "click>=7.0", | ||
| "tqdm>=4.45.0", | ||
| "pybind11>=2.10.0", | ||
| "pandas>=1.0.0", | ||
| "threadpoolctl", | ||
| ] | ||
| leiden_install = ["igraph", "leidenalg"] | ||
| networkx_install = ["networkx>=3.0"] | ||
| from pybind11.setup_helpers import Pybind11Extension | ||
| from setuptools import setup | ||
|
|
||
| setup( | ||
| name="PyGenStability", | ||
| version=__version__, | ||
| author="Alexis Arnaudon, Juni Schindler", | ||
| author_email="alexis.arnaudon@epfl.ch, juni.schindler19@imperial.ac.uk", | ||
| url="https://github.com/ImperialCollegeLondon/PyGenStability", | ||
| description="Python binding of generalised Louvain with Markov Stability", | ||
| long_description=open("README.md", "r").read(), | ||
| long_description_content_type="text/markdown", | ||
| ext_modules=ext_modules, | ||
| setup_requires=["pybind11>=2.10.0"], | ||
| install_requires=install_requires, | ||
| zip_safe=False, | ||
| extras_require={ | ||
| "plotly": plotly_require, | ||
| "leiden": leiden_install, | ||
| "networkx": networkx_install, | ||
| "all": plotly_require + test_require + leiden_install + networkx_install, | ||
| }, | ||
| entry_points={"console_scripts": ["pygenstability=pygenstability.app:cli"]}, | ||
| packages=find_namespace_packages("src"), | ||
| include_package_data=True, | ||
| package_dir={"": "src"}, | ||
| ext_modules=[ | ||
| Pybind11Extension( | ||
| "pygenstability.generalized_louvain", | ||
| ["src/pygenstability/generalized_louvain/generalized_louvain.cpp"], | ||
| include_dirs=["extra", "generalizedLouvain"], | ||
| extra_compile_args=["-std=c++11"], | ||
| optional=True, | ||
| ), | ||
| ], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.