Skip to main content

VarGraph 🕸️📐

License: MIT Python 3.9+ Version

VarGraph is a Python library that merges Graph Theory with Symbolic Computation. Instead of being limited to pure numerical weights, VarGraph allows you to build mathematical nets where edges are algebraic expressions, equations, or variables.

Under the hood, it seamlessly integrates with SymPy to provide advanced algebraic operations over complex network topologies.

📦 Installation

VarGraph requires SymPy as its core dependency for all mathematical evaluations.

For regular users:

pip install vargraph

For developers (Local Setup) If you want to contribute or modify the source code, install it in editable mode with testing dependencies:

git clone [https://github.com/luis-valdivieso/vargraph.git](https://github.com/luis-valdivieso/vargraph.git)
cd vargraph
pip install -e .[dev]

🚀 Quickstart and core features

1. Initialization and Algebraic Edges

Create a graph and assign symbolic mathematical expressions as edge weights.

import sympy as sp
from vargraph import VarGraph

# Initialize a directed graph
g = VarGraph(directed=True)

# Add edges with symbolic weights
g.add_edge("A", "B", "x**2 + 2*y")
g.add_edge("B", "C", "3*x")
g.add_edge("A", "C", "z")

# Extract all free algebraic variables used in the graph
print(g.free_symbols) 
# Output: {x, y, z}

2. Symbolic Pathfinding

Find all simple paths between two nodes and get the simplified algebraic cost of the route.

paths = g.get_symbolic_paths("A", "C")
for route, cost in paths:
    print(f"Route: {route} | Cost: {cost}")

# Output:
# Route: ['A', 'C'] | Cost: z
# Route: ['A', 'B', 'C'] | Cost: x**2 + 3*x + 2*y

3. Adjacency Matrix Extraction

Export the graph topology as a mathematical SymPy Matrix for linear algebra operations.

matrix, nodes = g.get_adjacency_matrix(["A", "B", "C"])
print(matrix)

# Output: 
# Matrix([
# [0, x**2 + 2*y, 0],
# [0,          0, 3*x],
# [0,          0,   0]])

4. Numerical Evaluation

Instantiate the abstract mathematical model into a real-world numerical use case. It supports partial evaluations, safely keeping non-substituted variables as SymPy symbols.

# Evaluate substituting x=2 (partial evaluation, y and z remain)
num_graph = g.evaluate({"x": 2})

print(num_graph.get_weight("B", "C"))
# Output: 6.0

print(num_graph.get_weight("A", "B"))
# Output: 2.0*y + 4.0

📄 License

This project is licensed under the MIT License.

Metadata

Release files for vargraph 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 vargraph 0.1.0
File Size Uploaded
vargraph-0.1.0.tar.gz 6.6 kB Details

Built distribution (wheel)

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

Total release size: 12.0 kB

Release files / vargraph-0.1.0.tar.gz

Download URL vargraph-0.1.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2b4000f756a65b7d93c022d2d1899e20788fdf5b9e4b3ed62e84d4dfab92b9f3
BLAKE2b-256 checksum
How to use checksums
6db7a1eb3f686c3e61b7d9361df4a1427de2bfcd94dfc6c0a0c4c1390c7e3b65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

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

Download URL vargraph-0.1.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6181f85afed808814120f0051a9776b5dfb02760573cde57b12423df15026c49
BLAKE2b-256 checksum
How to use checksums
a06c4a2d7fec1c23f898de757cfb470ec334d53be38f074f7d8daab9b3de5d8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

1.0.0

2 release files

This release

0.1.0 This release

2 release files

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