GithubHelp home page GithubHelp logo

Comments (14)

EwoutH avatar EwoutH commented on June 5, 2024 1

Thanks for reaching out. I will test this tomorrow morning, if no one else has done it by then.

Furthermore if I not call super().init() in the model class, the first agent is not added to the scheduler.

Calling super().__init__() was always recommended, but now it’s required. It initializes Model.agents among other things. You’re using the Mesa Model class, so you should properly initialize it.

from mesa.

EwoutH avatar EwoutH commented on June 5, 2024 1

I've narrowed it down to the fact that the AgentSet's shuffle(inplace=True) doesn't shuffle the agents. Could be because the shuffle isn't working, or the in place updating isn't.

mesa/mesa/time.py

Lines 144 to 147 in 99b35fc

def do_each(self, method, shuffle=False):
if shuffle:
self.agents.shuffle(inplace=True)
self.agents.do(method)

Screenshot_366

from mesa.

EwoutH avatar EwoutH commented on June 5, 2024 1

It's the inplace updating that isn't working. Without it, it works correctly:

Screenshot_367

@quaquel you wrote this code and know more about the AgentSet implementation. Could assist in fixing the inplace updating?

from mesa.

EwoutH avatar EwoutH commented on June 5, 2024 1

@profConradi we just released Mesa 2.2.4 which should fix this issue. Could you confirm this is the case?

from mesa.

profConradi avatar profConradi commented on June 5, 2024 1

Yes, the RandomActivation Scheduler of 2.2.4 works correctly! Thanks!

from mesa.

EwoutH avatar EwoutH commented on June 5, 2024 1

Great to hear, thanks a lot for reporting this issue!

For such a serious bug to slip thought the the review, test and release process is really unfortunate. I wrote some thoughts on it here: #1909 (comment)

from mesa.

EwoutH avatar EwoutH commented on June 5, 2024

@rht do you have time to investigate this?

from mesa.

rht avatar rht commented on June 5, 2024

I'd need some help debugging all the problems caused by 2.1.x -> 2.2.x. Hands are full with elsewhere.

from mesa.

EwoutH avatar EwoutH commented on June 5, 2024

Unfortunately, I can reproduce this issue for both Mesa 2.2.0 and 2.2.3, while the correct behavior (shuffled agent steps) on Mesa 2.1.5. @projectmesa/maintainers this is a major issue and needs immediate care, we broke RandomActivation.

I will investigate further.

from mesa.

profConradi avatar profConradi commented on June 5, 2024

Thanks for your work, Mesa is an amazing framework!

from mesa.

quaquel avatar quaquel commented on June 5, 2024

I can try this afternoon. I don't see an obvious mistake in the code.

AgentSet.shuffle

        shuffled_agents = list(self)
        self.random.shuffle(shuffled_agents)

        return (
            AgentSet(shuffled_agents, self.model)
            if not inplace
            else self._update(shuffled_agents)
        )

random.shuffle is inplace. List(self) returns a list of hard refs to the agents.

AgentSet._update

    def _update(self, agents: Iterable[Agent]):
        """Update the AgentSet with a new set of agents.
        This is a private method primarily used internally by other methods like select, shuffle, and sort.
        """

        self._agents = weakref.WeakKeyDictionary({agent: None for agent in agents})
        return self

We create a new WeakKeyDictionary so it should shuffle.

Accidentally, This is the code I was playing with for #1993. So my to do;

  • add a unittest that reproduces the error
  • figure out why the error exists, because based on the code I don't
  • test my fix from #1993

from mesa.

EwoutH avatar EwoutH commented on June 5, 2024

Thanks. I had already written an additional unittest for RandomActivation itself, we can test updates also against that (#2007).

from mesa.

quaquel avatar quaquel commented on June 5, 2024

Found it. The problem is in the scheduler not in AgentSet.

do_each should be

    def do_each(self, method, shuffle=False):
        if shuffle:
            self._agents.shuffle(inplace=True)
        self._agents.do(method)

from mesa.

quaquel avatar quaquel commented on June 5, 2024

I committed the fix to #2007.

from mesa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.