This assigns nodes to different partitions with Metis partitioning algorithm. When performing Metis partitioning, we can put some constraint on the partitioning. Current, it supports two constrants to balance the partitioning. By default, Metis always tries to balance the number of node
(
g, k, balance_ntypes=None, balance_edges=False, mode="k-way", objtype="cut"
)
| 276 | |
| 277 | |
| 278 | def metis_partition_assignment( |
| 279 | g, k, balance_ntypes=None, balance_edges=False, mode="k-way", objtype="cut" |
| 280 | ): |
| 281 | """This assigns nodes to different partitions with Metis partitioning algorithm. |
| 282 | |
| 283 | When performing Metis partitioning, we can put some constraint on the partitioning. |
| 284 | Current, it supports two constrants to balance the partitioning. By default, Metis |
| 285 | always tries to balance the number of nodes in each partition. |
| 286 | |
| 287 | * `balance_ntypes` balances the number of nodes of different types in each partition. |
| 288 | * `balance_edges` balances the number of edges in each partition. |
| 289 | |
| 290 | To balance the node types, a user needs to pass a vector of N elements to indicate |
| 291 | the type of each node. N is the number of nodes in the input graph. |
| 292 | |
| 293 | After the partition assignment, we construct partitions. |
| 294 | |
| 295 | Parameters |
| 296 | ---------- |
| 297 | g : DGLGraph |
| 298 | The graph to be partitioned |
| 299 | k : int |
| 300 | The number of partitions. |
| 301 | balance_ntypes : tensor |
| 302 | Node type of each node |
| 303 | balance_edges : bool |
| 304 | Indicate whether to balance the edges. |
| 305 | mode : str, "k-way" or "recursive" |
| 306 | Whether use multilevel recursive bisection or multilevel k-way paritioning. |
| 307 | objtype : str, "cut" or "vol" |
| 308 | Set the objective as edge-cut minimization or communication volume minimization. This |
| 309 | argument is used by the Metis algorithm. |
| 310 | |
| 311 | Returns |
| 312 | ------- |
| 313 | a 1-D tensor |
| 314 | A vector with each element that indicates the partition ID of a vertex. |
| 315 | """ |
| 316 | assert mode in ( |
| 317 | "k-way", |
| 318 | "recursive", |
| 319 | ), "'mode' can only be 'k-way' or 'recursive'" |
| 320 | assert ( |
| 321 | g.idtype == F.int64 |
| 322 | ), "IdType of graph is required to be int64 for now." |
| 323 | # METIS works only on symmetric graphs. |
| 324 | # The METIS runs on the symmetric graph to generate the node assignment to partitions. |
| 325 | start = time.time() |
| 326 | sym_gidx = _CAPI_DGLMakeSymmetric_Hetero(g._graph) |
| 327 | sym_g = DGLGraph(gidx=sym_gidx) |
| 328 | print( |
| 329 | "Convert a graph into a bidirected graph: {:.3f} seconds, peak memory: {:.3f} GB".format( |
| 330 | time.time() - start, get_peak_mem() |
| 331 | ) |
| 332 | ) |
| 333 | vwgt = [] |
| 334 | # To balance the node types in each partition, we can take advantage of the vertex weights |
| 335 | # in Metis. When vertex weights are provided, Metis will tries to generate partitions with |
no test coverage detected