draw_problem

Contents

draw_problem#

iqm.applications.graph_utils.draw_problem(problem_instance=None, *, graph_to_plot=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.

  • 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) – Binary string indicating which nodes are highlighted in the graph. Its length must match len(problem_instance.original_variables) and represent the state of all original variables (both fixed and unfixed). If the bitstring encodes only unfixed variables, it must first be converted using restore_fixed_variables_bitstring().

  • 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:
  • ValueError – If graph_to_plot is not 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