draw_problem

Contents

draw_problem#

iqm.applications.graph_utils.draw_problem(problem_instance=None, *, graph_to_plot=None, orig_to_new_mapping=None, fixed_vars=frozenset({}), bitstring=None, seed=None, highlight_edge_by_node_count=frozenset({2}))[source]#

High-level wrapper that prepares and visualizes a problem graph.

This function orchestrates three steps:
  1. Extraction of problem data via _extract_problem_info().

  2. Conversion into plotting data with prepare_plot_data().

  3. Visualization using plot_graph().

It exists primarily as a convenience entry point — most argument validation and interpretation is handled by _extract_problem_info().

Parameters:
  • problem_instance (QUBOInstance | ISInstance | None) – Optional optimization problem instance from which graph and mapping data can be derived.

  • graph_to_plot (nx.Graph | None) – Graph object to visualize. Overrides the graph from problem_instance, if both are provided.

  • orig_to_new_mapping (Mapping[Any, int] | None) – Mapping from original variable names to integer node indices. Overrides the mapping from problem_instance, if both are provided.

  • fixed_vars (frozenset[int]) – Variables that have been fixed and should appear dimmed in the visualization. Overrides the fixed variables from problem_instance, if both are provided.

  • bitstring (str | None) – Bitstring representing highlighted nodes in the graph.

  • highlight_edge_by_node_count (frozenset[int]) – Specifies which edges are highlighted based on the number of connected highlighted nodes (subset of {0, 1, 2}).

  • seed (int | None) – Optional random seed for layout stability.

Raises:
  • AttributeError – If problem_instance is provided and it does not contain a valid graph (and a graph wasn’t explicitly provided).

  • ValueError – If graph_to_plot and orig_to_new_mapping are not both provided (or obtainable from provided problem_instance).

  • ValueError – If the provided highlight_edge_by_node_count is not a subset of {0, 1, 2}.

  • ValueError – If the provided bitstring has different length than the graph has nodes.

Return type:

None