From 8c55e236330c14249139843bc10eff95824b0400 Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Thu, 23 Oct 2025 13:38:15 +0200 Subject: [PATCH 01/10] doc: install iplotx when building documentation --- scripts/mkdoc.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/mkdoc.sh b/scripts/mkdoc.sh index 1d94d3c32..9309987f6 100755 --- a/scripts/mkdoc.sh +++ b/scripts/mkdoc.sh @@ -54,18 +54,18 @@ if [ ! -d ".venv" ]; then echo "Creating virtualenv..." ${PYTHON:-python3} -m venv .venv - # Install sphinx, matplotlib, pandas, scipy, wheel and pydoctor into the venv. + # Install documentation dependencies into the venv. # doc2dash is optional; it will be installed when -d is given - .venv/bin/pip install -q -U pip wheel sphinx==7.4.7 matplotlib pandas scipy pydoctor sphinx-rtd-theme + .venv/bin/pip install -q -U pip wheel sphinx==7.4.7 matplotlib pandas scipy pydoctor sphinx-rtd-theme iplotx else # Upgrade pip in the virtualenv echo "Upgrading pip in virtualenv..." .venv/bin/pip install -q -U pip wheel fi -# Make sure that Sphinx, PyDoctor (and maybe doc2dash) are up-to-date in the virtualenv +# Make sure that documentation dependencies are up-to-date in the virtualenv echo "Making sure that all dependencies are up-to-date..." -.venv/bin/pip install -q -U sphinx==7.4.7 pydoctor sphinx-gallery sphinxcontrib-jquery sphinx-rtd-theme +.venv/bin/pip install -q -U sphinx==7.4.7 pydoctor sphinx-gallery sphinxcontrib-jquery sphinx-rtd-theme iplotx if [ x$DOC2DASH = x1 ]; then .venv/bin/pip install -U doc2dash fi From b16f27618674dd1913007a52855b76075802cbf9 Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Thu, 23 Oct 2025 13:38:34 +0200 Subject: [PATCH 02/10] chore: updated changelog, bumped version to 1.0.0 --- CHANGELOG.md | 30 ++++++++++++++++++++++++++++-- src/igraph/version.py | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 387957cd3..6b0c3a2b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,32 @@ # igraph Python interface changelog -## [main] +## [1.0.0] - 2025-10-23 + +### Added + +- Added `Graph.Nearest_Neighbor_Graph()`. + +- Added `node_in_weights` argument to `Graph.community_leiden()`. + +- Added `align_layout()` to align the principal axes of a layout nicely + with screen dimensions. + +- Added `Graph.commnity_voronoi()`. + +- Added `Graph.commnity_fluid_communities()`. + +### Changed + +- The C core of igraph was updated to version 1.0.0. + +- Most layouts are now auto-aligned using `align_layout()`. + +### Miscellaneous + +- Documentation improvements. + +- This is the last version that supports Python 3.9 as it will reach its + end of life at the end of October 2025. ## [0.11.9] - 2025-06-11 @@ -727,7 +753,7 @@ Please refer to the commit logs at for a list of changes affecting versions up to 0.8.3. Notable changes after 0.8.3 are documented above. -[main]: https://github.com/igraph/python-igraph/compare/0.11.9...main +[1.0.0]: https://github.com/igraph/python-igraph/compare/0.11.9...1.0.0 [0.11.9]: https://github.com/igraph/python-igraph/compare/0.11.8...0.11.9 [0.11.8]: https://github.com/igraph/python-igraph/compare/0.11.7...0.11.8 [0.11.7]: https://github.com/igraph/python-igraph/compare/0.11.6...0.11.7 diff --git a/src/igraph/version.py b/src/igraph/version.py index fbd1c8748..b69224ddc 100644 --- a/src/igraph/version.py +++ b/src/igraph/version.py @@ -1,2 +1,2 @@ -__version_info__ = (0, 11, 9) +__version_info__ = (1, 0, 0) __version__ = ".".join("{0}".format(x) for x in __version_info__) From a3cfb93a30f9394876e097cc9f33bfa27863b48e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Oct 2025 14:07:32 +0000 Subject: [PATCH 03/10] build(deps): bump actions/upload-artifact from 4 to 5 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 5. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 08557bd16..f7ca8642e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: CIBW_BUILD: "*-musllinux_x86_64" CIBW_TEST_COMMAND: "cd {project} && pip install --prefer-binary '.[test-musl]' && python -m pytest -v tests" - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v5 with: name: wheels-linux-x86_64 path: ./wheelhouse/*.whl @@ -55,7 +55,7 @@ jobs: CIBW_ARCHS_LINUX: aarch64 CIBW_BUILD: "*-manylinux_aarch64" - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v5 with: name: wheels-linux-aarch64-manylinux path: ./wheelhouse/*.whl @@ -77,7 +77,7 @@ jobs: CIBW_BUILD: "*-musllinux_aarch64" CIBW_TEST_COMMAND: "cd {project} && pip install --prefer-binary '.[test-musl]' && python -m pytest -v tests" - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v5 with: name: wheels-linux-aarch64-musllinux path: ./wheelhouse/*.whl @@ -140,7 +140,7 @@ jobs: CIBW_ENVIRONMENT: "LDFLAGS=-L$HOME/local/lib" IGRAPH_CMAKE_EXTRA_ARGS: -DCMAKE_OSX_ARCHITECTURES=${{ matrix.cmake_arch }} ${{ matrix.cmake_extra_args }} -DCMAKE_PREFIX_PATH=$HOME/local - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v5 with: name: wheels-macos-${{ matrix.wheel_arch }} path: ./wheelhouse/*.whl @@ -181,7 +181,7 @@ jobs: limit-access-to-actor: true wait-timeout-minutes: 5 - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v5 with: name: wheels-wasm path: ./dist/*.whl @@ -252,7 +252,7 @@ jobs: IGRAPH_EXTRA_LIBRARIES: libxml2,lzma,zlib,iconv,charset,bcrypt IGRAPH_EXTRA_DYNAMIC_LIBRARIES: wsock32,ws2_32 - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v5 with: name: wheels-win-${{ matrix.wheel_arch }} path: ./wheelhouse/*.whl @@ -294,7 +294,7 @@ jobs: pip install '.[test]' python -m pytest -v tests - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v5 with: name: sdist path: dist/*.tar.gz From fc0009308675592653d8a0b516e94b21fd34e726 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Nov 2025 13:06:34 +0000 Subject: [PATCH 04/10] build(deps): bump pypa/cibuildwheel from 3.2.1 to 3.3.0 Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 3.2.1 to 3.3.0. - [Release notes](https://github.com/pypa/cibuildwheel/releases) - [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md) - [Commits](https://github.com/pypa/cibuildwheel/compare/v3.2.1...v3.3.0) --- updated-dependencies: - dependency-name: pypa/cibuildwheel dependency-version: 3.3.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7ca8642e..5e2ed8ba0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,13 +22,13 @@ jobs: fetch-depth: 0 - name: Build wheels (manylinux) - uses: pypa/cibuildwheel@v3.2.1 + uses: pypa/cibuildwheel@v3.3.0 env: CIBW_BEFORE_BUILD: "yum install -y flex bison libxml2-devel zlib-devel cairo-devel && pip install -U cmake pip setuptools wheel && python setup.py build_c_core" CIBW_BUILD: "*-manylinux_x86_64" - name: Build wheels (musllinux) - uses: pypa/cibuildwheel@v3.2.1 + uses: pypa/cibuildwheel@v3.3.0 env: CIBW_BEFORE_BUILD: "apk add flex bison libxml2-dev zlib-dev cairo-dev && pip install -U cmake pip setuptools wheel && python setup.py build_c_core" CIBW_BUILD: "*-musllinux_x86_64" @@ -49,7 +49,7 @@ jobs: fetch-depth: 0 - name: Build wheels (manylinux) - uses: pypa/cibuildwheel@v3.2.1 + uses: pypa/cibuildwheel@v3.3.0 env: CIBW_BEFORE_BUILD: "yum install -y flex bison libxml2-devel zlib-devel cairo-devel && pip install -U cmake pip setuptools wheel && python setup.py build_c_core" CIBW_ARCHS_LINUX: aarch64 @@ -70,7 +70,7 @@ jobs: fetch-depth: 0 - name: Build wheels (musllinux) - uses: pypa/cibuildwheel@v3.2.1 + uses: pypa/cibuildwheel@v3.3.0 env: CIBW_BEFORE_BUILD: "apk add flex bison libxml2-dev zlib-dev cairo-dev && pip install -U cmake pip setuptools wheel && python setup.py build_c_core" CIBW_ARCHS_LINUX: aarch64 @@ -133,7 +133,7 @@ jobs: cmake --install . - name: Build wheels - uses: pypa/cibuildwheel@v3.2.1 + uses: pypa/cibuildwheel@v3.3.0 env: CIBW_ARCHS_MACOS: "${{ matrix.wheel_arch }}" CIBW_BEFORE_BUILD: "pip install -U setuptools && python setup.py build_c_core" @@ -238,7 +238,7 @@ jobs: shell: cmd - name: Build wheels - uses: pypa/cibuildwheel@v3.2.1 + uses: pypa/cibuildwheel@v3.3.0 env: CIBW_BEFORE_BUILD: "pip install -U setuptools && python setup.py build_c_core" CIBW_BUILD: "*-${{ matrix.wheel_arch }}" From 863884c1b385111430ed32a789daa208c62484fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 13:04:31 +0000 Subject: [PATCH 05/10] build(deps): bump actions/cache from 4 to 5 Bumps [actions/cache](https://github.com/actions/cache) from 4 to 5. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/cache dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5e2ed8ba0..d91b9b17c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,14 +105,14 @@ jobs: - name: Cache installed C core id: cache-c-core - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: vendor/install key: C-core-cache-${{ runner.os }}-${{ matrix.cmake_arch }}-llvm${{ env.LLVM_VERSION }}-${{ hashFiles('.git/modules/**/HEAD') }} - name: Cache C core dependencies id: cache-c-deps - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: ~/local key: deps-cache-v2-${{ runner.os }}-${{ matrix.cmake_arch }}-llvm${{ env.LLVM_VERSION }} @@ -216,13 +216,13 @@ jobs: - name: Cache installed C core id: cache-c-core - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: vendor/install key: C-core-cache-${{ runner.os }}-${{ matrix.cmake_arch }}-${{ hashFiles('.git/modules/**/HEAD') }} - name: Cache VCPKG - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: C:/vcpkg/installed/ key: vcpkg-${{ runner.os }}-${{ matrix.vcpkg_arch }} @@ -268,7 +268,7 @@ jobs: - name: Cache installed C core id: cache-c-core - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: | vendor/install @@ -314,7 +314,7 @@ jobs: - name: Cache installed C core id: cache-c-core - uses: actions/cache@v4 + uses: actions/cache@v5 with: path: | vendor/build From 9938af92eb003608986d0fb389d4217e1f2bdcde Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Dec 2025 13:04:36 +0000 Subject: [PATCH 06/10] build(deps): bump actions/upload-artifact from 5 to 6 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 6. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5e2ed8ba0..460fbc27e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: CIBW_BUILD: "*-musllinux_x86_64" CIBW_TEST_COMMAND: "cd {project} && pip install --prefer-binary '.[test-musl]' && python -m pytest -v tests" - - uses: actions/upload-artifact@v5 + - uses: actions/upload-artifact@v6 with: name: wheels-linux-x86_64 path: ./wheelhouse/*.whl @@ -55,7 +55,7 @@ jobs: CIBW_ARCHS_LINUX: aarch64 CIBW_BUILD: "*-manylinux_aarch64" - - uses: actions/upload-artifact@v5 + - uses: actions/upload-artifact@v6 with: name: wheels-linux-aarch64-manylinux path: ./wheelhouse/*.whl @@ -77,7 +77,7 @@ jobs: CIBW_BUILD: "*-musllinux_aarch64" CIBW_TEST_COMMAND: "cd {project} && pip install --prefer-binary '.[test-musl]' && python -m pytest -v tests" - - uses: actions/upload-artifact@v5 + - uses: actions/upload-artifact@v6 with: name: wheels-linux-aarch64-musllinux path: ./wheelhouse/*.whl @@ -140,7 +140,7 @@ jobs: CIBW_ENVIRONMENT: "LDFLAGS=-L$HOME/local/lib" IGRAPH_CMAKE_EXTRA_ARGS: -DCMAKE_OSX_ARCHITECTURES=${{ matrix.cmake_arch }} ${{ matrix.cmake_extra_args }} -DCMAKE_PREFIX_PATH=$HOME/local - - uses: actions/upload-artifact@v5 + - uses: actions/upload-artifact@v6 with: name: wheels-macos-${{ matrix.wheel_arch }} path: ./wheelhouse/*.whl @@ -181,7 +181,7 @@ jobs: limit-access-to-actor: true wait-timeout-minutes: 5 - - uses: actions/upload-artifact@v5 + - uses: actions/upload-artifact@v6 with: name: wheels-wasm path: ./dist/*.whl @@ -252,7 +252,7 @@ jobs: IGRAPH_EXTRA_LIBRARIES: libxml2,lzma,zlib,iconv,charset,bcrypt IGRAPH_EXTRA_DYNAMIC_LIBRARIES: wsock32,ws2_32 - - uses: actions/upload-artifact@v5 + - uses: actions/upload-artifact@v6 with: name: wheels-win-${{ matrix.wheel_arch }} path: ./wheelhouse/*.whl @@ -294,7 +294,7 @@ jobs: pip install '.[test]' python -m pytest -v tests - - uses: actions/upload-artifact@v5 + - uses: actions/upload-artifact@v6 with: name: sdist path: dist/*.tar.gz From 8d1b8112d841db8c44529105e5ffaebbb52405ec Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Tue, 23 Dec 2025 12:14:43 +0100 Subject: [PATCH 07/10] fix: make `get_adjacency_sparse` compatible with scipy 1.13+ --- src/igraph/adjacency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igraph/adjacency.py b/src/igraph/adjacency.py index f941ec822..e4d2500e5 100644 --- a/src/igraph/adjacency.py +++ b/src/igraph/adjacency.py @@ -113,7 +113,7 @@ def _get_adjacency_sparse(self, attribute=None): weights = self.es[attribute] N = self.vcount() - mtx = sparse.csr_matrix((weights, list(zip(*edges))), shape=(N, N)) + mtx = sparse.csr_matrix((weights, tuple(zip(*edges))), shape=(N, N)) if not self.is_directed(): mtx = mtx + sparse.triu(mtx, 1).T + sparse.tril(mtx, -1).T From 0f5f673b8dae60ef3522a24835277d81b6dbe716 Mon Sep 17 00:00:00 2001 From: "Philipp A." Date: Tue, 23 Dec 2025 12:28:21 +0100 Subject: [PATCH 08/10] fix for empty graph --- src/igraph/adjacency.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/igraph/adjacency.py b/src/igraph/adjacency.py index e4d2500e5..3d42b0bb2 100644 --- a/src/igraph/adjacency.py +++ b/src/igraph/adjacency.py @@ -113,7 +113,8 @@ def _get_adjacency_sparse(self, attribute=None): weights = self.es[attribute] N = self.vcount() - mtx = sparse.csr_matrix((weights, tuple(zip(*edges))), shape=(N, N)) + r, c = zip(*edges) if edges else ([], []) + mtx = sparse.csr_matrix((weights, (r, c)), shape=(N, N)) if not self.is_directed(): mtx = mtx + sparse.triu(mtx, 1).T + sparse.tril(mtx, -1).T From 709b2c68e9efcccd672961ef04ef02e81ca64e19 Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Sat, 27 Dec 2025 00:02:30 +0100 Subject: [PATCH 09/10] chore: updated C core to 1.0.1 --- CHANGELOG.md | 8 ++++++++ vendor/source/igraph | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b0c3a2b7..f2424f4fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # igraph Python interface changelog +## 1.0.1 - 2025-12-26 + +### Changed + +- The C core of igraph was updated to version 1.0.1. + ## [1.0.0] - 2025-10-23 ### Added @@ -21,6 +27,8 @@ - Most layouts are now auto-aligned using `align_layout()`. +- Dropped support for PyPy 3.9 and PyPy 3.10 as they are now EOL. + ### Miscellaneous - Documentation improvements. diff --git a/vendor/source/igraph b/vendor/source/igraph index b9b573902..7b4ae766c 160000 --- a/vendor/source/igraph +++ b/vendor/source/igraph @@ -1 +1 @@ -Subproject commit b9b573902ccbe393a78252ab5e94c7876ed92597 +Subproject commit 7b4ae766cbdee6b2017aa5b76752457db2a2972f From de9bc400ee0b4f3cee11174703b82e93af612777 Mon Sep 17 00:00:00 2001 From: Fabio Zanini Date: Thu, 5 Mar 2026 09:29:20 +1100 Subject: [PATCH 10/10] Export to pytorch geometric (#875) --- setup.py | 4 ++++ src/igraph/__init__.py | 12 ++++++---- src/igraph/io/libraries.py | 45 +++++++++++++++++++++++++++++++++++++ tests/test_foreign.py | 46 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index c919d3507..9c5b7c7f9 100644 --- a/setup.py +++ b/setup.py @@ -1018,6 +1018,10 @@ def get_tag(self): "plotly>=5.3.0", "Pillow>=9; platform_python_implementation != 'PyPy'", ], + "test-pyg": [ + "torch>=2.0.0; platform_python_implementation != 'PyPy'", + "torch-geometric>=2.0.0; platform_python_implementation != 'PyPy'", + ], # Dependencies needed for testing on Windows ARM64; only those that are either # pure Python or have Windows ARM64 wheels as we don't want to compile wheels # in CI diff --git a/src/igraph/__init__.py b/src/igraph/__init__.py index 6a4e189b9..85ad1a47a 100644 --- a/src/igraph/__init__.py +++ b/src/igraph/__init__.py @@ -211,6 +211,7 @@ _export_graph_to_networkx, _construct_graph_from_graph_tool, _export_graph_to_graph_tool, + _export_graph_to_torch_geometric, ) from igraph.io.random import ( _construct_random_geometric_graph, @@ -463,6 +464,8 @@ def __init__(self, *args, **kwds): from_graph_tool = classmethod(_construct_graph_from_graph_tool) to_graph_tool = _export_graph_to_graph_tool + to_torch_geometric = _export_graph_to_torch_geometric + # Files Read_DIMACS = classmethod(_construct_graph_from_dimacs_file) write_dimacs = _write_graph_to_dimacs_file @@ -708,7 +711,9 @@ def es(self): ########################### # Paths/traversals - def get_all_simple_paths(self, v, to=None, minlen=0, maxlen=-1, mode="out", max_results=None): + def get_all_simple_paths( + self, v, to=None, minlen=0, maxlen=-1, mode="out", max_results=None + ): """Calculates all the simple paths from a given node to some other nodes (or all of them) in a graph. @@ -973,15 +978,14 @@ def Incidence(cls, *args, **kwds): def are_connected(self, *args, **kwds): """Deprecated alias to L{Graph.are_adjacent()}.""" deprecated( - "Graph.are_connected() is deprecated; use Graph.are_adjacent() " "instead" + "Graph.are_connected() is deprecated; use Graph.are_adjacent() instead" ) return self.are_adjacent(*args, **kwds) def get_incidence(self, *args, **kwds): """Deprecated alias to L{Graph.get_biadjacency()}.""" deprecated( - "Graph.get_incidence() is deprecated; use Graph.get_biadjacency() " - "instead" + "Graph.get_incidence() is deprecated; use Graph.get_biadjacency() instead" ) return self.get_biadjacency(*args, **kwds) diff --git a/src/igraph/io/libraries.py b/src/igraph/io/libraries.py index f35cc9545..9b06f41f1 100644 --- a/src/igraph/io/libraries.py +++ b/src/igraph/io/libraries.py @@ -270,3 +270,48 @@ def _construct_graph_from_graph_tool(cls, g): graph.add_edges(edges, eattr) return graph + + +def _export_graph_to_torch_geometric( + graph, vertex_attributes=None, edge_attributes=None +): + """Converts the graph to torch geometric + + Data types: graph-tool only accepts specific data types. See the + following web page for a list: + + https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.data.Data.html#torch_geometric.data.Data + + @param g: graph-tool Graph + @param vertex_attributes: dictionary of vertex attributes to transfer. + Keys are attributes from the vertices, values are data types (see + below). C{None} means no vertex attributes are transferred. + @param edge_attributes: dictionary of edge attributes to transfer. + Keys are attributes from the edges, values are data types (see + below). C{None} means no vertex attributes are transferred. + """ + import torch + from torch_geometric.data import Data + + if vertex_attributes is None: + vertex_attributes = graph.vertex_attributes() + if edge_attributes is None: + edge_attributes = graph.edge_attributes() + + # Edge index + edge_index = torch.tensor(graph.get_edgelist(), dtype=torch.long) + + # Node attributes + x = torch.tensor([graph.vs[attr] for attr in vertex_attributes]) + if x.ndim > 1: + x = x.permute(*torch.arange(x.ndim - 1, -1, -1)) + + # Edge attributes + edge_attr = torch.tensor([graph.es[attr] for attr in edge_attributes]) + if edge_attr.ndim > 1: + edge_attr = edge_attr.permute(*torch.arange(edge_attr.ndim - 1, -1, -1)) + + # Wrap into correct data structure + data = Data(x=x, edge_index=edge_index, edge_attr=edge_attr) + + return data diff --git a/tests/test_foreign.py b/tests/test_foreign.py index 83664e5f5..b9caf6b52 100644 --- a/tests/test_foreign.py +++ b/tests/test_foreign.py @@ -23,6 +23,14 @@ pd = None +try: + import torch + from torch_geometric.data import Data as PyGData +except ImportError: + torch = None + PyGData = None + + GRAPHML_EXAMPLE_FILE = """\