Apache Spark Edition
Distributed graph sampling, one function call away.
Graph sampling methods built natively on Apache Spark GraphFrames. Select existing strategies or plug in your own without touching the core.
pip install graph-distributed-samplingQuick start
Attach GraphFrames, then sample.
The library runs inside any Spark environment where pyspark is available and the GraphFrames package is attached to the session.
from pyspark.sql import SparkSession spark = ( SparkSession.builder .appName("sampling") .config("spark.jars.packages", "graphframes:graphframes:0.8.3-spark3.5-s_2.12") .getOrCreate())from graphframes import GraphFramefrom distributed_sampling import sample_graph # gf: a GraphFrame with columns id, src, dstsampled = sample_graph(gf, "random_node", fraction=0.1, seed=42) # Switching strategy is a one-string changesampled = sample_graph(gf, "nuvsn", fraction=0.1, seed=42)sampled = sample_graph(gf, "forest_fire", p=0.35, max_nodes=50_000)Distributed by default
Samplers are pure DataFrame transformations — joins, aggregations, anti-joins. The graph is never collected to the driver.
One uniform interface
Every sampler consumes and returns a GraphFrame and shares induced-subgraph construction, so methods are interchangeable.
Lightweight packaging
Pure Python with no hard Spark dependency: your cluster provides pyspark and GraphFrames, avoiding version conflicts.
14 samplers · 4 families
Pick a strategy. Keep the interface.
Every method sits behind the same sample_graph call — switch strategies by changing a single string.
Random node
NodeUniform vertex sample with its induced subgraph.
Uniform vertex + neighborhood
NodeUniform seed vertices augmented with their one-hop neighborhood.
Degree-weighted vertex + neighborhood
NodeGumbel-top-k degree-weighted seeds plus neighborhoods, computed without the driver.
Random edge
EdgeUniform edge sample; endpoints of retained edges are kept.
Top-K by degree
EdgeKeeps the K vertices with the highest in, out, or total degree.
Snowball
TraversalLayer-by-layer frontier expansion from seeds, stopping early when nothing new appears.
Breadth-first
TraversalBreadth-first expansion using bidirectional frontier joins and anti-joins.
Depth-first (approx.)
TraversalGreedy per-frontier choice of one unvisited successor per step.
Forest fire
TraversalEach active vertex burns a random subset of its outgoing neighbors with probability p.
Random walk
WalkThousands of unbiased walkers advanced in parallel within one set of transformations.
Multiple independent walkers
WalkDead-end walkers respawn from fresh random vertices to sustain coverage.
Metropolis–Hastings walk
WalkAccepts moves with min(1, deg(u)/deg(v)) to correct degree bias.
Random walk with escaping
WalkRestarts with probability α to escape dense regions and improve coverage.
Multidimensional walk
WalkSuccessor choice biased by a vertex attribute for property-aware exploration.
Evaluation
Built for the graphs that don't fit in memory.
Evaluated on seven SNAP graphs spanning four orders of magnitude in edge count, from ca-GrQc to the 68.9M-edge soc-LiveJournal1. Scaling runs use an Amazon EMR cluster with four m5.2xlarge workers.
Faster than Gradoop on Apache Flink
Matched parallelism, three samplers both systems implement. Faster on every graph; the margin narrows with scale.
Scaling from 1 to 8 executors
web-Google on Amazon EMR. Runtime falls monotonically; compute-bound walks scale best.
- random_walk3.8×
- mhrw2.4×
- uvsn2.0×
Plugin architecture
Bring your own sampler.
The built-in samplers are registered through exactly the same mechanism, so first- and third-party methods are treated identically — no modification or recompilation of the core.
- 1Subclass GraphSampler; configuration goes in the constructor.
- 2Implement sample(graph) and return a GraphFrame.
- 3Declare an entry point in your package — the registry discovers it on first use.
from distributed_sampling.samplers \ import GraphSampler class NewSampler(GraphSampler): name = "new_method" def __init__(self, new_param=0.5): self.new_param = new_param def sample(self, graph): ... # return a GraphFrame[project.entry-points."distributed_sampling.samplers"]new_method = "new_pkg.new_module:NewSampler"sample_graph(gf, "new_method", new_param=0.8)