0

Hey I am using the Python library Mesa for Agent-Based Modeling.

I have adapted the 'virus on a network' model to my own research about stakeholder engagement in smart-city and get stuck at debugging the ModularServer which creates the link between the model in python and its browser interface in javascript.

here is my code:

# create and launch server
server = ModularServer(
    SEmodel, [network, chart], "Stakeholder Engagement Model", model_parameters
)
server.port = 8521 #default port

and here is the error:

TypeError                                 Traceback (most recent call last)
<ipython-input-79-3fa8b0cdeb17> in <module>
      1 # create and launch server
----> 2 server = ModularServer(
      3     SEmodel, [network, chart], "Stakeholder Engagement Model", model_parameters
      4 )
      5 server.port = 8521 #default port

/usr/local/anaconda3/lib/python3.8/site-packages/mesa/visualization/ModularVisualization.py in __init__(self, model_cls, visualization_elements, name, model_params)
    284 
    285         self.model_kwargs = model_params
--> 286         self.reset_model()
    287 
    288         # Initializing the application itself:

/usr/local/anaconda3/lib/python3.8/site-packages/mesa/visualization/ModularVisualization.py in reset_model(self)
    312                 model_params[key] = val
    313 
--> 314         self.model = self.model_cls(**model_params)
    315 
    316     def render_model(self):

<ipython-input-76-fe37123a8f72> in __init__(self, num_nodes, avg_node_degree, engagement, trustability, influenceability, recovery, experience, initial_opinion, opinion, public_opinion, public_sector_opinion, corpo_opinion, startup_opinion, academic_opinion, civil_opinion, media_opinion)
    180 
    181         self.running = True
--> 182         self.datacollector.collect(self)
    183 
    184 

/usr/local/anaconda3/lib/python3.8/site-packages/mesa/datacollection.py in collect(self, model)
    189                     self.model_vars[var].append(reporter[0](*reporter[1]))
    190                 else:
--> 191                     self.model_vars[var].append(self._reporter_decorator(reporter))
    192 
    193         if self.agent_reporters:

/usr/local/anaconda3/lib/python3.8/site-packages/mesa/datacollection.py in _reporter_decorator(self, reporter)
    172 
    173     def _reporter_decorator(self, reporter):
--> 174         return reporter()
    175 
    176     def collect(self, model):

TypeError: 'int' object is not callable
  • 1
    This isn't a [mre] if we don't know what's in `SEmodel`, `network`, `chart`, or `model_parameters`. The issue could be the value of one of those variables, so I'm not sure how we could solve the issue if that's what it turns out to be. – Random Davis Apr 19 '21 at 15:28
  • Should I publish the whole code here ? – Julien Carbonnell Apr 20 '21 at 09:40
  • Not necessarily, look at that page I linked to get an idea of what kind of code you should show. It should be the smallest amount of code possible that still gives the same error. You can just manually assign example values to your variables, for instance, meaning you wouldn't need much code to set them up. – Random Davis Apr 20 '21 at 16:45

0 Answers0