<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def markov_network(potentials):
 """Creates a Markov Network from potentials. A Markov Network is also knows as a `Markov Random Field`_ Parameters potentials : dict[tuple, dict] A dict where the keys are either nodes or edges and the values are a dictionary of potentials. The potential dict should map each possible assignment of the nodes/edges to their energy. Returns ------- MN : :obj:`networkx.Graph` A markov network as a graph where each node/edge stores its potential dict as above. Examples -------- -1 .. _Markov Random Field: https://en.wikipedia.org/wiki/Markov_random_field """


    G = nx.Graph()

    G.name = 'markov_network({!r})'.format(potentials)

    # we use 'clique' because the keys of potentials can be either nodes or
    # edges, but in either case they are fully connected.
    for clique, phis in potentials.items():

        num_vars = len(clique)

        # because this data potentially wont be used for a while, let's do some
        # input checking now and save some debugging issues later
        if not isinstance(phis, abc.Mapping):
            raise TypeError("phis should be a dict")
        elif not all(config in phis for config in itertools.product((0, 1), repeat=num_vars)):
            raise ValueError("not all potentials provided for {!r}".format(clique))

        if num_vars == 1:
            u, = clique
            G.add_node(u, potential=phis)
        elif num_vars == 2:
            u, v = clique
            # in python<=3.5 the edge order might not be consistent so we store
            # the relevant order of the variables relative to the potentials
            G.add_edge(u, v, potential=phis, order=(u, v))
        else:
            # developer note: in principle supporting larger cliques can be done
            # using higher-order, but it would make the use of networkx graphs
            # far more difficult
            raise ValueError("Only supports cliques up to size 2")

    return G