Skip to content

Results are limited to QUBO Solver v0.9.1

Product news
You are reading QUBO Solver v0.9.1, an older version of this documentation. Go to the latest version (v0.10.0)

qubosolver.analysis

Free functions for analysing QUBO solutions.

Converts one or more Solution objects into a unified pandas.DataFrame (external), for filtering, comparing, and summarizing solver outputs.

Example
df = to_dataframe([sol_a, sol_b], labels=["classical", "quantum"])

Functions:

to_dataframe(solutions: Sequence[ Solution
dataclass
(qubosolver.Solution)" href="../qubosolver/#qubosolver.Solution">Solution], *, labels: Sequence[str] | Literal['auto'] = 'auto') -> pd.DataFrame

Convert one or more Solution into a single, unified pandas.DataFrame (external).

The resulting pandas.DataFrame (external) can be used for filtering, sorting, and analysis.

Parameters:

Returns:

Raises:

Source code in qubosolver/utils/analysis.py
def to_dataframe(
solutions: Sequence[Solution],
*,
labels: Sequence[str] | Literal["auto"] = "auto",
) -> pd.DataFrame:
"""Convert one or more [`Solution`][] into a single, unified [`pandas.DataFrame`][].
The resulting [`pandas.DataFrame`][] can be used for filtering, sorting, and analysis.
Args:
solutions: A sequence of [`Solution`][].
labels: One label per solution used to identify each group in the
[`pandas.DataFrame`][]. Defaults to ``"0"``, ``"1"``, … when ``"auto"``.
Returns:
The concatenated [`pandas.DataFrame`][] containing all solutions.
Raises:
ValueError: If the number of labels does not match the number of solutions.
"""
if labels == "auto":
labels = [str(i) for i in range(len(solutions))]
elif len(labels) != len(solutions):
raise ValueError("The number of labels must equal the number of QUBOSolutions provided.")
df_list = []
df_list.append(_solution_to_dataframe(Solution(), solution_label=""))
for label, sol in zip(labels, solutions, strict=True):
df_list.append(_solution_to_dataframe(sol, solution_label=label))
return pd.concat(df_list, ignore_index=True)