Functionality¶
- class pymetis.IntSequence¶
A
Sequenceof integers, or anything satisfying the Python buffer interface as a one-dimensional array of integers. To avoid unnecessary copying of data, make sure to usezero_copy_dtype().
- pymetis.PythonicGraph: TypeAlias = 'Sequence[IntSequence] | Mapping[int, IntSequence]'
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.
- class pymetis.PythonicGraph¶
See above.
- class pymetis.CSRAdjacency(adj_starts: IntSequence, adjacent: IntSequence)[source]¶
- adj_starts: IntSequence¶
Length must be number of vertices + 1.
- adjacent: IntSequence¶
Vertex i has adjacent vertices
adjacent[adj_starts[i]:adj_starts[i+1]].Added in version 2025.2.
- pymetis.nested_dissection(adjacency: CSRAdjacency | PythonicGraph | None = None, xadj: None = None, adjncy: None = None, vweights: IntSequence | None = None, options: Options | None = None) Sequence[int][source]¶
- pymetis.nested_dissection(adjacency: None = None, xadj: IntSequence | None = None, adjncy: IntSequence | None = None, vweights: IntSequence | None = None, options: Options | None = None) Sequence[int]
This function computes fill reducing orderings of sparse matrices using the multilevel nested dissection algorithm.
The input graph is given as either a Pythonic way as the adjacency parameter or in the direct C-like way that Metis likes as xadj and adjncy. It is an error to specify both graph inputs.
Changed in version 2025.2.2: Added vweights.
- pymetis.part_graph(nparts: int, adjacency: PythonicGraph | CSRAdjacency | None = None, xadj: None = None, adjncy: None = None, *, vweights: IntSequence | None = None, vsize: IntSequence | None = None, eweights: IntSequence | None = None, tpwgts: Sequence[float] | None = None, recursive: bool | None = None, contiguous: bool | None = None, options: Options | None = None, warn_on_copies: bool = False) GraphPartition[source]¶
- pymetis.part_graph(nparts: int, adjacency: None = None, xadj: IntSequence | None = None, adjncy: IntSequence | None = None, *, vweights: IntSequence | None = None, vsize: IntSequence | None = None, eweights: IntSequence | None = None, tpwgts: Sequence[float] | None = None, recursive: bool | None = None, contiguous: bool | None = None, options: Options | None = None, warn_on_copies: bool = False) GraphPartition
Return a partition (cutcount, part_vert) into nparts for an input graph.
The input graph is given in either a Pythonic way as the adjacency parameter or in the direct CSR-like way that Metis uses internally as xadj and adjncy. It is an error to specify both graph inputs.
The Pythonic graph specifier adjacency is required to have the following properties:
len(adjacency) needs to return the number of vertices
adjacency[i]needs to be an iterable of vertices adjacent to vertex i. Both directions of an undirected graph edge are required to be stored.
If you would like to use eweights (edge weights), you need to use the xadj/adjncy way of specifying graph connectivity. This works as follows:
The adjacency structure of the graph is stored as follows: The adjacency list of vertex i is stored in array adjncy starting at index
xadj[i]and ending at (but not including) indexxadj[i + 1]. That is, for each vertex i, its adjacency list is stored in consecutive locations in the array adjncy, and the array xadj is used to point to where it begins and where it ends.The weights of the edges (if any) are stored in an additional array called eweights. This array contains 2m elements (where m is the number of edges, taking into account the undirected nature of the graph), and the weight of edge
adjncy[j]is stored at locationeweights[j]. The edge-weights must be integers greater than zero. If all the edges of the graph have the same weight (i.e., the graph is unweighted), then the eweight can be set toNone.METIS runtime options can be specified by supplying an
Optionsobject in the input.tpwgtsis a list of sizenpartsthat specifies the desired weight for each partition. Its entries must sum to a value less than or equal to 1.(quoted with slight adaptations from the Metis docs)
- pymetis.part_mesh(n_parts: int, connectivity: Sequence[IntSequence], options: Options | None = None, tpwgts: Sequence[float] | None = None, gtype: Literal[GType.NODAL, GType.DUAL] | None = None, ncommon: int = 1) MeshPartition[source]¶
This function is used to partition a mesh into n_parts parts based on a graph partitioning where each vertex is a node in the graph. A mesh is a collection of non-overlapping elements which are identified by their vertices. An element can have a different number of vertices based on its topology, ie 3 -> triangular, 6 -> prism, 8 -> hexahedron.
The mesh connectivity is specified as a list of elements where each element is specified by a list of its vertex indices, eg
[ [0, 1, 5, 4], [1, 2, 6, 5], ... ]. The spatial points, which make up the element vertices, are needed for defining the mesh, but are not needed for partitioning.len(connectivity)should be the number of elements in mesh
METIS expects a connectivity which is flattened with a corresponding offset vector that points to the beginning and end of each element declaration. This connectivity format allows a mesh to be comprised of multiple element types, eg triangles and quads. The
part_meshmethod will deduce these vectors based on the connectivity supplied.METIS runtime options can be specified by supplying an
Optionsobject in the input.tpwgtsis a list of sizen_partsthat specifies the desired weight for each partition.gtypespecifies the partitioning is based on a nodal/dual graph of the mesh. It has to be one ofGType.NODALorGType.DUAL.ncommonis needed whengtype = GType.DUAL. It Specifies the number of common nodes that two elements must have in order to put an edge between them in the dual graph. For example, for tetrahedron meshes, ncommon should be 3, which creates an edge between two tets when they share a triangular face (i.e., 3 nodes).Returns a namedtuple of
(edge_cuts, element_part, vertex_part), whereedge_cutsis the number of cuts to the connectivity graph,element_partis an array of length n_elements, with entries identifying the element’s partition index, andvertex_partis an array of length n_vertices with entries identifying the vertex’s partition index.
- pymetis.zero_copy_dtype() np.dtype[np.integer][source]¶
Return the
np.dtypeneeded for zero-copy operation in METIS.Requires
numpy(unlike the rest of PyMETIS).
- class pymetis.Options(**kwargs: int)[source]¶
See the METIS manual for context.
- ncuts¶
- nseps¶
- numbering¶
- niter¶
- minconn¶
- no2hop¶
- seed¶
- contig¶
- compress¶
- ccorder¶
- pfactor¶
- ufactor¶
- class pymetis.MeshPartition(edge_cuts: int, element_part: Sequence[int], vertex_part: Sequence[int])[source]¶
A named tuple for describing the partitioning of a mesh.
- class pymetis.GraphPartition(edge_cuts: int, vertex_part: Sequence[int])[source]¶
A named tuple for describing the partitioning of a mesh.
- class pymetis.OptionKey¶
A wrapper for METIS option codes.
- PTYPE¶
- OBJTYPE¶
- CTYPE¶
- IPTYPE¶
- RTYPE¶
- DBGLVL¶
- NITER¶
- NCUTS¶
- SEED¶
- NO2HOP¶
- MINCONN¶
- CONTIG¶
- COMPRESS¶
- CCORDER¶
- PFACTOR¶
- NSEPS¶
- UFACTOR¶
- NUMBERING¶
- HELP¶
- TPWGTS¶
- NCOMMON¶
- NOOUTPUT¶
- BALANCE¶
- GTYPE¶
- UBVEC¶
- class pymetis.IPType¶
A wrapper for METIS initial partitioning scheme codes.
- GROW¶
- RANDOM¶
- EDGE¶
- NODE¶
- METISRB¶
- class pymetis.DebugLevel¶
A wrapper for METIS debug level codes.
- INFO¶
Shows various diagnostic message
- TIME¶
Perform timing analysis
- COARSEN¶
Show the coarsening progress
- REFINE¶
Show the refinement progress
- IPART¶
Show info on initial partitioning
- MOVEINFO¶
Show info on vertex moves during refinement
- SEPINFO¶
Show info in vertex moves during se refinement
- CONNINFO¶
Show info on minimization of subdomain connectivity
- CONTIGINFO¶
Show info on elimination of connected components
- MEMORY¶
Show info related to wspace allocation
References¶
- class np.integer¶
See
numpy.integer.
- class np.dtype¶
See
numpy.dtype.