Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions qaoa/problems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .qubo_problem import QUBO
from .graph_problem import GraphProblem
from .exactcover_problem import ExactCover
from .bucketexactcover_problem import BucketExactCover
from .portfolio_problem import PortfolioOptimization
from .maxkcut_binary_powertwo import MaxKCutBinaryPowerOfTwo
from .maxkcut_binary_fullH import MaxKCutBinaryFullH
Expand Down
20 changes: 20 additions & 0 deletions qaoa/problems/base_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,23 @@ def validate_circuit(self, t=1, flip=True, atol=1e-8, rtol=1e-8):
if self.circuit is None:
self.create_circuit()
return validation.check_phase_separator_exact_problem(self, t=t, flip=flip, atol=atol, rtol=rtol)


def preprocess_histogram(self, hist: dict) -> dict:
"""
Optionally transform a measurement histogram before plotting or analysis.

Subclasses that use encoded bitstrings (e.g. binary-encoded formulations
with modular wrapping as in BucketExactCover) may override this to decode
keys into a canonical format and combine counts for equivalent solutions.
The default implementation returns the histogram unchanged.

Args:
hist (dict): Raw histogram mapping bitstrings to hit counts.

Returns:
dict: Histogram with keys in the format used for plotting and
comparison. For problems without encoding, returns ``hist``
unchanged.
"""
return hist
Loading