|
| 1 | +# Contribution Guidelines for Adding Tests |
| 2 | + |
| 3 | +### Contents |
| 4 | + |
| 5 | +- [Running the tests](#running-the-tests) |
| 6 | +- [Directory Layout](#directory-layout) |
| 7 | +- [Adding tests](#adding-tests) |
| 8 | +- [Available Graphs](#available-graphs) |
| 9 | + |
| 10 | +## Running the tests |
| 11 | + |
| 12 | +Execute the following to download the dependencies and run the tests. Make sure you're in a venv. |
| 13 | + |
| 14 | +```sh |
| 15 | +echo ' |
| 16 | +HOST_NAME="https://tg-hostname" |
| 17 | +USER_NAME=tigergraph |
| 18 | +PASS=tigergraph |
| 19 | +' >> test/.env |
| 20 | +pip install -r requirements.txt |
| 21 | +./run.sh |
| 22 | +``` |
| 23 | + |
| 24 | +`test/.env` |
| 25 | + |
| 26 | +- HOST_NAME: A TG environment that you have querywriter access to so setup.py can load data and queries to a subgraph named `graph_algorithms_testing` |
| 27 | +- USER_NAME: user |
| 28 | +- PASS: user's password |
| 29 | + |
| 30 | +`run.sh` does a few things: |
| 31 | + |
| 32 | +- runs `data/create_baseline.py` |
| 33 | + - this creates the baselines from the graphs listed in that file |
| 34 | +- runs the setup script to make sure the graph is created and data is loaded |
| 35 | +- runs the tests with pytest |
| 36 | + |
| 37 | +## Directory layout |
| 38 | + |
| 39 | +Data: stores the satic data for creating graphs, and algorithm baseline results. |
| 40 | + |
| 41 | +- CSV files under `data/[heterogeneous_edges, unweighted_edges, weighted_edges]` store the adjacency information for creating graphs. The baselines for algorithms are made from these graphs |
| 42 | + - For example `data/weighted_edges/line_edges.csv` stores the edges and weights to create a weighted, line graph. |
| 43 | +- JSON files under `data/baseline` store the baseline results for a given algorithm on a given graph type. |
| 44 | + - For example `data/baseline/centrality/pagerank/Line_Directed.json` stores the baseline results for pagerank on a directed line graph |
| 45 | + |
| 46 | +test: |
| 47 | + |
| 48 | +- setup.py: creates the graph, loads the data and installs the queries from pyTG's featurizer. Any new/custom queries need to be manually installed |
| 49 | +- test<algo_family>.py: houses the testing code for each family of algorithms |
| 50 | + |
| 51 | +``` |
| 52 | +├── data |
| 53 | +│ ├── baseline |
| 54 | +│ │ ├── <algo_family> |
| 55 | +│ │ │ └── <algo_name> |
| 56 | +│ │ │ └── <GraphType>.json |
| 57 | +│ ├── <edge_family> |
| 58 | +│ │ └── <graph_type>.csv |
| 59 | +│ └── create_baseline.py |
| 60 | +├── requirements.txt |
| 61 | +├── run.sh |
| 62 | +├── test |
| 63 | +│ ├── pyrightconfig.json |
| 64 | +│ ├── setup.py |
| 65 | +│ ├── test_centrality.py |
| 66 | +│ ├── test_community.py |
| 67 | +│ ├── test_path_finding.py |
| 68 | +│ ├── test_topological_link_prediction.py |
| 69 | +│ └── util.py |
| 70 | +``` |
| 71 | + |
| 72 | +## Adding tests |
| 73 | + |
| 74 | +Start with creating the baseline. Add a section to `create_baseline.py` that creates a baseline for all the necessary graph types for your algorithm. The output of the baseline should be written to |
| 75 | +the correct baseline path (see above [layout](#directory-layout)). |
| 76 | + |
| 77 | +If you're adding a new algorithm, add a test method for it to the algorithm family that it belongs to (i.e., community algorigthms go in community.py). The first test method in `test/test_centrality.py` |
| 78 | +is a good template to follow: |
| 79 | + |
| 80 | +```py |
| 81 | + # this function will run once for each of the graph names in the undirected_graphs list |
| 82 | + @pytest.mark.parametrize("test_name", undirected_graphs) |
| 83 | + def test_degree_centrality1(self, test_name): |
| 84 | + # query params |
| 85 | + params = { |
| 86 | + "v_type_set": ["V20"], |
| 87 | + "e_type_set": [test_name], |
| 88 | + "reverse_e_type_set": [test_name], |
| 89 | + "in_degree": True, |
| 90 | + "out_degree": False, |
| 91 | + "top_k": 100, |
| 92 | + "print_results": True, |
| 93 | + "result_attribute": "", |
| 94 | + "file_path": "", |
| 95 | + } |
| 96 | + with open(f"data/baseline/centrality/degree_centrality/{test_name}.json") as f: |
| 97 | + baseline = json.load(f) |
| 98 | + baseline = sorted(baseline[0]["top_scores"], key=lambda x: x["Vertex_ID"]) |
| 99 | + |
| 100 | + # call the the algorithm through the featurizer |
| 101 | + result = self.feat.runAlgorithm("tg_degree_cent", params=params) |
| 102 | + result = sorted(result[0]["top_scores"], key=lambda x: x["Vertex_ID"]) |
| 103 | + |
| 104 | + |
| 105 | + # check that the results agree with the baseline |
| 106 | + for b in baseline: |
| 107 | + for r in result: |
| 108 | + if r["Vertex_ID"] == b["Vertex_ID"] and r["score"] != pytest.approx( |
| 109 | + b["score"] |
| 110 | + ): |
| 111 | + pytest.fail(f'{r["score"]} != {b["score"]}') |
| 112 | +``` |
| 113 | + |
| 114 | +## Available Graphs |
| 115 | + |
| 116 | +Example usage: |
| 117 | + |
| 118 | +- If you want to run a query on a directed, weighted, line graph, use the V20 verts and Line_Directed_Weighted edges. |
| 119 | + |
| 120 | +| Graph | Type | Vertices | Edges | |
| 121 | +| --------------------------- | ------------------------------------------------------------ | -------- | -------------------------------- | |
| 122 | +| Null | | V0 | | |
| 123 | +| Single node | | V1 | | |
| 124 | +| Empty graph | Undirected | V20 | Empty | |
| 125 | +| | Directed | | Empty_Directed | |
| 126 | +| Line | Undirected, unweighted | V20 | Line | |
| 127 | +| | Directed, unweighted | | Line_Directed | |
| 128 | +| | Undirected, weighted | | Line_Weighted | |
| 129 | +| | Directed, weighted | | Line_Directed_Weighted | |
| 130 | +| | Heterogeneous vertex types, directed, weighted | V20, V8 | Line_Heterogeneous | |
| 131 | +| Ring | Undirected, unweighted | V20 | Ring | |
| 132 | +| | Directed, unweighted | | Ring_Directed | |
| 133 | +| | Undirected, weighted | | Ring_Weighted | |
| 134 | +| | Directed, weighted | | Ring_Directed_Weighted | |
| 135 | +| | Heterogeneous vertex types, directed, weighted | V20, V8 | Ring_Heterogeneous | |
| 136 | +| Hub & spoke | Undirected, unweighted | V20 | Hub_Spoke | |
| 137 | +| | Directed (towards the spokes), unweighted Hub_Spoke_Directed | | | |
| 138 | +| | Undirected, weighted Hub_Spoke_Weighted | | | |
| 139 | +| | Directed, weighted Hub_Spoke_Directed_Weighted | | | |
| 140 | +| | Heterogeneous vertex types, directed, weighted | V20, V8 | Hub_Spoke_Heterogeneous | |
| 141 | +| Hub-connected hub & spoke | Undirected, unweighted | V20 | Hub_Connected_Hub_Spoke | |
| 142 | +| | Undirected, weighted | | Hub_Connected_Hub_Spoke_Weighted | |
| 143 | +| Tree | Undirected, unweighted | V20 | Tree | |
| 144 | +| | Directed, unweighted | | Tree_Directed | |
| 145 | +| | Undirected, weighted | | Tree_Weighted | |
| 146 | +| | Directed, weighted | | Tree_Directed_Weighted | |
| 147 | +| | Heterogeneous vertex types, directed, weighted | V20, V8 | Tree_Heterogeneous | |
| 148 | +| Complete | Undirected, unweighted | V8 | Complete | |
| 149 | +| | Directed, unweighted | | Complete_Directed | |
| 150 | +| | Undirected, weighted | | Complete_Weighted | |
| 151 | +| | Directed, weighted | | Complete_Directed_Weighted | |
| 152 | +| | Heterogeneous vertex types, directed, weighted | V4, V8 | Complete_Heterogeneous | |
| 153 | +| DAG | Directed, unweighted | V20 | DAG_Directed | |
| 154 | +| | Directed, weighted | | DAG_Directed_Weighted | |
| 155 | +| | Heterogeneous vertex types, directed, weighted | V20, V8 | DAG_Heterogeneous | |
| 156 | +| Graph with negative cycles | Directed, weighted | V20 | Negative_cycles | |
| 157 | +| | Heterogeneous vertex types, directed, weighted | V20, V8 | Negative_Cycle_Heterogeneous | |
| 158 | +| Topological link prediction | Unweighted, undirected | V8 | topo_link1 | |
| 159 | +| | topo_link2 | | | |
| 160 | +| | topo_link3 | | | |
| 161 | +| | topo_link4 | | | |
| 162 | +| | topo_link5 | | | |
| 163 | +| | topo_link6 | | | |
| 164 | +| | Unweighted, directed | | topo_link_directed | |
| 165 | +| Same Community | no edges | V4 | | |
0 commit comments