-
Notifications
You must be signed in to change notification settings - Fork 5
feat(networks): expose networkx helpers and plotting #233
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
nicola-bastianello
merged 21 commits into
team-decent:main
from
adrianardv:feat/networkx-extras
Dec 29, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
1380951
feat(networks): add network base and federated support
9a669db
wip(fl-setup): save network changes after merge (Array)
96a89e6
fix(networks): resolve lint and doc warning
8c22e64
merge(fl-setup): sync with main and verify suite
e6fce23
enh(networks): address review feedback (#229)
9b968d9
merge(fl-setup): sync with main and verify suite
6973a75
ref(networks): align APIs with PR feedback (#229)
38075db
enh(networks): address review feedback (#229)
0b2acca
ref(networks): Enforce connectivity checks in send/receive (#229)
2e59602
enh(networks): Alias neighbors to base connected_agents (#229)
3ff5876
feat(networks): expose networkx helpers and plotting
8efe189
enh(networks): Detail connection validation errors (#229)
e9880e2
fix(networks): align plotting typing and docs config
cff0081
merge(network): merge remote-tracking branch 'origin/feat/fl-setup' i…
d342f32
merge(network): Merge latest 'main' into feat/networkx-extras and run…
d581924
docs(user): Document network plot kwargs and layouts
e5dcad2
wip(networkx-extras): Address PR review feedback
778dea6
ref(networks): move plotting to util and update docs (#233)
2547010
Merge remote-tracking branch 'origin/main' into feat/networkx-extras
da53861
ref(networks): Simplify FedNetwork API and relocate utils (#233)
8875b51
docs(user-guide): tidy network utilities section (#233)
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Mapping | ||
| from typing import Any, Literal | ||
|
|
||
| import matplotlib.axes | ||
| import networkx | ||
| import networkx as nx | ||
|
|
||
| _LAYOUT_FUNCS: dict[Literal["spring", "kamada_kawai", "circular", "random", "shell"], Any] = { | ||
| "spring": nx.drawing.layout.spring_layout, | ||
| "kamada_kawai": nx.drawing.layout.kamada_kawai_layout, | ||
| "circular": nx.drawing.layout.circular_layout, | ||
| "random": nx.drawing.layout.random_layout, | ||
| "shell": nx.drawing.layout.shell_layout, | ||
| } | ||
|
|
||
|
|
||
| def plot_network( | ||
| graph: networkx.Graph[Any], | ||
| *, | ||
| ax: matplotlib.axes.Axes | None = None, | ||
| layout: Literal["spring", "kamada_kawai", "circular", "random", "shell"] = "spring", | ||
| **draw_kwargs: Mapping[str, object], | ||
| ) -> matplotlib.axes.Axes: | ||
| """ | ||
| Plot a NetworkX graph using the built-in NetworkX drawing utilities. | ||
|
|
||
| Args: | ||
| graph: NetworkX graph to plot. | ||
| ax: optional :class:`matplotlib.axes.Axes` to draw on. If ``None`` a new figure is created. | ||
| layout: layout algorithm to position nodes (e.g. :func:`networkx.drawing.layout.spring_layout`, | ||
| :func:`networkx.drawing.layout.kamada_kawai_layout`, | ||
| :func:`networkx.drawing.layout.circular_layout`, | ||
| :func:`networkx.drawing.layout.random_layout`, | ||
| :func:`networkx.drawing.layout.shell_layout`). | ||
| draw_kwargs: forwarded to :func:`networkx.drawing.nx_pylab.draw_networkx`. | ||
|
|
||
| Returns: | ||
| The matplotlib :class:`matplotlib.axes.Axes` containing the plot. | ||
|
|
||
| Raises: | ||
| RuntimeError: if matplotlib is not available. | ||
| ValueError: if an unsupported layout is requested. | ||
|
|
||
| """ | ||
| try: | ||
| import matplotlib.pyplot as plt # noqa: PLC0415 | ||
| except Exception as exc: # pragma: no cover - runtime dependency guard | ||
| raise RuntimeError("matplotlib is required for plotting the network") from exc | ||
|
|
||
| layout_func = _LAYOUT_FUNCS.get(layout) | ||
| if layout_func is None: | ||
| supported = ", ".join(sorted(_LAYOUT_FUNCS)) | ||
| raise ValueError(f"Unsupported layout '{layout}'. Supported layouts: {supported}") | ||
|
|
||
| pos = layout_func(graph) | ||
| if ax is None: | ||
| _, ax = plt.subplots() | ||
|
|
||
| draw_kwargs_dict: dict[str, Any] = dict(draw_kwargs) | ||
| nx.drawing.nx_pylab.draw_networkx( | ||
| graph, | ||
| pos=pos, | ||
| ax=ax, | ||
| **draw_kwargs_dict, | ||
| ) | ||
| return ax |
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,7 @@ | ||
| decent_bench.utils.network_utils | ||
| ================================ | ||
|
|
||
| .. automodule:: decent_bench.utils.network_utils | ||
| :members: | ||
| :show-inheritance: | ||
| :undoc-members: |
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
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.