synthetic-graph-benchmarks 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ import os
2
+ import requests
3
+
4
+ def download_file(url: str, folder: str) -> str:
5
+ """
6
+ Download a file from the given URL and save it to the specified folder.
7
+
8
+ Args:
9
+ url (str): The URL of the file to download.
10
+ folder (str): The folder where the file will be saved.
11
+
12
+ Returns:
13
+ str: The path to the downloaded file.
14
+ """
15
+ os.makedirs(folder, exist_ok=True)
16
+ filename = url.split("/")[-1]
17
+ filepath = f"{folder}/{filename}"
18
+ if os.path.exists(filepath):
19
+ print(f"File {filename} already exists in {folder}. Skipping download.")
20
+ return filepath
21
+ response = requests.get(url)
22
+ response.raise_for_status() # Raise an error for bad responses
23
+
24
+ with open(filepath, "wb") as file:
25
+ file.write(response.content)
26
+
27
+ return filepath
28
+
29
+
30
+ def available_cpu_count():
31
+ # 1. Slurm-aware (allocated CPUs)
32
+ slurm_cpus = os.environ.get("SLURM_CPUS_ON_NODE") or os.environ.get(
33
+ "SLURM_CPUS_PER_TASK"
34
+ )
35
+ if slurm_cpus:
36
+ return int(slurm_cpus)
37
+
38
+ # 2. Respect CPU affinity if psutil is available
39
+ try:
40
+ process = psutil.Process()
41
+ if hasattr(process, "cpu_affinity"):
42
+ # psutil.cpu_count() returns the number of logical CPUs
43
+ # cpu_affinity() returns the CPUs that the process is allowed to run on
44
+ # We return the length of the CPU affinity list
45
+ affinity = process.cpu_affinity()
46
+ if affinity:
47
+ return len(affinity)
48
+ except Exception:
49
+ pass
50
+
51
+ # 3. Try Python 3.9+'s os.sched_getaffinity (Linux only)
52
+ if hasattr(os, "sched_getaffinity"):
53
+ return len(os.sched_getaffinity(0))
54
+
55
+ # 4. Fall back to all visible CPUs (may overcount on clusters)
56
+ return os.cpu_count() or 1 # fallback to 1 if os.cpu_count() returns None
@@ -0,0 +1,227 @@
1
+ Metadata-Version: 2.4
2
+ Name: synthetic-graph-benchmarks
3
+ Version: 0.1.0
4
+ Summary: Standardized benchmarks for evaluating synthetic graph generation methods
5
+ Project-URL: Homepage, https://github.com/peteole/synthetic_graph_benchmarks
6
+ Project-URL: Repository, https://github.com/peteole/synthetic_graph_benchmarks
7
+ Project-URL: Documentation, https://github.com/peteole/synthetic_graph_benchmarks#readme
8
+ Project-URL: Bug Tracker, https://github.com/peteole/synthetic_graph_benchmarks/issues
9
+ Author-email: Ole Petersen <peteole2707@gmail.com>
10
+ Maintainer-email: Ole Petersen <peteole2707@gmail.com>
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Keywords: benchmarks,evaluation-metrics,graph-generation,graph-neural-networks,machine-learning,networkx,synthetic-graphs
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: networkx>=3.4.2
28
+ Requires-Dist: numpy>=2.2.6
29
+ Requires-Dist: orca-graphlets>=0.1.4
30
+ Requires-Dist: pygsp>=0.5.1
31
+ Requires-Dist: requests>=2.32.4
32
+ Requires-Dist: scikit-learn>=1.7.1
33
+ Requires-Dist: scipy>=1.15.3
34
+ Requires-Dist: torch>=2.3.0
35
+ Description-Content-Type: text/markdown
36
+
37
+ # Synthetic Graph Benchmarks
38
+
39
+ [![PyPI version](https://badge.fury.io/py/synthetic-graph-benchmarks.svg)](https://badge.fury.io/py/synthetic-graph-benchmarks)
40
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
42
+
43
+ A Python package implementing standardized benchmarks for evaluating synthetic graph generation methods, based on the evaluation frameworks introduced in:
44
+
45
+ - [**SPECTRE: Spectral Conditioning Helps to Overcome the Expressivity Limits of One-shot Graph Generators**](https://arxiv.org/pdf/2204.01613) (ICML 2022)
46
+ - [**Efficient and Scalable Graph Generation through Iterative Local Expansion**](https://arxiv.org/html/2312.11529v4) (2023)
47
+
48
+ This package provides a unified interface for benchmarking graph generation algorithms against established datasets and metrics used in the graph generation literature.
49
+
50
+ ## Features
51
+
52
+ - **Standardized Datasets**: Access to benchmark datasets including Stochastic Block Model (SBM), Planar graphs, and Tree graphs
53
+ - **Comprehensive Metrics**: Implementation of key evaluation metrics including:
54
+ - Degree distribution comparison (MMD)
55
+ - Clustering coefficient analysis
56
+ - Orbit count statistics (using ORCA)
57
+ - Spectral properties analysis
58
+ - Wavelet coefficient comparison
59
+ - **Validation Metrics**: Graph-type specific validation (planarity, tree properties, SBM likelihood)
60
+ - **Reproducible Evaluation**: Consistent benchmarking across different graph generation methods
61
+ - **Easy Integration**: Simple API for evaluating your own graph generation algorithms
62
+
63
+ ## Installation
64
+
65
+ ### From PyPI (recommended)
66
+
67
+ ```bash
68
+ pip install synthetic-graph-benchmarks
69
+ ```
70
+
71
+ ### From Source
72
+
73
+ ```bash
74
+ git clone https://github.com/peteole/synthetic_graph_benchmarks.git
75
+ cd synthetic_graph_benchmarks
76
+ pip install -e .
77
+ ```
78
+
79
+ ## Quick Start
80
+
81
+ ```python
82
+ import networkx as nx
83
+ from synthetic_graph_benchmarks import (
84
+ benchmark_planar_results,
85
+ benchmark_sbm_results,
86
+ benchmark_tree_results
87
+ )
88
+
89
+ # Generate some example graphs (replace with your graph generation method)
90
+ generated_graphs = [nx.erdos_renyi_graph(64, 0.1) for _ in range(20)]
91
+
92
+ # Benchmark against planar graph dataset
93
+ results = benchmark_planar_results(generated_graphs)
94
+ print(f"Planar accuracy: {results['planar_acc']:.3f}")
95
+ print(f"Average metric ratio: {results['average_ratio']:.3f}")
96
+
97
+ # Benchmark against SBM dataset
98
+ sbm_results = benchmark_sbm_results(generated_graphs)
99
+ print(f"SBM accuracy: {sbm_results['sbm_acc']:.3f}")
100
+
101
+ # Benchmark against tree dataset
102
+ tree_results = benchmark_tree_results(generated_graphs)
103
+ print(f"Tree accuracy: {tree_results['planar_acc']:.3f}")
104
+ ```
105
+
106
+ ## Datasets
107
+
108
+ The package provides access to three standard benchmark datasets:
109
+
110
+ ### Stochastic Block Model (SBM)
111
+ - **Size**: 200 graphs
112
+ - **Properties**: 2-5 communities, 20-40 nodes per community
113
+ - **Edge probabilities**: 0.3 intra-community, 0.05 inter-community
114
+
115
+ ### Planar Graphs
116
+ - **Size**: 200 graphs with 64 nodes each
117
+ - **Generation**: Delaunay triangulation on random points in unit square
118
+ - **Properties**: Guaranteed planarity
119
+
120
+ ### Tree Graphs
121
+ - **Size**: 200 graphs with 64 nodes each
122
+ - **Properties**: Connected acyclic graphs (trees)
123
+
124
+ ## Evaluation Metrics
125
+
126
+ ### Graph Statistics
127
+ - **Degree Distribution**: Maximum Mean Discrepancy (MMD) between degree histograms
128
+ - **Clustering Coefficient**: Local clustering coefficient comparison
129
+ - **Orbit Counts**: 4-node orbit statistics using ORCA package
130
+ - **Spectral Properties**: Laplacian eigenvalue distribution analysis
131
+ - **Wavelet Coefficients**: Graph wavelet signature comparison
132
+
133
+ ### Validity Metrics
134
+ - **Planar Accuracy**: Fraction of generated graphs that are planar
135
+ - **Tree Accuracy**: Fraction of generated graphs that are trees (acyclic)
136
+ - **SBM Accuracy**: Likelihood of graphs under fitted SBM parameters
137
+
138
+ ### Quality Scores
139
+ - **Uniqueness**: Fraction of non-isomorphic graphs in generated set
140
+ - **Novelty**: Fraction of generated graphs not isomorphic to training graphs
141
+ - **Validity-Uniqueness-Novelty (VUN)**: Combined score for overall quality
142
+
143
+ ## Advanced Usage
144
+
145
+ ### Custom Evaluation
146
+
147
+ ```python
148
+ from synthetic_graph_benchmarks.dataset import Dataset
149
+ from synthetic_graph_benchmarks.spectre_utils import PlanarSamplingMetrics
150
+
151
+ # Load dataset manually
152
+ dataset = Dataset.load_planar()
153
+ print(f"Training graphs: {len(dataset.train_graphs)}")
154
+ print(f"Validation graphs: {len(dataset.val_graphs)}")
155
+
156
+ # Use metrics directly
157
+ metrics = PlanarSamplingMetrics(dataset)
158
+ test_metrics = metrics.forward(dataset.train_graphs, test=True)
159
+ results = metrics.forward(generated_graphs, ref_metrics={"test": test_metrics}, test=True)
160
+ ```
161
+
162
+ ### Accessing Individual Metrics
163
+
164
+ ```python
165
+ # Get detailed breakdown of all metrics
166
+ results = benchmark_planar_results(generated_graphs)
167
+
168
+ # Individual metric values
169
+ print(f"Degree MMD: {results['degree']:.6f}")
170
+ print(f"Clustering MMD: {results['clustering']:.6f}")
171
+ print(f"Orbit MMD: {results['orbit']:.6f}")
172
+ print(f"Spectral MMD: {results['spectre']:.6f}")
173
+ print(f"Wavelet MMD: {results['wavelet']:.6f}")
174
+
175
+ # Ratios compared to training set
176
+ print(f"Degree ratio: {results['degree_ratio']:.3f}")
177
+ print(f"Average ratio: {results['average_ratio']:.3f}")
178
+ ```
179
+
180
+ ## Citing
181
+
182
+ If you use this package in your research, please cite the original papers:
183
+
184
+ ```bibtex
185
+ @inproceedings{martinkus2022spectre,
186
+ title={SPECTRE: Spectral Conditioning Helps to Overcome the Expressivity Limits of One-shot Graph Generators},
187
+ author={Martinkus, Karolis and Loukas, Andreas and Perraudin, Nathanaël and Wattenhofer, Roger},
188
+ booktitle={International Conference on Machine Learning},
189
+ pages={15159--15202},
190
+ year={2022},
191
+ organization={PMLR}
192
+ }
193
+
194
+ @article{bergmeister2023efficient,
195
+ title={Efficient and Scalable Graph Generation through Iterative Local Expansion},
196
+ author={Bergmeister, Andreas and Martinkus, Karolis and Perraudin, Nathanaël and Wattenhofer, Roger},
197
+ journal={arXiv preprint arXiv:2312.11529},
198
+ year={2023}
199
+ }
200
+ ```
201
+
202
+ ## Dependencies
203
+
204
+ - Python ≥ 3.10
205
+ - NetworkX ≥ 3.4.2
206
+ - NumPy ≥ 2.2.6
207
+ - SciPy ≥ 1.15.3
208
+ - PyGSP ≥ 0.5.1
209
+ - scikit-learn ≥ 1.7.1
210
+ - ORCA-graphlets ≥ 0.1.4
211
+ - PyTorch ≥ 2.3.0
212
+
213
+ ## Contributing
214
+
215
+ Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
216
+
217
+ ## License
218
+
219
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
220
+
221
+ ## Acknowledgments
222
+
223
+ This package is based on evaluation frameworks developed by:
224
+ - Karolis Martinkus (SPECTRE paper)
225
+ - Andreas Bergmeister (Iterative Local Expansion paper)
226
+ - The original GRAN evaluation codebase
227
+ - NetworkX and PyGSP communities
@@ -0,0 +1,11 @@
1
+ synthetic_graph_benchmarks/__init__.py,sha256=pMEdpnJXD8laVjCG4zd8d555chyqXv3-2WGxnrKFAQg,660
2
+ synthetic_graph_benchmarks/benchmarks.py,sha256=jWDaVrAwe4uYaKl1EnUIVqavDz5ZeuxcSOcHyMwUPBc,2707
3
+ synthetic_graph_benchmarks/dataset.py,sha256=Yca2fNPvRu7cOFyjjixkyqttboC07iPDgUXZWvvweN0,1515
4
+ synthetic_graph_benchmarks/dist_helper.py,sha256=rwtpP_IaIe8DcS5OvrSkYdF8xl7VBHaGoM3jv_Yeeos,7001
5
+ synthetic_graph_benchmarks/spectre_utils.py,sha256=CuOQdTlznar9_FIM66qoYk5zg1OEfa4M8be4WwHsFKA,41734
6
+ synthetic_graph_benchmarks/utils.py,sha256=Y5QTRmGjr79p1Y6h54c6k9kXz-jDveoj0ZjpAMKml50,1835
7
+ synthetic_graph_benchmarks-0.1.0.dist-info/METADATA,sha256=7zz-Yd3WXLVNjax5UPbkmPWO0n2uMRTD9w531tuqc3I,8484
8
+ synthetic_graph_benchmarks-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ synthetic_graph_benchmarks-0.1.0.dist-info/entry_points.txt,sha256=KvCdlYfIhAw2srO-7H9XG0jTaAIENxGXprw0B4aClco,79
10
+ synthetic_graph_benchmarks-0.1.0.dist-info/licenses/LICENSE,sha256=VDqzZZ7UjLMPLrsbgpHsMCW-H4msljYwm9z61rQSIsc,1069
11
+ synthetic_graph_benchmarks-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ synthetic-graph-benchmarks = synthetic_graph_benchmarks:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ole Petersen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.