Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesa Backend Problems #313

Closed
DevPy129387 opened this issue Feb 8, 2024 · 5 comments · Fixed by #314
Closed

Mesa Backend Problems #313

DevPy129387 opened this issue Feb 8, 2024 · 5 comments · Fixed by #314

Comments

@DevPy129387
Copy link

I installed agentMet4Fof today (with pip install agentmet4fof). I use Python 3.11 on a Windows 10 PC.
When I try Tutorial06 I get the following error: 'NoneType' object has no attribute 'agents_'

Traceback (most recent call last):
  File "D:\Anaconda\envs\Agents\Lib\site-packages\mesa\agent.py", line 53, in __init__
    self.model.agents_[type(self)][self] = None
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'agents_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Dokumente\Projekte\AGENT4Heat_meins\MAS\agentMET4FOF\agentMET4FOFtest\Tutorial06_changeToMesa.py", line 23, in <module>
    demonstrate_mesa_backend()
  File "D:\Dokumente\Projekte\AGENT4Heat_meins\MAS\agentMET4FOF\agentMET4FOFtest\Tutorial06_changeToMesa.py", line 9, in demonstrate_mesa_backend
    _agent_network = AgentNetwork(backend=Backend.MESA)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\Agents\Lib\site-packages\agentMET4FOF\network.py", line 597, in __init__
    self.start_server_mesa()
  File "D:\Anaconda\envs\Agents\Lib\site-packages\agentMET4FOF\network.py", line 688, in start_server_mesa
    self._controller = self._AgentController(
                       ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\Agents\Lib\site-packages\agentMET4FOF\agents\base_agents.py", line 63, in __init__
    MesaAgent.__init__(self, name, mesa_model)
  File "D:\Anaconda\envs\Agents\Lib\site-packages\mesa\agent.py", line 56, in __init__
    self.model.agents_ = defaultdict(dict)
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'agents_'
@BjoernLudwigPTB
Copy link
Member

Hi! Sorry for the delay. You seem to have customized the code somehow, as the file names and locations seem to differ from the default. Could you please share the content of Tutorial06_changeToMesa.py?

@DevPy129387
Copy link
Author

Hi!
I copied the code from https://agentmet4fof.readthedocs.io/en/latest/agentMET4FOF_tutorials/tutorial_6_mesa_backend.html into a *.py file and tried to run it.

# %load tutorial_6_mesa_backend.py
from agentMET4FOF.agents import AgentNetwork, MonitorAgent, SineGeneratorAgent
from agentMET4FOF.utils import Backend


def demonstrate_mesa_backend():

    # Start agent network and specify backend via the corresponding keyword parameter.
    _agent_network = AgentNetwork(backend=Backend.MESA)

    # Initialize agents by adding them to the agent network.
    sine_agent = _agent_network.add_agent(agentType=SineGeneratorAgent)
    monitor_agent = _agent_network.add_agent(agentType=MonitorAgent, buffer_size=200)
    sine_agent.bind_output(monitor_agent)

    # Set all agents states to "Running".
    _agent_network.set_running_state()

    return _agent_network


if __name__ == "__main__":
    demonstrate_mesa_backend()

I also tried to run the tutorial from the tutdorial-dir. I get the same output:

Traceback (most recent call last):
  File "D:\Anaconda\envs\Agents\Lib\site-packages\mesa\agent.py", line 53, in __init__
    self.model.agents_[type(self)][self] = None
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'agents_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Anaconda\envs\Agents\Lib\site-packages\agentMET4FOF_tutorials\tutorial_6_mesa_backend.py", line 22, in <module>
    demonstrate_mesa_backend()
  File "D:\Anaconda\envs\Agents\Lib\site-packages\agentMET4FOF_tutorials\tutorial_6_mesa_backend.py", line 8, in demonstrate_mesa_backend
    _agent_network = AgentNetwork(backend=Backend.MESA)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\Agents\Lib\site-packages\agentMET4FOF\network.py", line 597, in __init__
    self.start_server_mesa()
  File "D:\Anaconda\envs\Agents\Lib\site-packages\agentMET4FOF\network.py", line 688, in start_server_mesa
    self._controller = self._AgentController(
                       ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\Agents\Lib\site-packages\agentMET4FOF\agents\base_agents.py", line 63, in __init__
    MesaAgent.__init__(self, name, mesa_model)
  File "D:\Anaconda\envs\Agents\Lib\site-packages\mesa\agent.py", line 56, in __init__
    self.model.agents_ = defaultdict(dict)
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'agents_'

@BjoernLudwigPTB
Copy link
Member

I am so sorry for the long delay. It seems that there arises some compatibility issue from a new release of mesa or some of the current versions of the dependencies. The error is reproducible in our CI environment since two months. I will look into this deeper in two weeks time about, but for now, you should be able ti fix your problem by following these steps:

  1. Inside of your Python environment (which hopefully is virtual environment exclusively for your agentMET4FOF project) install pip-tools:
    $ python -m pip install pip-tools
  2. Sync your dependencies with the pinned known to work versions from your repository's root folder:
    $ python -m piptools sync

This should clear all packages from the environment, which are not mentioned in our requirements.txt file and install otherwise all the packages mentioned in the respective versions.

Then please try again to run the tutorial. Everything should work as expected.

@BjoernLudwigPTB
Copy link
Member

@DevPy129387 Were you able to try our fix?

@DevPy129387
Copy link
Author

DevPy129387 commented Apr 18, 2024

Unfortunately I didn't try this fix. While waiting for a solution for this problem we decided to use another framework. Thanks for your advice.

@BjoernLudwigPTB BjoernLudwigPTB linked a pull request May 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants