def _maximal_matching_qubo(G, edge_mapping, magnitude=1.0):
    """Generates a QUBO that when combined with one as generated by _matching_qubo,
    induces a maximal matching on the given graph G.
    The variables in the QUBO are the edges, as given my edge_mapping.

    ground_energy = -1 * magnitude * |edges|
    infeasible_gap >= magnitude
    """
    Q = {}
    for u, v in G.edges:
        for edge in G.edges(u):
            x = edge_mapping[edge]
            if (x, x) not in Q:
                Q[x, x] = -1 * magnitude
            else:
                Q[x, x] -= magnitude
        for edge in G.edges(v):
            x = edge_mapping[edge]
            if (x, x) not in Q:
                Q[x, x] = -1 * magnitude
            else:
                Q[x, x] -= magnitude
        for e0 in G.edges(v):
            x0 = edge_mapping[e0]
            for e1 in G.edges(u):
                x1 = edge_mapping[e1]
                if x0 < x1:
                    if (x0, x1) not in Q:
                        Q[x0, x1] = magnitude
                    else:
                        Q[x0, x1] += magnitude
                elif (x1, x0) not in Q:
                    Q[x1, x0] = magnitude
                else:
                    Q[x1, x0] += magnitude
    return Q
