  We identify a sufficient condition, treewidth-pliability, that gives a
polynomial-time algorithm for an arbitrarily good approximation of the optimal
value in a large class of Max-2-CSPs parameterised by the class of allowed
constraint graphs (with arbitrary constraints on an unbounded alphabet). Our
result applies more generally to the maximum homomorphism problem between two
rational-valued structures.
  The condition unifies the two main approaches for designing a polynomial-time
approximation scheme. One is Baker's layering technique, which applies to
sparse graphs such as planar or excluded-minor graphs. The other is based on
Szemer\'edi's regularity lemma and applies to dense graphs. We extend the
applicability of both techniques to new classes of Max-CSPs. On the other hand,
we prove that the condition cannot be used to find solutions (as opposed to
approximating the optimal value) in general.
  Treewidth-pliability turns out to be a robust notion that can be defined in
several equivalent ways, including characterisations via size, treedepth, or
the Hadwiger number. We show connections to the notions of
fractional-treewidth-fragility from structural graph theory, hyperfiniteness
from the area of property testing, and regularity partitions from the theory of
dense graph limits. These may be of independent interest. In particular we show
that a monotone class of graphs is hyperfinite if and only if it is
fractionally-treewidth-fragile and has bounded degree.
