Skip to main content

optimization.postprocess()

Post-processing utilities for quantum optimization results. This module provides utility functions for educational and analysis purposes. For production postprocessing, use haiqu.postprocess() which leverages the Haiqu API.

optimization.bitflip_search(cost_function: Callable[[str], float], K: int = 1, seed: int | None = None) → Tuple[str, float]

Perform local search optimization using bit-flip moves. This is a standalone educational reference implementation for understanding local search algorithms. For production postprocessing, use haiqu.postprocess() which leverages optimized API algorithms.
  • Parameters:
    • bitstring — Initial binary string to optimize.
    • cost_function — Function that computes cost of a bitstring.
    • K — Maximum number of passes through all bits.
    • seed — Random seed for reproducible results. Defaults to None.
  • Returns: Tuple of (optimized_bitstring, final_cost).

Example

>>> def cost_fn(bs):
...     return sum(int(b) for b in bs)
>>> optimized, cost = bitflip_search("0000", cost_fn, K=5)

optimization.cvar_expectation(problem: QUBO, alpha: float = 1.0, reverse_string: bool = True, cost_function: Callable[[str], float] | None = None) → float

Calculate Conditional Value at Risk (CVaR) expectation value. This is a utility function for analyzing optimization results.
  • Parameters:
    • counts — Dictionary mapping bitstrings to counts/probabilities.
    • problem — The QUBO problem instance.
    • alpha — CVaR parameter (0 < alpha <= 1). Defaults to 1.0 (full expectation).
    • reverse_string — Whether to reverse bitstring ordering. Defaults to True.
    • cost_function — Custom cost function. If None, uses problem.cost().
  • Returns: CVaR expectation value.