GiulioRossetti / ndlib

Network Diffusion Library - (for NetworkX and iGraph)
http://ndlib.readthedocs.io/
BSD 2-Clause "Simplified" License
272 stars 80 forks source link

TypeError: "method" object is not iterable #24

Closed Nexuist closed 6 years ago

Nexuist commented 6 years ago

Hi,

My friend is trying to use the Voter model sample and keeps running into an error.

Here is his code (straight from the sample):

import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.opinions.VoterModel as vt

# Network topology
g = nx.erdos_renyi_graph(1000, 0.1)

# Model selection
model = vt.VoterModel(g)
config = mc.Configuration()
config.add_model_parameter('percentage_infected', 0.1)

model.set_initial_status(config)

# Simulation execution
iterations = model.iteration_bunch(200)

His error:

TypeError                                 Traceback (most recent call last)
c:\users\Friend\appdata\local\temp\tmp9eye_m.py in <module>()
     14 
     15 # Simulation execution
---> 16 iterations = model.iteration_bunch(200)

C:\Users\Friend\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\ndlib\models\DiffusionModel.py in iteration_bunch(self, bunch_size, node_status)
    189         system_status = []
    190         for it in past.builtins.xrange(0, bunch_size):
--> 191             its = self.iteration(node_status)
    192             system_status.append(its)
    193         return system_status
C:\Users\Friend\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\ndlib\models\opinions\VoterModel.py in iteration(self, node_status)
     51 
     52         # select a random node
---> 53         listener = list(self.graph.nodes)[np.random.randint(0, self.graph.number_of_nodes())]
     54 
     55         # select a random neighbour
TypeError: 'method' object is not iterable 

What is he doing wrong?

GiulioRossetti commented 6 years ago

Hi,

the most likely scenario is that your friend has an older version of networkx installed on his system (<2.0). If it is the case ask him to upgrade it.

Unfortunately, I was not able to replicate such issue: however, I tried to patch it anyway and the tests seem to run smoothly. Try reinstalling ndlib directly from github

pip install git+https://github.com/GiulioRossetti/ndlib

Let me know if the issue persists!

Giulio

Nexuist commented 6 years ago

Hi again,

Thanks for the very quick response. After installing the dev version the error went away and now the sample runs perfectly.

Have a great day!