-
Notifications
You must be signed in to change notification settings - Fork 929
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
Comments
Is the sole purpose of the utility function to create an AgentSet where the agents have If this Is the case, then there is no need to create this utility because of fixing #2213? |
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 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 |
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. |
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. |
is this issue still open? |
@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. |
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:
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.
The text was updated successfully, but these errors were encountered: