GraphProblemBase

class GraphProblemBase(graph, *, use_constrained_mixer=True, config=None)[source]

Bases: QAOAProblem

Shared 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_cls class attributes. Problems without a constrained mixer set _supports_constrained_mixer = False and ignore use_constrained_mixer.

Attributes Summary

cost_hamiltonian

The cost Hamiltonian encoding the optimisation objective.

decode_fn

Map a measurement bitstring to a domain-level solution.

graph

The underlying graph.

metadata

mixer_hamiltonian

Mixer Hamiltonian for exploring the solution space.

recommended_initial_state

Recommended initial quantum state for this problem.

wire_labels

Qubit-position-ordered labels for the cost Hamiltonian.

Methods Summary

decompose()

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.

initial_solution_size()

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_solution and the adjacency cached by is_feasible are 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:

dict[Hashable, QAOAProblem]

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:

float

extend_solution(current_solution, prog_id, candidate_decoded)[source]

Map a sub-solution’s decoded bits into the global solution vector.

prog_id is one of the keys returned by decompose(). Must return a new list — do not mutate current_solution.

Return type:

list[int]

initial_solution_size()[source]

Size of the global solution vector (e.g. number of graph nodes).

Return type:

int

order_partitions(prog_ids)[source]

Partitions ordered so each next one has the largest summed |w| edge weight to those already placed.

Return type:

list[Hashable]

postprocess_candidates(candidates, *, strict=False)[source]

Post-process raw partition-aggregation candidates.

Parameters:
  • candidates (Sequence[tuple[float, list[int]]]) – Beam-search (score, solution) pairs, where score is the value returned by evaluate_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:

list[tuple[list[int], float]]

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).