Thanks to visit codestin.com
Credit goes to github.com

Skip to content

superleesa/gpatches

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gpatches

A tool to diff two graphs. This library helps you identify changes between two networkx graphs including added/removed nodes, changed node parameters, and added/removed edges.

Installation

pip install gpatches

Usage

import networkx as nx
from gpatches import diff_graphs

G1 = nx.DiGraph()
G1.add_node("A", x=1, y=2)
G1.add_node("B", foo="bar")
G1.add_edge("A", "B", weight=5)

G2 = nx.DiGraph()
G2.add_node("A", x=1, y=3, z=4)  # Changed y value and added z parameter
G2.add_node("C", color="blue")   # New node
G2.add_edge("A", "C", weight=2)  # New edge

# Diff the graphs
patches = diff_graphs(G1, G2)
print(patches)

The output from the above example would be:

GraphPatch(
    added_nodes={'C': {'color': 'blue'}},
    removed_nodes={'B': {'foo': 'bar'}},
    changed_nodes={
        'A': NodePatch(
            added_params={'z': 4},
            removed_params={},
            changed_params={'y': ParamPatch(old_param_value=2, new_param_value=3)}
        )
    },
    removed_edges={('A', 'B'): {'weight': 5}},
    added_edges={('A', 'C'): {'weight': 2}}
)

About

A tool to diff two graphs.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages