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 a QUBO optimization problem using Linear Ramp QAOA (LR-QAOA). This high-level method orchestrates the complete LR-QAOA workflow:- Builds LR-QAOA circuit with custom parameter schedules
- Optionally compresses the circuit
- Executes on specified backend
- Post-processes results using Haiqu API
- Calculates CVaR expectation
- Parameters:
- problem (QUBO) — The QUBO optimization problem to solve.
- 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. IfNone(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: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().- 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 (QUBO) — The QUBO problem instance.
- 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:- Raises:
- ValueError — If no API client is available (not logged in).
- ValidationError — If parameters have incorrect types.
- Parameters:
- counts (dict *[*str , int | float ])
- problem (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 (QUBO) — The QUBO problem instance. 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