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

Allow creating multiple agents directly #2221

Open
EwoutH opened this issue Aug 17, 2024 · 7 comments
Open

Allow creating multiple agents directly #2221

EwoutH opened this issue Aug 17, 2024 · 7 comments
Labels
feature Release notes label

Comments

@EwoutH
Copy link
Member

EwoutH commented Aug 17, 2024

It would be nice if there was some utility function to create multiple agents directly (via the AgentSet or the model).

This shouldn't be needed, for example:

        for i in range(self.num_agents):
            BarCustomer(i, self, memory_size, crowd_threshold, num_strategies)

Loops might still be nice if you want to create complicated agents and positon them etc, but an elegant alternative should be present in the AgentSet or model for really simple operations.

@GittyHarsha
Copy link

Is the sole purpose of the utility function to create an AgentSet where the agents have unique_id's [0, 1, 2, .... num_agents-1]?

If this Is the case, then there is no need to create this utility because of fixing #2213?

@EwoutH
Copy link
Member Author

EwoutH commented Aug 19, 2024

I mainly think loops are unnecessary in most cases, but solving #2213 first would help with this issue, since you don't need to input an unique_id anymore.

I don't have a clear user API in mind as this point. There could also be a bit of discussion where this code should take place (model, agent, agentset or other).

@adamamer20 how do you populate the AgentSet / create multiple agents in Mesa-frames?

@adamamer20
Copy link
Collaborator

I mainly think loops are unnecessary in most cases, but solving #2213 first would help with this issue, since you don't need to input an unique_id anymore.

I don't have a clear user API in mind as this point. There could also be a bit of discussion where this code should take place (model, agent, agentset or other).

@adamamer20 how do you populate the AgentSet / create multiple agents in Mesa-frames?

The syntax is AgentSet.add(agents) or AgentSet + agents or AgentSet += agents where agents is anything that could be constructed into a DF (so a dictionary, a sequence of sequences or a DF itself). It must have a 'unique_id' integer column or if sequence of sequences it will try to take the first value as unique_id.

An example would be:

df = pd.DataFrame({'unique_id': [0, 1, 2], 'sugar': [0, 3, 5]})
AgentSetDF.add(df)
# equivalent to 
AgentSetDF += df
# equivalent to (although a bit slower because creates a copy) 
AgentSetDF = AgentSetDF + df

@quaquel
Copy link
Member

quaquel commented Aug 19, 2024

Loops might still be nice if you want to create complicated agents and positon them etc, but an elegant alternative should be present in the AgentSet or model for really simple operations.

I mainly think loops are unnecessary in most cases, but solving #2213 first would help with this issue, since you don't need to input an unique_id anymore.

The default way to solve this is some kind of factory method/factory pattern. In python, one way to do it is through a factory class method. It will be hard, however, to fully standardize this given the degrees of freedom users have in defining their own Agent subclasses. A factory method is typically a class level method and the API could look something like this

Agent.create_agents(SomeBaseAgentClass, model, dataframe_with_attributes)

Not sure what you mean about loops not being necessary because any factory will have some internal loop to create each individual agent.

@EwoutH
Copy link
Member Author

EwoutH commented Aug 19, 2024

Thanks for both your insights! I'm not sure if this can be implemented more intuitively than the current best-practice of just looping.

Certainly not a priority, let's focus on more valuable features for now.

@advait-zx
Copy link

is this issue still open?

@EwoutH
Copy link
Member Author

EwoutH commented Sep 19, 2024

@advait-zx yes, but I'm not sure if "good first issue" is still representative of the difficulty of this issue. If you want to tackle this, please first discuss your proposed API here with us.

@quaquel quaquel added feature Release notes label and removed good first issue labels Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Release notes label
Projects
None yet
Development

No branches or pull requests

5 participants