Skip to main content
haiqu.postprocess takes an unconstrained binary OptimizationProblem with a quadratic or higher-order objective. Solvers always minimize; a maximize OptimizationProblem is converted internally, and returned costs use the original objective of the found bitstring. Every OptimizationProblem uses the polynomial_problem payload. The deprecated Haiqu QUBO class is still accepted through the legacy LP wire. haiqu.solve_qubo is a deprecated wrapper around haiqu.build_lr_qaoa_circuit, optional haiqu.state_compression, haiqu.run, and haiqu.postprocess.

Haiqu.solve_qubo(problem, p=10, initial_state=None, alphas=None, betas=None, delta=0.5, shots=1000, device=None, device_id=None, options=None, use_packing=False, pack_size=None, compression=False, compression_options=None, postprocess_iterations=5, seed=None, cvar_alpha=0.1)

Solve an unconstrained binary optimization problem using Linear Ramp QAOA (LR-QAOA). The public problem type is qiskit_addon_opt_mapper.problems.OptimizationProblem. Constrained models must be penalty-folded with to_unconstrained_problem first. Every OptimizationProblem, quadratic or higher-order, uses the polynomial_problem payload. The deprecated Haiqu QUBO class is still accepted through the legacy LP wire. This high-level method orchestrates the complete LR-QAOA workflow:
  1. Builds LR-QAOA circuit with custom parameter schedules
  2. Optionally compresses the circuit
  3. Executes on specified backend
  4. Post-processes results using Haiqu API
  5. Calculates CVaR expectation

Deprecated

Deprecated since version 1.6.0: The method haiqu.sdk.quantum_haiqu.Haiqu.solve_qubo() is deprecated as of haiqu-sdk 1.6.0. It will be removed no sooner than 3 months after the release date. Instead, use an unconstrained quadratic qiskit_addon_opt_mapper.problems.OptimizationProblem with haiqu.build_lr_qaoa_circuit, optional haiqu.state_compression, haiqu.run, and haiqu.postprocess.
  • Parameters:
    • problem (OptimizationProblem | QUBO) — Unconstrained binary OptimizationProblem (or deprecated QUBO).
    • p (int) — Number of QAOA layers. Defaults to 10.
    • initial_state (Optional *[*QuantumCircuit ]) — Custom initial state. Defaults to None (uniform superposition).
    • alphas (Optional *[*list *[*float ] ]) — Cost operator parameters. Defaults to None (linear ramp).
    • betas (Optional *[*list *[*float ] ]) — Mixer operator parameters. Defaults to None (linear ramp).
    • delta (float) — Ramp parameter when alphas/betas not specified. Defaults to 0.5.
    • shots (int) — Number of measurement shots. Defaults to 1000.
    • device (DeviceModel) — Device to execute on. Defaults to None.
    • device_id (str) — Id of the device to execute on. Defaults to None.
    • options (Optional *[*dict ]) — Additional device options.
    • use_packing (bool) — Whether to use circuit packing for efficient device utilization. Defaults to False. Warning: Experimental — packing replicates circuits on unused device qubits to run multiple copies in parallel, which may increase errors for deeper input circuits. For example, a 4-qubit circuit with pack_size=2 and 1000 shots runs two copies in parallel with 500 shots each, yielding 1000 shots of results while only paying for 500 shot executions on the QPU — a 2x cost saving.
    • pack_size (Optional *[*int ]) — Number of circuit copies to pack onto the device. Must be >= 2. Only valid when use_packing=True. If None (default), the backend will pack into at most 2/3 of the device qubits.
    • compression (bool) — Whether to compress the circuit. Defaults to False.
    • compression_options (Optional *[*dict ]) — Compression options dictionary. See method state_compression for details.
    • postprocess_iterations (int) — Maximum number of post-processing passes. Defaults to 5. Controls the number of complete passes through all bits. Higher values may find better local minima but increase runtime. Default of 5 provides good balance between speed and solution quality.
    • seed (Optional *[*int ]) — Random seed for reproducible post-processing results. Defaults to None.
    • cvar_alpha (Optional *[*float ]) — CVaR alpha parameter. None to disable CVaR. Defaults to 0.1.
  • Returns: Complete solution with raw/processed results, costs, and metadata.
  • Return type: SolverResult

NOTE

Bitstrings use Qiskit convention: rightmost bit = qubit 0. Example: “101” means qubit 0=1, qubit 1=0, qubit 2=1.

Examples

Basic usage:
With more post-processing iterations:
With custom schedules and compression:
Without CVaR:

Haiqu.postprocess(counts, problem, postprocess_iterations=5, seed=None)

Apply post-processing to quantum measurement results using Haiqu API. This method uses the Haiqu API’s optimized postprocessing algorithms to improve quantum optimization results. Requires authentication via login(). Constrained OptimizationProblem instances must be folded with to_unconstrained_problem first. Every OptimizationProblem, quadratic or higher-order, uses the polynomial_problem payload. The deprecated Haiqu QUBO class uses the legacy LP wire.
  • Parameters:
    • counts (dict *[*str , int | float ]) — Dictionary mapping bitstrings to their measurement counts or probabilities. Bitstrings must be in Qiskit’s little-endian convention (rightmost bit = qubit 0).
    • problem (OptimizationProblem | QUBO) — Unconstrained binary OptimizationProblem (or deprecated QUBO).
    • postprocess_iterations (int) — Maximum number of optimization passes. Defaults to 5.
    • seed (int | None) — Random seed for reproducible results. Defaults to None.
  • Returns:
    • optimized_costs: Dict mapping bitstrings to their costs
    • optimized_counts: Dict mapping bitstrings to aggregated counts
  • Return type: Tuple of (optimized_costs, optimized_counts)

NOTE

Bitstrings use Qiskit convention: rightmost bit = qubit 0. Example: “101” means qubit 0=1, qubit 1=0, qubit 2=1.

Examples

Basic usage:
With custom parameters:
  • Raises: ValidationError — If parameters have incorrect types.
  • Parameters:
    • counts (dict *[*str , int | float ])
    • problem (OptimizationProblem | QUBO)
    • postprocess_iterations (int)
    • seed (int | None)
  • Return type: tuple[dict[str, float], dict[str, int | float]]

optimization.cvar_expectation(problem=None, alpha=1.0, cost_function=None)

Calculate Conditional Value at Risk (CVaR) expectation value. This is a utility function for analyzing optimization results.
  • Parameters:
    • counts (Dict *[*str , Union *[*int , float ] ]) — Dictionary mapping bitstrings to counts/probabilities. Bitstrings in Qiskit convention (little-endian).
    • problem (Union [ ‘OptimizationProblem’ , ‘QUBO’ , None ]) — Unconstrained binary OptimizationProblem or deprecated QUBO. Required if cost_function is not provided.
    • alpha (float) — CVaR parameter (0 < alpha <= 1). Defaults to 1.0 (full expectation).
    • cost_function (Optional *[*Callable [ *[*str ] , float ] ]) — Custom cost function. If None, uses problem.cost(). Required if problem is not provided.
  • Returns: CVaR expectation value.
  • Raises: ValueError — If both problem and cost_function are None.
  • Return type: float

NOTE

Bitstrings use Qiskit convention: rightmost bit = qubit 0.

Examples

Using an OptimizationProblem:
Using a custom cost function: