Skip to main content

distributed-sampling

Extensible distributed graph sampling library for Spark GraphFrames.

Install

This library is a pure Python package. It expects to run inside a Spark environment where pyspark is available, and the GraphFrames package is attached to the Spark session.

pip install distributed-sampling

GraphFrames is provided as a Spark package. Start Spark with GraphFrames attached, e.g.:

# Adjust versions to your Spark/Scala setup
pyspark \
  --packages graphframes:graphframes:0.8.3-spark3.5-s_2.12

Or in code when creating a SparkSession:

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()
)

Usage

from graphframes import GraphFrame
from distributed_sampling import sample_graph

# gf: a GraphFrame with columns id, src, dst
sampled = sample_graph(gf, method="random_node", fraction=0.1, seed=42)

API

  • sample_graph(graph: GraphFrame, method: str, **kwargs) -> GraphFrame — top-level API.
  • Samplers implement the interface GraphSampler with a sample method.

Built-in methods

  • random_node — random node sampling with induced subgraph.
  • random_edge — randomly sample edges and keep their endpoints.
  • snowball — BFS-style expansion from seeds up to a given depth.
  • random_walk — multiple random walks; induced subgraph of visited nodes.
  • forest_fire — burn a fraction of neighbors iteratively.
  • topk — keep top-K vertices by degree (in/out/total).

Additional methods:

  • bfs(seeds=None, num_seeds=1, depth=2) — breadth-first expansion.
  • uvsn(fraction=0.1|num_vertices, seed=None) — uniform vertex sampling with neighborhood.
  • nuvsn(fraction=0.1|num_vertices, seed=None) — non-uniform (degree-weighted) vertex sampling with neighborhood.
  • mhrw(walk_length=100, num_walks=10, start_nodes=None, seed=None) — Metropolis-Hastings random walk.
  • rwe(walk_length=100, num_walks=10, start_nodes=None, alpha=0.15, seed=None) — random walk with escaping/restarts.
  • mirw(walk_length=10, num_walks=100, seed=None) — multiple independent walkers.
  • mdrw(walk_length=10, num_walks=10, attr=None, seed=None) — multi-dimensional walk biased by vertex attribute.
  • dfs(seeds=None, num_seeds=1, max_steps=100) — approximate depth-first sampling.

Extending with your own sampler

  1. Implement a class that subclasses GraphSampler:
from distributed_sampling.samplers import GraphSampler

class MySampler(GraphSampler):
    name = "my_method"  # optional convenience

    def __init__(self, my_param: float = 0.5):
        self.my_param = my_param

    def sample(self, graph):
        # return a GraphFrame
        ...
  1. Expose it via entry points in your own package pyproject.toml:
[project.entry-points."distributed_sampling.samplers"]
my_method = "my_pkg.my_module:MySampler"

Your sampler will be discoverable by name "my_method" at runtime without code changes here.

Development

python -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
pytest

https://arxiv.org/pdf/1308.5865

Metadata

Release files for distributed-sampling 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for distributed-sampling 0.1.0
File Size Uploaded Provenance Actions
distributed_sampling-0.1.0.tar.gz 21.4 kB Without provenance Details for distributed_sampling-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for distributed-sampling 0.1.0
File Interpreter ABI Platform Actions
distributed_sampling-0.1.0-py3-none-any.whl Python 3 none any Details for distributed_sampling-0.1.0-py3-none-any.whl

Total release size: 51.3 kB

Release files / distributed_sampling-0.1.0.tar.gz

Download URL distributed_sampling-0.1.0.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5d0611f4319475314acb5baec24427c65d9273fc055a88430a4501f63a09bd9c
BLAKE2b-256 checksum
How to use checksums
d83bbe2f9f51064039726c200a03dd67f8efb545adcf8250d83d029b9a442fb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / distributed_sampling-0.1.0-py3-none-any.whl

Download URL distributed_sampling-0.1.0-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42a2ca46537dfca5c3d82ca554da481a3f90f56f6a5ad030f3c2c5f4a3658439
BLAKE2b-256 checksum
How to use checksums
e821f0bd687d33393e7205f83988b0ba1d90d7420b59d20cbf041b4809bf4a91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for distributed-sampling 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page