GraphProblemBase¶
- class GraphProblemBase(graph, *, use_constrained_mixer=True, config=None)[source]¶
Bases:
QAOAProblemShared logic for graph problems built directly from
SparsePauliOp.Subclasses set
_resolver(a function returning(cost_spo, mixer_spo)or(cost_spo, mixer_spo, metadata)), or override_resolve_hamiltonians, and the two_*_state_clsclass attributes. Problems without a constrained mixer set_supports_constrained_mixer = Falseand ignoreuse_constrained_mixer.Attributes Summary
The cost Hamiltonian encoding the optimisation objective.
Map a measurement bitstring to a domain-level solution.
The underlying graph.
Mixer Hamiltonian for exploring the solution space.
Recommended initial quantum state for this problem.
Qubit-position-ordered labels for the cost Hamiltonian.
Methods Summary
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).
order_partitions(prog_ids)Partitions ordered so each next one has the largest summed
|w|edge weight to those already placed.postprocess_candidates(candidates, *[, strict])Post-process raw partition-aggregation candidates.
Attributes Documentation
- cost_hamiltonian¶
- decode_fn¶
- graph¶
The underlying graph.
Treat as read-only: the cost Hamiltonian, the Pauli terms cached by
evaluate_global_solutionand the adjacency cached byis_feasibleare built from it once. Build a new problem instead of mutating it.
- metadata¶
- mixer_hamiltonian¶
- recommended_initial_state¶
- wire_labels¶
Methods Documentation
- 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 maximisation 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:
- order_partitions(prog_ids)[source]¶
Partitions ordered so each next one has the largest summed
|w|edge weight to those already placed.
- postprocess_candidates(candidates, *, strict=False)[source]¶
Post-process raw partition-aggregation candidates.
- Parameters:
candidates (
Sequence[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).