<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_networkx(cls, network):
 r""" Write OpenPNM Network to a NetworkX object. Parameters network : OpenPNM Network Object The OpenPNM Network to be converted to a NetworkX object Returns ------- A NetworkX object with all pore/throat properties attached to it """

        # Ensure network is an OpenPNM Network object.
        if not isinstance(network, GenericNetwork):
            raise('Provided network is not an OpenPNM Network.')

        G = nx.Graph()

        # Extracting node list and connectivity matrix from Network
        nodes = map(int, network.Ps)
        conns = network['throat.conns']

        # Explicitly add nodes and connectivity matrix
        G.add_nodes_from(nodes)
        G.add_edges_from(conns)

        # Attach Network properties to G
        for prop in network.props(deep=True) + network.labels():
            if 'pore.' in prop:
                if len(network[prop].shape) > 1:
                    val = {i: list(network[prop][i]) for i in network.Ps}
                else:
                    val = {i: network[prop][i] for i in network.Ps}
                nx.set_node_attributes(G, name=prop[5:], values=val)
            if 'throat.' in prop:
                val = {tuple(conn): network[prop][i] for i, conn
                       in enumerate(conns)}
                nx.set_edge_attributes(G, name=prop[7:], values=val)

        return G