<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def structural_imbalance(S, sampler=None, **sampler_args):
 """Returns an approximate set of frustrated edges and a bicoloring. A signed social network graph is a graph whose signed edges represent friendly/hostile interactions between nodes. A signed social network is considered balanced if it can be cleanly divided into two factions, where all relations within a faction are friendly, and all relations between factions are hostile. The measure of imbalance or frustration is the minimum number of edges that violate this rule. Parameters S : NetworkX graph A social graph on which each edge has a 'sign' attribute with a numeric value. sampler A binary quadratic model sampler. A sampler is a process that samples from low energy states in models defined by an Ising equation or a Quadratic Unconstrainted Binary Optimization Problem (QUBO). A sampler is expected to have a 'sample_qubo' and 'sample_ising' method. A sampler is expected to return an iterable of samples, in order of increasing energy. If no sampler is provided, one must be provided using the `set_default_sampler` function. sampler_args Additional keyword parameters are passed to the sampler. Returns ------- frustrated_edges : dict A dictionary of the edges that violate the edge sign. The imbalance of the network is the length of frustrated_edges. colors: dict A bicoloring of the nodes into two factions. Raises ------ ValueError If any edge does not have a 'sign' attribute. Examples -------- {} {'Alice': 0, 'Bob': 0, 'Eve': 1} {('Ted', 'Eve'):
 {'sign': 1}} {'Bob': 1, 'Ted': 1, 'Alice': 1, 'Eve': 0} Notes ----- Samplers by their nature may not return the optimal solution. This function does not attempt to confirm the quality of the returned sample. References `Ising model on Wikipedia <https://en.wikipedia.org/wiki/Ising_model>`_ .. [FIA] Facchetti, G., Iacono G., and Altafini C. (2011). Computing global structural balance in large-scale signed social networks. PNAS, 108, no. 52, 20953-20958 """

    h, J = structural_imbalance_ising(S)

    # use the sampler to find low energy states
    response = sampler.sample_ising(h, J, **sampler_args)

    # we want the lowest energy sample
    sample = next(iter(response))

    # spins determine the color
    colors = {v: (spin + 1) // 2 for v, spin in iteritems(sample)}

    # frustrated edges are the ones that are violated
    frustrated_edges = {}
    for u, v, data in S.edges(data=True):
        sign = data['sign']

        if sign > 0 and colors[u] != colors[v]:
            frustrated_edges[(u, v)] = data
        elif sign < 0 and colors[u] == colors[v]:
            frustrated_edges[(u, v)] = data
        # else: not frustrated or sign == 0, no relation to violate

    return frustrated_edges, colors