Skip to main content

A library to sample temporal random walks from in-memory temporal graphs

Project description

🚀 Temporal Random Walk

Build Passing PyPI Latest Release PyPI Downloads

A high-performance temporal random walk sampler for dynamic networks with GPU acceleration. Built for scale.


🔥 Why Temporal Random Walk?

Performance First – GPU-accelerated sampling for massive networks
Memory Efficient – Smart memory management for large graphs
Flexible Integration – Easy Python bindings with NumPy/NetworkX support
Production Ready – Tested with hundreds of extensive unit tests.
Multi Platform Builds and runs seamlessly on devices with or without CUDA.


⚡ Quick Start

from temporal_random_walk import TemporalRandomWalk

# Create a directed temporal graph
walker = TemporalRandomWalk(is_directed=True, use_gpu=True, max_time_capacity=-1)

# Add edges - can be numpy arrays or python lists
sources = [3, 2, 0, 3, 3, 1]
targets = [4, 4, 2, 1, 2, 4]
timestamps = [71, 82, 19, 34, 79, 19]

walker.add_multiple_edges(sources, targets, timestamps)

# Sample walks with exponential time bias
walk_nodes, walk_timestamps, walk_lens, edge_features = walker.get_random_walks_and_times_for_all_nodes(
    max_walk_len=5,
    walk_bias="ExponentialIndex",
    num_walks_per_node=10,
    initial_edge_bias="Uniform"
)
# edge_features is None when no edge features were added (feature_dim=0)

✨ Key Features

  • GPU acceleration for large graphs
  • 🎯 Multiple sampling strategies – Uniform, Linear, Exponential
  • 🧠 Advanced temporal biases – ExponentialWeight (CTDNE-style) and TemporalNode2Vec
  • 🔄 Forward & backward temporal walks
  • 📡 Rolling window support for streaming data
  • 🏷️ Optional edge feature propagation from input edges to sampled walks
  • 🔗 NetworkX integration
  • 🛠️ Efficient memory management
  • ⚙️ Uses C++ std libraries or Thrust API selectively based on hardware availability and configuration.

🏷️ Edge Features (Optional)

If your edges carry attributes (weights, embeddings, types, etc.), you can pass them to add_multiple_edges(...) and receive aligned edge features for each sampled transition.

import numpy as np
from temporal_random_walk import TemporalRandomWalk

walker = TemporalRandomWalk(is_directed=True, use_gpu=False)

sources = np.array([0, 0, 1], dtype=np.int32)
targets = np.array([1, 2, 2], dtype=np.int32)
timestamps = np.array([10, 20, 30], dtype=np.int64)

# shape: [num_edges, feature_dim]
edge_features = np.array([
    [0.1, 1.0],
    [0.2, 0.5],
    [0.9, 0.3],
], dtype=np.float32)

walker.add_multiple_edges(sources, targets, timestamps, edge_features=edge_features)

walk_nodes, walk_timestamps, walk_lens, walk_edge_features = walker.get_random_walks_and_times(
    max_walk_len=4,
    walk_bias="Uniform",
    num_walks_total=5,
)

# walk_edge_features.shape == [num_walks, max_walk_len - 1, feature_dim]

walk_edge_features is None when no edge features are provided.

🏷️ Node Features

The library can also store dense node features. Use set_node_features(node_ids, node_features) to populate features for specific nodes, then get_node_features() to retrieve the dense matrix.


🧭 Bias Selection Notes

  • Use ExponentialIndex or Linear for recency-aware sampling with no extra setup.
  • Use ExponentialWeight when you want CTDNE-style weight computation (enable_weight_computation=True, optionally tune timescale_bound).
  • Use TemporalNode2Vec when you need return/in-out control via temporal_node2vec_p and temporal_node2vec_q.

📦 Dependencies

Dependency Purpose
pybind11 Python-C++ bindings
python3 Required for building the python interfaces
gtest Unit testing framework

💡 Tip: Use vcpkg to easily install and link the C++ dependencies.


📦 Installation

pip install temporal-random-walk

📖 Documentation

📌 C++ Documentation →
📌 Python Interface Documentation →


📚 Inspired By

Nguyen, Giang Hoang, et al.
"Continuous-Time Dynamic Network Embeddings."
Companion Proceedings of The Web Conference 2018.

👨‍🔬 Built by Packets Research Lab

🚀 Contributions welcome! Open a PR or issue if you have suggestions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

temporal_random_walk-1.6.8-cp311-cp311-manylinux_2_34_x86_64.whl (98.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

temporal_random_walk-1.6.8-cp310-cp310-manylinux_2_34_x86_64.whl (98.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

temporal_random_walk-1.6.8-cp39-cp39-manylinux_2_34_x86_64.whl (98.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

temporal_random_walk-1.6.8-cp38-cp38-manylinux_2_34_x86_64.whl (98.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

File details

Details for the file temporal_random_walk-1.6.8-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for temporal_random_walk-1.6.8-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 325b3be88a20b9c83faab936fd734757848ba987c411cb421fcf2ddc935483a4
MD5 78dfa461c8872f48210b1228840fdcaf
BLAKE2b-256 60d07a6a8f3065c4084f56245cf578ac94316f7a25dc6122e825e38d6ce52053

See more details on using hashes here.

File details

Details for the file temporal_random_walk-1.6.8-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for temporal_random_walk-1.6.8-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ea922419f7ecf41505d1e65b7df7c4a176f259701ca7320087a67966fee0232f
MD5 3b4a540d35f93c42be0fe3d11f31fff9
BLAKE2b-256 1805ed079e079ddff416456286d18c332c6a9fd9bc0bf3c06c4593471642d889

See more details on using hashes here.

File details

Details for the file temporal_random_walk-1.6.8-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for temporal_random_walk-1.6.8-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6851e35649cefae6a659666cee1e11ccff0c5956965c98ea02008c5c1378aa1e
MD5 c32bd9bd93360e8132a734325761b01c
BLAKE2b-256 e7f140f0610ab4b3ea3cb1153ade161a3fb88057bd52907670f6ad88a20425df

See more details on using hashes here.

File details

Details for the file temporal_random_walk-1.6.8-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for temporal_random_walk-1.6.8-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b47c19aa3e28ee456c494ed878b641614943f0f3fb212ab584ce3519050af121
MD5 d733228903b9d52696a8a369681c7ac9
BLAKE2b-256 c4a8c2fee97123af763c46a49f9d7f3a72647d8a124abc442d33cd43129608cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page