qubosolver.analysis
qubosolver.analysis
Section titled “
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–Convert one or more
Solutioninto a single, unifiedpandas.DataFrame(external).
to_dataframe
Section titled “
to_dataframe
”to_dataframe(solutions: Sequence[ Solution
dataclass (qubosolver.Solution)" href="../qubosolver/#qubosolver.Solution">Solution], *, labels: Sequence[str] | Literal['auto'] = 'auto') -> pd.DataFrameConvert 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:
-
solutions(Sequence (external)[Solution]) –A sequence of
Solution. -
labels(Sequence (external)[str (external)] | Literal (external)['auto'], default:'auto') –One label per solution used to identify each group in the
pandas.DataFrame(external). Defaults to"0","1", … when"auto".
Returns:
-
pd (external).DataFrame (external)–The concatenated
pandas.DataFrame(external) containing all solutions.
Raises:
-
ValueError (external)–If the number of labels does not match the number of solutions.
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)