Package: openGraphMatching
openGraphMatchingA Python Graph/Subgraph Matching programming library. Based on openGraphMatching and the framework provided, you can develop and test different subgraph matching algorithms efficiently. What's more, since the codebase is Python-based, algorithms with neural networks can be integrated easily with traditional subgraph matching algorithms.UsagePrerequisitepytorch>=1.6, networkx, pytorch-geometric, deepsnap.A detailed environment configration can be found inenv.yml.TheBaseMatcheris the minium implementation of subgraph matching algorithm.Here is the demo code for running GraphQL algorithm:importopenGraphMatching.matcherasmatcher# Prepare query graph q and target graph G in advance. q and G are networkx instance.m=matcher.GQLMatcher(G)# Initialize the object with targer graph Gm.is_subgraph_match(q)# Run the check match processQuickstartClone this repository:git clone https://github.com/chang2000/openGraphMatchingInstall all prerequisitenetworkxpytorch-geometricdeepsnapIf you are using conda-like package manager, we provide the conda environment fileenv.ymlfor this package. You may refer to thislinkto install a conda environment by a environment file. In short, use this commandconda env create -f env.yml. Then a conda envrionment namedogmis created.pip install openGraphMatchingto install this package.Enter theexamplesfolder, then runpython exact_subgraph_match_validate.pyto run the validation demo of this package.InternalsEach matcher follows thefiltering->ordering->enumeratingdesign pattern. In the directorymatcherthere are three files:filters.py,orders.py,enumeraters.py, where each file contains the general algorithms.For example, in the graphQL matcher, the code pipeline is like:fromopenGraphMatchingimportBaseMatcherfromopenGraphMatchingimportfiltersasffromopenGraphMatchingimportordersasofromopenGraphMatchingimportenumeratersaseclassGQLMatcher(BaseMatcher):def__init__(self,G):super().__init__(G)deffiltering(self,q):prefilter=f.Filter(self.G)returnprefilter.gql_filtering(q)defordering(self,q,candidates):orderer=o.Order(self.G)returnorderer.gql_order(q,candidates)defenumerate(self,q,imd,order,i):enu=e.Enumerater(self.G)enu.normal_enum(q,imd,order,i)returnenu.res_getter()defis_subgraph_match(self,q):# Some verbose and statistics are skipped herecandidates=self.filtering(q)order=self.ordering(q,candidates)match_list=self.enumerate(q,candidates,order,1)returnmatch_listMiscValidate the correctness of algorithm.We use HPRD (9460 nodes, 34998 edges) to validate the correctness considering the time consuming and program performance.We provides 200 quries(dense, 16 nodes).A correctness checker is implemented inutils.py.Expected result of all the matching are provided inexpected.res. Refer to the datasetvalidatefor more information.The data format of the datasetsFor each.graphfile, the first line will always bet x ywherexandyare two int indicates the number of nodes and edgesVertex datav v_id v_label v_degreeEdge datae v_id v_idSide wordCannot handle yeast well even it has a smaller dataset size, since around 10% of nodes left for 3000 nodes.The observation above inspires us to combine the traditional subgraph matching methods and the neural methods together.