prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  maximal_independent_set does not work for DiGraph
  Currently [maximal_independent_set](https://github.com/networkx/networkx/blob/d7d906e1d16ef331da0bc1d149953e7532155acc/networkx/algorithms/mis.py#L70) returns the wrong results for a `DiGraph` because it uses the `G.neighbors` method which returns only the successor nodes in a `DiGraph`.  I believe the [all_neighbors](https://github.com/networkx/networkx/blob/13b373bf6938c077d1e61adc60a48cb910a75755/networkx/classes/function.py#L540) function should be used instead to make `maximal_independent_set` work correctly for both graph types.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `networkx/algorithms/mis.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 # $Id: maximalIndependentSet.py 576 2011-03-01 05:50:34Z lleeoo $
  3 """
  4 Algorithm to find a maximal (not maximum) independent set.
  5 
  6 """
  7 #    Leo Lopes <leo.lopes@monash.edu>
  8 #    Aric Hagberg <hagberg@lanl.gov>
  9 #    Dan Schult <dschult@colgate.edu>
  10 #    Pieter Swart <swart@lanl.gov>
  11 #    All rights reserved.
  12 #    BSD license.
  13 
  14 __author__ = "\n".join(["Leo Lopes <leo.lopes@monash.edu>",
  15                         "Loïc Séguin-C. <loicseguin@gmail.com>"])
  16 
  17 __all__ = ['maximal_independent_set']
  18 
  19 import random
  20 import networkx as nx
  21 
  22 def maximal_independent_set(G, nodes=None):
  23     """Return a random maximal independent set guaranteed to contain
  24     a given set of nodes.
  25 
  26     An independent set is a set of nodes such that the subgraph
  27     of G induced by these nodes contains no edges. A maximal
  28     independent set is an independent set such that it is not possible
  29     to add a new node and still get an independent set.
  30     
  31     Parameters
  32     ----------
  33     G : NetworkX graph 
  34 
  35     nodes : list or iterable
  36        Nodes that must be part of the independent set. This set of nodes
  37        must be independent.
  38 
  39     Returns
  40     -------
  41     indep_nodes : list 
  42        List of nodes that are part of a maximal independent set.
  43 
  44     Raises
  45     ------
  46     NetworkXUnfeasible
  47        If the nodes in the provided list are not part of the graph or
  48        do not form an independent set, an exception is raised.
  49 
  50     Examples
  51     --------
  52     >>> G = nx.path_graph(5)
  53     >>> nx.maximal_independent_set(G) # doctest: +SKIP
  54     [4, 0, 2]
  55     >>> nx.maximal_independent_set(G, [1]) # doctest: +SKIP
  56     [1, 3]
  57     
  58     Notes
  59     -----
  60     This algorithm does not solve the maximum independent set problem.
  61 
  62     """
  63     if not nodes:
  64         nodes = set([random.choice(list(G))])
  65     else:
  66         nodes = set(nodes)
  67     if not nodes.issubset(G):
  68         raise nx.NetworkXUnfeasible(
  69                 "%s is not a subset of the nodes of G" % nodes)
  70     neighbors = set.union(*[set(G.neighbors(v)) for v in nodes])
  71     if set.intersection(neighbors, nodes):
  72         raise nx.NetworkXUnfeasible(
  73                 "%s is not an independent set of G" % nodes)
  74     indep_nodes = list(nodes)
  75     available_nodes = set(G.nodes()).difference(neighbors.union(nodes))
  76     while available_nodes:
  77         node = random.choice(list(available_nodes))
  78         indep_nodes.append(node)
  79         available_nodes.difference_update(list(G.neighbors(node)) + [node])
  80     return indep_nodes
  81 
  82
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/networkx/algorithms/mis.py b/networkx/algorithms/mis.py
  --- a/networkx/algorithms/mis.py
  +++ b/networkx/algorithms/mis.py
  @@ -1,24 +1,26 @@
   # -*- coding: utf-8 -*-
   # $Id: maximalIndependentSet.py 576 2011-03-01 05:50:34Z lleeoo $
  -"""
  -Algorithm to find a maximal (not maximum) independent set.
  -
  -"""
   #    Leo Lopes <leo.lopes@monash.edu>
   #    Aric Hagberg <hagberg@lanl.gov>
   #    Dan Schult <dschult@colgate.edu>
   #    Pieter Swart <swart@lanl.gov>
   #    All rights reserved.
   #    BSD license.
  +#
  +# Authors: Leo Lopes <leo.lopes@monash.edu>
  +#          Loïc Séguin-C. <loicseguin@gmail.com>
  +"""
  +Algorithm to find a maximal (not maximum) independent set.
   
  -__author__ = "\n".join(["Leo Lopes <leo.lopes@monash.edu>",
  -                        "Loïc Séguin-C. <loicseguin@gmail.com>"])
  +"""
  +import random
  +import networkx as nx
  +from networkx.utils import not_implemented_for
   
   __all__ = ['maximal_independent_set']
   
  -import random
  -import networkx as nx
   
  +@not_implemented_for('directed')
   def maximal_independent_set(G, nodes=None):
       """Return a random maximal independent set guaranteed to contain
       a given set of nodes.
  @@ -27,10 +29,10 @@
       of G induced by these nodes contains no edges. A maximal
       independent set is an independent set such that it is not possible
       to add a new node and still get an independent set.
  -    
  +
       Parameters
       ----------
  -    G : NetworkX graph 
  +    G : NetworkX graph
   
       nodes : list or iterable
          Nodes that must be part of the independent set. This set of nodes
  @@ -38,7 +40,7 @@
   
       Returns
       -------
  -    indep_nodes : list 
  +    indep_nodes : list
          List of nodes that are part of a maximal independent set.
   
       Raises
  @@ -47,6 +49,9 @@
          If the nodes in the provided list are not part of the graph or
          do not form an independent set, an exception is raised.
   
  +    NetworkXNotImplemented
  +        If `G` is directed.
  +
       Examples
       --------
       >>> G = nx.path_graph(5)
  @@ -54,7 +59,7 @@
       [4, 0, 2]
       >>> nx.maximal_independent_set(G, [1]) # doctest: +SKIP
       [1, 3]
  -    
  +
       Notes
       -----
       This algorithm does not solve the maximum independent set problem.
  @@ -67,7 +72,7 @@
       if not nodes.issubset(G):
           raise nx.NetworkXUnfeasible(
                   "%s is not a subset of the nodes of G" % nodes)
  -    neighbors = set.union(*[set(G.neighbors(v)) for v in nodes])
  +    neighbors = set.union(*[set(G.adj[v]) for v in nodes])
       if set.intersection(neighbors, nodes):
           raise nx.NetworkXUnfeasible(
                   "%s is not an independent set of G" % nodes)
  @@ -76,6 +81,5 @@
       while available_nodes:
           node = random.choice(list(available_nodes))
           indep_nodes.append(node)
  -        available_nodes.difference_update(list(G.neighbors(node)) + [node])
  +        available_nodes.difference_update(list(G.adj[node]) + [node])
       return indep_nodes
  -
  
verification_info: {"golden_diff": "diff --git a/networkx/algorithms/mis.py b/networkx/algorithms/mis.py\n--- a/networkx/algorithms/mis.py\n+++ b/networkx/algorithms/mis.py\n@@ -1,24 +1,26 @@\n # -*- coding: utf-8 -*-\n # $Id: maximalIndependentSet.py 576 2011-03-01 05:50:34Z lleeoo $\n-\"\"\"\n-Algorithm to find a maximal (not maximum) independent set.\n-\n-\"\"\"\n #    Leo Lopes <leo.lopes@monash.edu>\n #    Aric Hagberg <hagberg@lanl.gov>\n #    Dan Schult <dschult@colgate.edu>\n #    Pieter Swart <swart@lanl.gov>\n #    All rights reserved.\n #    BSD license.\n+#\n+# Authors: Leo Lopes <leo.lopes@monash.edu>\n+#          Lo\u00efc S\u00e9guin-C. <loicseguin@gmail.com>\n+\"\"\"\n+Algorithm to find a maximal (not maximum) independent set.\n \n-__author__ = \"\\n\".join([\"Leo Lopes <leo.lopes@monash.edu>\",\n-                        \"Lo\u00efc S\u00e9guin-C. <loicseguin@gmail.com>\"])\n+\"\"\"\n+import random\n+import networkx as nx\n+from networkx.utils import not_implemented_for\n \n __all__ = ['maximal_independent_set']\n \n-import random\n-import networkx as nx\n \n+@not_implemented_for('directed')\n def maximal_independent_set(G, nodes=None):\n     \"\"\"Return a random maximal independent set guaranteed to contain\n     a given set of nodes.\n@@ -27,10 +29,10 @@\n     of G induced by these nodes contains no edges. A maximal\n     independent set is an independent set such that it is not possible\n     to add a new node and still get an independent set.\n-    \n+\n     Parameters\n     ----------\n-    G : NetworkX graph \n+    G : NetworkX graph\n \n     nodes : list or iterable\n        Nodes that must be part of the independent set. This set of nodes\n@@ -38,7 +40,7 @@\n \n     Returns\n     -------\n-    indep_nodes : list \n+    indep_nodes : list\n        List of nodes that are part of a maximal independent set.\n \n     Raises\n@@ -47,6 +49,9 @@\n        If the nodes in the provided list are not part of the graph or\n        do not form an independent set, an exception is raised.\n \n+    NetworkXNotImplemented\n+        If `G` is directed.\n+\n     Examples\n     --------\n     >>> G = nx.path_graph(5)\n@@ -54,7 +59,7 @@\n     [4, 0, 2]\n     >>> nx.maximal_independent_set(G, [1]) # doctest: +SKIP\n     [1, 3]\n-    \n+\n     Notes\n     -----\n     This algorithm does not solve the maximum independent set problem.\n@@ -67,7 +72,7 @@\n     if not nodes.issubset(G):\n         raise nx.NetworkXUnfeasible(\n                 \"%s is not a subset of the nodes of G\" % nodes)\n-    neighbors = set.union(*[set(G.neighbors(v)) for v in nodes])\n+    neighbors = set.union(*[set(G.adj[v]) for v in nodes])\n     if set.intersection(neighbors, nodes):\n         raise nx.NetworkXUnfeasible(\n                 \"%s is not an independent set of G\" % nodes)\n@@ -76,6 +81,5 @@\n     while available_nodes:\n         node = random.choice(list(available_nodes))\n         indep_nodes.append(node)\n-        available_nodes.difference_update(list(G.neighbors(node)) + [node])\n+        available_nodes.difference_update(list(G.adj[node]) + [node])\n     return indep_nodes\n-\n", "issue": "maximal_independent_set does not work for DiGraph\nCurrently [maximal_independent_set](https://github.com/networkx/networkx/blob/d7d906e1d16ef331da0bc1d149953e7532155acc/networkx/algorithms/mis.py#L70) returns the wrong results for a `DiGraph` because it uses the `G.neighbors` method which returns only the successor nodes in a `DiGraph`.  I believe the [all_neighbors](https://github.com/networkx/networkx/blob/13b373bf6938c077d1e61adc60a48cb910a75755/networkx/classes/function.py#L540) function should be used instead to make `maximal_independent_set` work correctly for both graph types.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# $Id: maximalIndependentSet.py 576 2011-03-01 05:50:34Z lleeoo $\n\"\"\"\nAlgorithm to find a maximal (not maximum) independent set.\n\n\"\"\"\n#    Leo Lopes <leo.lopes@monash.edu>\n#    Aric Hagberg <hagberg@lanl.gov>\n#    Dan Schult <dschult@colgate.edu>\n#    Pieter Swart <swart@lanl.gov>\n#    All rights reserved.\n#    BSD license.\n\n__author__ = \"\\n\".join([\"Leo Lopes <leo.lopes@monash.edu>\",\n                        \"Lo\u00efc S\u00e9guin-C. <loicseguin@gmail.com>\"])\n\n__all__ = ['maximal_independent_set']\n\nimport random\nimport networkx as nx\n\ndef maximal_independent_set(G, nodes=None):\n    \"\"\"Return a random maximal independent set guaranteed to contain\n    a given set of nodes.\n\n    An independent set is a set of nodes such that the subgraph\n    of G induced by these nodes contains no edges. A maximal\n    independent set is an independent set such that it is not possible\n    to add a new node and still get an independent set.\n    \n    Parameters\n    ----------\n    G : NetworkX graph \n\n    nodes : list or iterable\n       Nodes that must be part of the independent set. This set of nodes\n       must be independent.\n\n    Returns\n    -------\n    indep_nodes : list \n       List of nodes that are part of a maximal independent set.\n\n    Raises\n    ------\n    NetworkXUnfeasible\n       If the nodes in the provided list are not part of the graph or\n       do not form an independent set, an exception is raised.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(5)\n    >>> nx.maximal_independent_set(G) # doctest: +SKIP\n    [4, 0, 2]\n    >>> nx.maximal_independent_set(G, [1]) # doctest: +SKIP\n    [1, 3]\n    \n    Notes\n    -----\n    This algorithm does not solve the maximum independent set problem.\n\n    \"\"\"\n    if not nodes:\n        nodes = set([random.choice(list(G))])\n    else:\n        nodes = set(nodes)\n    if not nodes.issubset(G):\n        raise nx.NetworkXUnfeasible(\n                \"%s is not a subset of the nodes of G\" % nodes)\n    neighbors = set.union(*[set(G.neighbors(v)) for v in nodes])\n    if set.intersection(neighbors, nodes):\n        raise nx.NetworkXUnfeasible(\n                \"%s is not an independent set of G\" % nodes)\n    indep_nodes = list(nodes)\n    available_nodes = set(G.nodes()).difference(neighbors.union(nodes))\n    while available_nodes:\n        node = random.choice(list(available_nodes))\n        indep_nodes.append(node)\n        available_nodes.difference_update(list(G.neighbors(node)) + [node])\n    return indep_nodes\n\n", "path": "networkx/algorithms/mis.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# $Id: maximalIndependentSet.py 576 2011-03-01 05:50:34Z lleeoo $\n#    Leo Lopes <leo.lopes@monash.edu>\n#    Aric Hagberg <hagberg@lanl.gov>\n#    Dan Schult <dschult@colgate.edu>\n#    Pieter Swart <swart@lanl.gov>\n#    All rights reserved.\n#    BSD license.\n#\n# Authors: Leo Lopes <leo.lopes@monash.edu>\n#          Lo\u00efc S\u00e9guin-C. <loicseguin@gmail.com>\n\"\"\"\nAlgorithm to find a maximal (not maximum) independent set.\n\n\"\"\"\nimport random\nimport networkx as nx\nfrom networkx.utils import not_implemented_for\n\n__all__ = ['maximal_independent_set']\n\n\n@not_implemented_for('directed')\ndef maximal_independent_set(G, nodes=None):\n    \"\"\"Return a random maximal independent set guaranteed to contain\n    a given set of nodes.\n\n    An independent set is a set of nodes such that the subgraph\n    of G induced by these nodes contains no edges. A maximal\n    independent set is an independent set such that it is not possible\n    to add a new node and still get an independent set.\n\n    Parameters\n    ----------\n    G : NetworkX graph\n\n    nodes : list or iterable\n       Nodes that must be part of the independent set. This set of nodes\n       must be independent.\n\n    Returns\n    -------\n    indep_nodes : list\n       List of nodes that are part of a maximal independent set.\n\n    Raises\n    ------\n    NetworkXUnfeasible\n       If the nodes in the provided list are not part of the graph or\n       do not form an independent set, an exception is raised.\n\n    NetworkXNotImplemented\n        If `G` is directed.\n\n    Examples\n    --------\n    >>> G = nx.path_graph(5)\n    >>> nx.maximal_independent_set(G) # doctest: +SKIP\n    [4, 0, 2]\n    >>> nx.maximal_independent_set(G, [1]) # doctest: +SKIP\n    [1, 3]\n\n    Notes\n    -----\n    This algorithm does not solve the maximum independent set problem.\n\n    \"\"\"\n    if not nodes:\n        nodes = set([random.choice(list(G))])\n    else:\n        nodes = set(nodes)\n    if not nodes.issubset(G):\n        raise nx.NetworkXUnfeasible(\n                \"%s is not a subset of the nodes of G\" % nodes)\n    neighbors = set.union(*[set(G.adj[v]) for v in nodes])\n    if set.intersection(neighbors, nodes):\n        raise nx.NetworkXUnfeasible(\n                \"%s is not an independent set of G\" % nodes)\n    indep_nodes = list(nodes)\n    available_nodes = set(G.nodes()).difference(neighbors.union(nodes))\n    while available_nodes:\n        node = random.choice(list(available_nodes))\n        indep_nodes.append(node)\n        available_nodes.difference_update(list(G.adj[node]) + [node])\n    return indep_nodes\n", "path": "networkx/algorithms/mis.py"}]}