code: def _community_multilevel(
      graph, weights=None, return_levels=False, resolution=1
  ):
      """Community structure based on the multilevel algorithm of
      Blondel et al.
  
      This is a bottom-up algorithm: initially every vertex belongs to a
      separate community, and vertices are moved between communities
      iteratively in a way that maximizes the vertices' local contribution
      to the overall modularity score. When a consensus is reached (i.e. no
      single move would increase the modularity score), every community in
      the original graph is shrank to a single vertex (while keeping the
      total weight of the incident edges) and the process continues on the
      next level. The algorithm stops when it is not possible to increase
      the modularity any more after shrinking the communities to vertices.
  
      This algorithm is said to run almost in linear time on sparse graphs.
  
      B{Reference}: VD Blondel, J-L Guillaume, R Lambiotte and E Lefebvre: Fast
      unfolding of community hierarchies in large networks, I{J Stat Mech}
      P10008 (2008). U{http://arxiv.org/abs/0803.0476}
  
      @param weights: edge attribute name or a list containing edge
        weights
      @param return_levels: if C{True}, the communities at each level are
        returned in a list. If C{False}, only the community structure with
        the best modularity is returned.
      @param resolution: the resolution parameter to use in the modularity
        measure. Smaller values result in a smaller number of larger clusters,
        while higher values yield a large number of small clusters. The classical
        modularity measure assumes a resolution parameter of 1.
      @return: a list of L{VertexClustering} objects, one corresponding to
        each level (if C{return_levels} is C{True}), or a L{VertexClustering}
        corresponding to the best modularity.
      """
      if graph.is_directed():
          raise ValueError("input graph must be undirected")
  
      modularity_params = {"weights": weights, "resolution": resolution}
      if return_levels:
          levels, qs = GraphBase.community_multilevel(
              graph, weights, return_levels=True, resolution=resolution
          )
          result = []
          for level, q in zip(levels, qs):
              result.append(
                  VertexClustering(
                      graph,
                      level,
                      q,
                      modularity_params=modularity_params,
                  )
              )
      else:
          membership = GraphBase.community_multilevel(
              graph, weights, return_levels=False, resolution=resolution
          )
          result = VertexClustering(
              graph, membership, modularity_params=modularity_params
          )
  
      return result
  
file_path: python-igraph/src/igraph/community.py
imports: from igraph._igraph import GraphBase
  from igraph.clustering import VertexDendrogram, VertexClustering
  from igraph.utils import deprecated
  from typing import List, Sequence, Tuple
label_desc: Use image node_id 5 for calling a global function with example usage: _community_multilevel(graph, weights, return_levels, resolution) and returns: result