qiskit_addon_opt_mapper.applications.GraphPartition

class GraphPartition(graph)[source]

Bases: GraphOptimizationApplication

Optimization application for the “graph partition” [1] problem based on a NetworkX graph.

References

[1]: “Graph partition”, https://en.wikipedia.org/wiki/Graph_partition

Init method.

Parameters:
  • graph (Graph | ndarray | list | PyGraph) –

    A graph representing a problem. It can be specified in the following formats:

    • A Rustworkx undirected graph (rx.PyGraph)

    • A NetworkX undirected graph (nx.Graph)

    • A NumPy adjacency matrix (np.ndarray)

    • A list of edges or adjacency list (list)

  • rx.PyGraph. (The input graph will be internally normalized to a)

__init__(graph)[source]

Init method.

Parameters:
  • graph (Graph | ndarray | list | PyGraph) –

    A graph representing a problem. It can be specified in the following formats:

    • A Rustworkx undirected graph (rx.PyGraph)

    • A NetworkX undirected graph (nx.Graph)

    • A NumPy adjacency matrix (np.ndarray)

    • A list of edges or adjacency list (list)

  • rx.PyGraph. (The input graph will be internally normalized to a)

Return type:

None

Methods

__init__(graph)

Init method.

draw([result, pos])

Draw a graph with the result.

interpret(result)

Interpret a result as a list of node indices.

sample_most_likely(state_vector)

Compute the most likely binary string from state vector.

to_optimization_problem()

Represent as an optimization problem.

Attributes

graph

Getter of the graph.

nx_graph

Getter of the graph in Networkx format.

draw(result=None, pos=None)[source]

Draw a graph with the result.

When the result is None, draw an original graph without colors.

Parameters:
  • result (ndarray | None) – The calculated result for the problem

  • pos (dict[int, ndarray] | None) – The positions of nodes

Return type:

None

property graph: PyGraph

Getter of the graph.

Returns:

A graph for a problem

interpret(result)[source]

Interpret a result as a list of node indices.

Parameters:

result (ndarray) – The calculated result of the problem

Returns:

A list of node indices divided into two groups.

Return type:

list[list[int]]

property nx_graph: Graph

Getter of the graph in Networkx format.

Returns:

A graph for a problem

static sample_most_likely(state_vector)[source]

Compute the most likely binary string from state vector.

Parameters:

state_vector (QuasiDistribution | Statevector | ndarray | dict) – state vector or counts or quasi-probabilities.

Returns:

binary string as numpy.ndarray of ints.

Raises:

ValueError – if state_vector is not QuasiDistribution, Statevector, np.ndarray, or dict.

Return type:

ndarray

to_optimization_problem()[source]

Represent as an optimization problem.

Convert a graph partition instance into a OptimizationProblem

Returns:

The OptimizationProblem created from the graph partition instance.

Return type:

OptimizationProblem