fumitoh / modelx

Use Python like a spreadsheet!

Home Page:https://modelx.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v0.25.0 model.clear_all() - NetworkXError nbunch is not a node or a sequence of nodes.

gmadd72891 opened this issue · comments

We are running into the issue below when using the model.clear_all() function. It is unclear why we are running into this issue. It appears the remove_with_referred logic was added in modelx v0.25.0. Our model performs as expected when using modelx v0.24.0.

Can you please help us understand why we might experience this error?

  File [User Script], line 69, in [User Function]
    m.clear_all()
  File "...\modelx\core\model.py", line 342, in clear_all
    space.clear_all_cells(
  File "...\modelx\core\space.py", line 1478, in clear_all_cells
    cells.clear_all_values(clear_input=clear_input)
  File "...\modelx\core\cells.py", line 742, in clear_all_values
    self.clear_value_at(key, clear_input)
  File "...\modelx\core\cells.py", line 747, in clear_value_at
    self.model.clear_with_descs(key_to_node(self, key))
  File "...\modelx\core\model.py", line 759, in clear_with_descs
    self.refgraph.remove_with_referred(removed)
  File "...\modelx\core\model.py", line 137, in remove_with_referred
    if self.degree(n) == 0:
       ^^^^^^^^^^^^^^
  File "...\networkx\classes\reportviews.py", line 438, in __call__
    return self.__class__(self._graph, nbunch, weight)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\networkx\classes\reportviews.py", line 423, in __init__
    self._nodes = self._succ if nbunch is None else list(G.nbunch_iter(nbunch))
                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\networkx\classes\graph.py", line 2040, in bunch_iter
    raise exc
networkx.exception.NetworkXError: nbunch is not a node or a sequence of nodes.

Thank you for the report. This seems to be a bug in modelx. What version of networkx was used in the erroneous run above?

Thank you for the report. This seems to be a bug in modelx. What version of networkx was used in the erroneous run above?

This error occurs when using networkx 2.7.1 as suggested by modelx requirements.txt to use networkx < 2.8, as well as the latest version of networkx, version 3.3.

I reproduced the issue. The following script throws the same error.

import modelx as mx

m = mx.new_model()
s1 = m.new_space("Space1")
s2 = s1.new_space("Space2")

@mx.defcells(space=s1)
def cells1(t):
    return Space2.x

@mx.defcells(space=s1)
def cells2(t):
    return cells1(t) + Space2.x

s2.x = 1

cells1(10)
cells2(10)
m.clear_all()

Thank you for the report. This seems to be a bug in modelx. What version of networkx was used in the erroneous run above?

This error occurs when using networkx 2.7.1 as suggested by modelx requirements.txt to use networkx < 2.8, as well as the latest version of networkx, version 3.3.

requirements-doc.txt is only for rendering documents on readthedocs.org. You can use any networkx version higher than 2.8 with modelx

modelx v0.25.1 is just released and now available on PyPI. The release should address the issue. The document has not been updated. Please test with it and let me know how it goes.

This fix is working well after upgrading to modelx 0.25.1 along with networkx 3.3.