(args: str | None = None, include_self_links: bool | None = None, skip_adjust_bipartite_flow: bool = False, bipartite_teleportation: bool = False, weight_threshold: float | None = None, no_self_links: bool = False, node_limit: int | None = None, matchable_multilayer_ids: int | None = None, cluster_data: str | os.PathLike[str] | None = None, assign_to_neighbouring_module: bool = False, meta_data: str | os.PathLike[str] | None = None, meta_data_rate: float = 1.0, meta_data_unweighted: bool = False, no_infomap: bool = False, out_name: str | None = None, no_file_output: bool = False, tree: bool = False, ftree: bool = False, clu: bool = False, clu_level: int | None = None, output: list[typing.Literal['clu', 'tree', 'ftree', 'newick', 'json', 'csv', 'network', 'states', 'flow']] | tuple[typing.Literal['clu', 'tree', 'ftree', 'newick', 'json', 'csv', 'network', 'states', 'flow'], ...] | None = None, hide_bipartite_nodes: bool = False, print_all_trials: bool = False, no_overwrite: bool = False, print_config_fingerprint: bool = False, timing_json: str | os.PathLike[str] | None = None, summary_json: str | os.PathLike[str] | None = None, manifest_json: str | os.PathLike[str] | None = None, memory_report: bool = False, trial_offset: int | None = None, trial_results: str | os.PathLike[str] | None = None, no_final_output: bool = False, verbosity_level: int = 1, silent: bool = True, pretty: bool | None = None, two_level: bool = , flow_model: Optional[Literal['undirected', 'directed', 'undirdir', 'outdirdir', 'rawdir', 'precomputed']] = None, directed: bool | None = , recorded_teleportation: bool = False, use_node_weights_as_flow: bool = False, to_nodes: bool = False, teleportation_probability: float = 0.15, max_flow_iterations: int = 400, min_flow_iterations: int = 50, flow_tolerance: float = 1e-15, regularized: bool = False, regularization_strength: float = 1.0, entropy_corrected: bool = False, entropy_correction_strength: float = 1.0, markov_time: float = , variable_markov_time: bool = False, variable_markov_damping: float = 1.0, variable_markov_min_scale: float = 1.0, preferred_number_of_modules: int | None = None, preferred_number_of_levels: int | None = None, preferred_number_of_levels_strength: float = 1.0, multilayer_relax_rate: float = 0.15, multilayer_relax_limit: int = -1, multilayer_relax_limit_up: int = -1, multilayer_relax_limit_down: int = -1, multilayer_relax_by_jsd: bool = False, multilayer_relax_to_self: bool = False, seed: int = , num_trials: int = , core_loop_limit: int = 10, core_level_limit: int | None = None, tune_iteration_limit: int | None = None, core_loop_codelength_threshold: float = 1e-10, tune_iteration_relative_threshold: float = 1e-05, fast_hierarchical_solution: int | None = None, inner_parallelization: bool = False, parallel_trials: bool = False, converge: bool = False, num_threads: str | int | None = None, threads: str | int | None = None, prefer_modular_solution: bool = False, num_random_moves: int = 5, max_degree_for_random_moves: int = 2, options: infomap._options.Options | collections.abc.Mapping | None = None) -> None The stateful entry point to the algorithm: build a network with the ``add_*`` verbs, then call :meth:`run` to get an immutable :class:`~infomap.Result`. Internally it composes a :class:`~infomap.Network` (input) and an :class:`~infomap.Options` config over a single ``Core`` boundary to the SWIG-compiled engine, rather than exposing that engine directly. For one-shot use prefer the functional :func:`infomap.run`; for incremental construction prefer :class:`~infomap.Network`. .. note:: Only ``seed``, ``num_trials``, ``two_level``, ``directed`` and ``markov_time`` are first-class keyword options here. The 70+ other keyword parameters in the ``__init__``/:meth:`run` signature are per-option deprecation shims that move off these signatures in 3.0 -- carry every other engine option via :class:`~infomap.Options` (``im.run(options=Options(regularized=True))``) rather than as a bare keyword. The output-file flags (``tree``, ``clu``, ``output``, ``out_name``, ``no_file_output`` ...) are inert here; write from the :class:`~infomap.Result` / :class:`~infomap.Network` instead. For a clean, one-entry-per-option parameter reference read ``inspect.getdoc(infomap.Options)``, not the raw signature. Examples -------- Build a network, run Infomap, and read the results off the returned :class:`~infomap.Result`: >>> from infomap import Infomap >>> im = Infomap() >>> im.add_node(1) >>> im.add_node(2) >>> im.add_link(1, 2) >>> result = im.run() >>> result.codelength 1.0 Read a network file and inspect a few metrics on the result. Point ``read_file`` at your own network file (Pajek, link list, ``*States`` ...); the bundled :mod:`infomap.datasets` need no file at all:: im = Infomap(num_trials=10) im.read_file("your-network.net") result = im.run() result.codelength # e.g. 3.3858 result.num_top_modules # e.g. 3 Iterate the partition via :meth:`Result.modules` (``node_id -> module_id``) or :meth:`Result.nodes` (per-node views): >>> from infomap import Infomap >>> im = Infomap() >>> im.add_links(((1, 2), (1, 3), (2, 3), (4, 5), (4, 6), (5, 6), (3, 4))) >>> result = im.run() >>> for node_id, module_id in sorted(result.modules().items()): ... print(node_id, module_id) 1 1 2 1 3 1 4 2 5 2 6 2 ``run()`` returns an immutable :class:`~infomap.Result`; read collections via methods (``result.modules()``, ``result.nodes()``, ``result.tree()``, ``result.links()``, ``result.to_dataframe()``) and scalars via properties (``result.codelength``, ``result.num_top_modules``). For more examples, see :doc:`/quickstart` and :doc:`/examples/index`. Get a dict with node ids as keys and module ids as values for a given depth in the hierarchical tree. :: Level Root 0 ┌─┐ ┌─────────┴─┴────────┐ │ │ │ │ │ │ Path │ Module Path │ Module 1 1 ┌┼┐ 1 2 ┌┼┐ 2 ┌───┴─┴───┐ ┌───┴─┴───┐ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 2 1 ┌┼┐ 1 2 ┌┼┐ 2 1 ┌┼┐ 3 2 ┌┼┐ 3 ┌───┴─┴───┐ └─┴────┐ └─┘ └─┘ │ │ │ │ │ │ ▲ ▲ │ │ │ └────┬────┘ │ │ │ │ 3 1 ┌┼┐ 2 ┌┼┐ 1 ┌┼┐ └─┘ └─┘ └─┘ ◄─── Leaf-nodes Path to the left of the nodes. Depth dependent module ids to the right. The five leaf-nodes are network-nodes. All other tree-nodes are modules. For example: The left-most node on level 3 has path 1:1:1 and belong to module 1 on level 1. The right-most node on level 2 has path 2:2 and belong to module 2 on level 1 which is renamed to module 3 on level 2 as we have more modules in total on this level. Assuming the nodes are labelled 1-5 from left to right, then the first three nodes are in module 1, and the last two nodes are in module 2:: > im.get_modules(depth_level=1) {1: 1, 2: 1, 3: 1, 4: 2, 5: 2} However, at level 2, the first two nodes are in module 1, the third node in module 2, and the last two nodes are in module 3:: > im.get_modules(depth_level=2) {1: 1, 2: 1, 3: 2, 4: 3, 5: 3} Examples -------- >>> from infomap import Infomap >>> im = Infomap() >>> im.read_file("twotriangles.net") >>> _ = im.run() >>> im.get_modules() {1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2} >>> from infomap import Infomap >>> im = Infomap() >>> im.read_file("states.net") >>> _ = im.run() >>> im.get_modules(states=True) {1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2} Notes ----- In a higher-order network, a physical node (defined by ``node_id``) may partially exist in multiple modules. However, the ``node_id`` can not exist multiple times as a key in the node-to-module map, so only one occurrence of a physical node will be retrieved. To get all states, use ``get_modules(states=True)``. Parameters ---------- depth_level : int, optional The level in the hierarchical tree. Set to ``1`` (default) to return the top modules (coarsest level). Set to ``2`` for second coarsest level etc. Set to ``-1`` to return the bottom level modules (finest level). Default ``1``. states : bool, optional For higher-order networks, if ``states`` is True, it will return state node ids. Otherwise it will return physical node ids, merging state nodes with same ``node_id`` if they are in the same module. Note that the same physical node may end up on different paths in the tree. Default ``false``. Returns ------- dict of int Dict with node ids as keys and module ids as values. .. deprecated:: 2.15 Use ``result = im.run(); result.modules(depth, states=states)``.