QAOAProblem¶
- class QAOAProblem[source]¶
Bases:
ABCBase class for all QAOA-compatible problems.
Subclasses must implement the abstract properties that provide the ingredients QAOA needs. Default implementations of
mixer_hamiltonian,recommended_initial_state,is_feasible,repair_infeasible_bitstring, andcompute_energyare provided and can be overridden.Attributes Summary
The cost Hamiltonian encoding the optimization objective.
Map a measurement bitstring to a domain-level solution.
Constant offset added back to the expectation value.
Mixer Hamiltonian for exploring the solution space.
Recommended initial quantum state for this problem.
Qubit-position-ordered labels for the cost Hamiltonian.
Methods Summary
compute_energy(bitstring)Evaluate the objective energy for a bitstring.
Decompose this problem into sub-problems for partitioned solving.
evaluate_global_solution(solution)Score a complete global solution for beam search.
extend_solution(current_solution, prog_id, ...)Map a sub-solution's decoded bits into the global solution vector.
Size of the global solution vector (e.g. number of graph nodes).
is_feasible(bitstring)Check whether a bitstring represents a feasible solution.
postprocess_candidates(candidates, *[, strict])Post-process raw partition-aggregation candidates.
repair_infeasible_bitstring(bitstring)Repair an infeasible bitstring into a feasible one.
Attributes Documentation
- cost_hamiltonian¶
The cost Hamiltonian encoding the optimization objective.
- decode_fn¶
Map a measurement bitstring to a domain-level solution.
Bitstrings use left-to-right qubit ordering: the character at index i corresponds to qubit i of the cost Hamiltonian.
- loss_constant¶
Constant offset added back to the expectation value.
- mixer_hamiltonian¶
Mixer Hamiltonian for exploring the solution space.
Defaults to the standard X mixer over the cost Hamiltonian qubits, suitable for unconstrained binary optimization. Override this for constrained feasible subspaces or problem-specific mixers.
- recommended_initial_state¶
Recommended initial quantum state for this problem.
Defaults to
SuperpositionState(ground state of the standard X mixer).
- wire_labels¶
Qubit-position-ordered labels for the cost Hamiltonian.
Defaults to dense
range(num_qubits). Override for problems whose users expect domain-level identifiers (e.g. graph node names) atQAOA._circuit_wiresand throughdecode_fn.
Methods Documentation
- compute_energy(bitstring)[source]¶
Evaluate the objective energy for a bitstring.
Defaults to
None(unknown).
- decompose()[source]¶
Decompose this problem into sub-problems for partitioned solving.
Returns a dict mapping program IDs to sub-problems. Program IDs must be hashable and stable because later partitioning hooks receive the same IDs when extending candidates into a global solution.
- Raises:
NotImplementedError – If the subclass does not support decomposition.
- Return type:
- evaluate_global_solution(solution)[source]¶
Score a complete global solution for beam search.
Lower scores are better. Problems with maximization objectives should usually return a negated score here, then expose the natural objective value from
postprocess_candidates().- Return type:
- extend_solution(current_solution, prog_id, candidate_decoded)[source]¶
Map a sub-solution’s decoded bits into the global solution vector.
prog_idis one of the keys returned bydecompose(). Must return a new list — do not mutate current_solution.
- initial_solution_size()[source]¶
Size of the global solution vector (e.g. number of graph nodes).
- Return type:
- is_feasible(bitstring)[source]¶
Check whether a bitstring represents a feasible solution.
Defaults to
True(unconstrained).- Return type:
- postprocess_candidates(candidates, *, strict=False)[source]¶
Post-process raw partition-aggregation candidates.
- Parameters:
candidates (
list[tuple[float,list[int]]]) – Beam-search(score, solution)pairs, wherescoreis the value returned byevaluate_global_solution()and lower is better.strict (
bool) – If supported by a constrained problem, reject invalid raw solutions instead of repairing them. The default implementation ignores this flag.
- Return type:
- Returns:
Problem-specific
(result, objective_value)tuples ready to return from partitioned aggregation APIs. The objective value uses the problem’s public convention, which may differ from the beam-search score. Default:(solution, score).
- repair_infeasible_bitstring(bitstring)[source]¶
Repair an infeasible bitstring into a feasible one.
- Returns:
repaired_bitstring: The feasible bitstring after repair.
decoded: Domain-level solution (e.g. tour list, routes), or
Noneif unavailable.energy: Objective value of the repaired solution, or
Noneif unknown.
- Return type:
The default implementation returns the bitstring unchanged.