From 2ecd8ba935eb69be511f4a2194343f29192f4e6f Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Sat, 21 Sep 2024 09:48:58 +0200 Subject: [PATCH] Use performance optimized shuffle_do() method Replace shuffle().do() in 18 models with the performance optimized shuffle_do() method --- examples/aco_tsp/aco_tsp/model.py | 2 +- examples/bank_reserves/bank_reserves/model.py | 2 +- examples/bank_reserves/batch_run.py | 2 +- examples/boid_flockers/boid_flockers/model.py | 2 +- .../boltzmann_wealth_model/boltzmann_wealth_model/model.py | 2 +- examples/boltzmann_wealth_model_experimental/model.py | 2 +- .../boltzmann_wealth_model_network/model.py | 2 +- examples/caching_and_replay/model.py | 2 +- examples/charts/charts/model.py | 2 +- examples/el_farol/el_farol/model.py | 4 ++-- .../epstein_civil_violence/epstein_civil_violence/model.py | 2 +- examples/forest_fire/Forest Fire Model.ipynb | 2 +- examples/forest_fire/forest_fire/model.py | 2 +- examples/hotelling_law/hotelling_law/model.py | 2 +- examples/schelling/model.py | 2 +- examples/schelling_experimental/model.py | 2 +- examples/shape_example/shape_example/model.py | 2 +- examples/virus_on_network/virus_on_network/model.py | 2 +- 18 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/aco_tsp/aco_tsp/model.py b/examples/aco_tsp/aco_tsp/model.py index d69a0a19..a7b44f74 100644 --- a/examples/aco_tsp/aco_tsp/model.py +++ b/examples/aco_tsp/aco_tsp/model.py @@ -225,7 +225,7 @@ def step(self): """ A model step. Used for activating the agents and collecting data. """ - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") self.update_pheromone() # Check len of cities visited by an agent diff --git a/examples/bank_reserves/bank_reserves/model.py b/examples/bank_reserves/bank_reserves/model.py index 9fc78750..ae6b0a0f 100644 --- a/examples/bank_reserves/bank_reserves/model.py +++ b/examples/bank_reserves/bank_reserves/model.py @@ -152,7 +152,7 @@ def __init__( def step(self): # tell all the agents in the model to run their step function - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self) diff --git a/examples/bank_reserves/batch_run.py b/examples/bank_reserves/batch_run.py index 9b06ce3c..00b08a63 100644 --- a/examples/bank_reserves/batch_run.py +++ b/examples/bank_reserves/batch_run.py @@ -167,7 +167,7 @@ def step(self): # collect data self.datacollector.collect(self) # tell all the agents in the model to run their step function - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") def run_model(self): for i in range(self.run_time): diff --git a/examples/boid_flockers/boid_flockers/model.py b/examples/boid_flockers/boid_flockers/model.py index 312986bd..ae3099f3 100644 --- a/examples/boid_flockers/boid_flockers/model.py +++ b/examples/boid_flockers/boid_flockers/model.py @@ -143,4 +143,4 @@ def make_agents(self): self.space.place_agent(boid, pos) def step(self): - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") diff --git a/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py b/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py index 5c6d1f88..ac091a6c 100644 --- a/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py +++ b/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py @@ -38,7 +38,7 @@ def __init__(self, N=100, width=10, height=10): self.datacollector.collect(self) def step(self): - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self) diff --git a/examples/boltzmann_wealth_model_experimental/model.py b/examples/boltzmann_wealth_model_experimental/model.py index 5c6d1f88..ac091a6c 100644 --- a/examples/boltzmann_wealth_model_experimental/model.py +++ b/examples/boltzmann_wealth_model_experimental/model.py @@ -38,7 +38,7 @@ def __init__(self, N=100, width=10, height=10): self.datacollector.collect(self) def step(self): - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self) diff --git a/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py b/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py index 0fa71926..a61cf4bf 100644 --- a/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py +++ b/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py @@ -38,7 +38,7 @@ def __init__(self, num_agents=7, num_nodes=10): self.datacollector.collect(self) def step(self): - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self) diff --git a/examples/caching_and_replay/model.py b/examples/caching_and_replay/model.py index 50c15caf..e4bc23c7 100644 --- a/examples/caching_and_replay/model.py +++ b/examples/caching_and_replay/model.py @@ -93,7 +93,7 @@ def step(self): Run one step of the model. """ self.happy = 0 # Reset counter of happy agents - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") self.datacollector.collect(self) diff --git a/examples/charts/charts/model.py b/examples/charts/charts/model.py index c1bfb2e8..679f3176 100644 --- a/examples/charts/charts/model.py +++ b/examples/charts/charts/model.py @@ -135,7 +135,7 @@ def __init__( def step(self): # tell all the agents in the model to run their step function - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self) diff --git a/examples/el_farol/el_farol/model.py b/examples/el_farol/el_farol/model.py index c3c08b3c..a57d5de5 100644 --- a/examples/el_farol/el_farol/model.py +++ b/examples/el_farol/el_farol/model.py @@ -34,9 +34,9 @@ def __init__( def step(self): self.datacollector.collect(self) self.attendance = 0 - self.agents.shuffle().do("update_attendance") + self.agents.shuffle_do("update_attendance") # We ensure that the length of history is constant # after each step. self.history.pop(0) self.history.append(self.attendance) - self.agents.shuffle().do("update_strategies") + self.agents.shuffle_do("update_strategies") diff --git a/examples/epstein_civil_violence/epstein_civil_violence/model.py b/examples/epstein_civil_violence/epstein_civil_violence/model.py index 75b7791c..b278f23e 100644 --- a/examples/epstein_civil_violence/epstein_civil_violence/model.py +++ b/examples/epstein_civil_violence/epstein_civil_violence/model.py @@ -105,7 +105,7 @@ def step(self): """ Advance the model by one step and collect data. """ - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self) self.iteration += 1 diff --git a/examples/forest_fire/Forest Fire Model.ipynb b/examples/forest_fire/Forest Fire Model.ipynb index 47672f0b..189672ed 100644 --- a/examples/forest_fire/Forest Fire Model.ipynb +++ b/examples/forest_fire/Forest Fire Model.ipynb @@ -149,7 +149,7 @@ " \"\"\"\n", " Advance the model by one step.\n", " \"\"\"\n", - " self.agents.shuffle().do(\"step\")\n", + " self.agents.shuffle_do(\"step\")\n", " self.dc.collect(self)\n", " # Halt if no more fire\n", " if self.count_type(self, \"On Fire\") == 0:\n", diff --git a/examples/forest_fire/forest_fire/model.py b/examples/forest_fire/forest_fire/model.py index f035df6e..e23a9e9e 100644 --- a/examples/forest_fire/forest_fire/model.py +++ b/examples/forest_fire/forest_fire/model.py @@ -46,7 +46,7 @@ def step(self): """ Advance the model by one step. """ - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self) diff --git a/examples/hotelling_law/hotelling_law/model.py b/examples/hotelling_law/hotelling_law/model.py index e0dc3b41..d2bc19bc 100644 --- a/examples/hotelling_law/hotelling_law/model.py +++ b/examples/hotelling_law/hotelling_law/model.py @@ -216,7 +216,7 @@ def step(self): # Collect data for the current step. self.datacollector.collect(self) # Activate all agents in random order - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # Update market dynamics based on the latest actions self.recalculate_market_share() diff --git a/examples/schelling/model.py b/examples/schelling/model.py index aec6d5b5..e995f31e 100644 --- a/examples/schelling/model.py +++ b/examples/schelling/model.py @@ -91,7 +91,7 @@ def step(self): Run one step of the model. """ self.happy = 0 # Reset counter of happy agents - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") self.datacollector.collect(self) diff --git a/examples/schelling_experimental/model.py b/examples/schelling_experimental/model.py index 5358eb64..d7239a97 100644 --- a/examples/schelling_experimental/model.py +++ b/examples/schelling_experimental/model.py @@ -64,7 +64,7 @@ def step(self): Run one step of the model. If All agents are happy, halt the model. """ self.happy = 0 # Reset counter of happy agents - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self) diff --git a/examples/shape_example/shape_example/model.py b/examples/shape_example/shape_example/model.py index 0333e236..2fa82fd7 100644 --- a/examples/shape_example/shape_example/model.py +++ b/examples/shape_example/shape_example/model.py @@ -36,4 +36,4 @@ def make_walker_agents(self): unique_id += 1 def step(self): - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") diff --git a/examples/virus_on_network/virus_on_network/model.py b/examples/virus_on_network/virus_on_network/model.py index 2df667bc..d892a0c4 100644 --- a/examples/virus_on_network/virus_on_network/model.py +++ b/examples/virus_on_network/virus_on_network/model.py @@ -95,7 +95,7 @@ def resistant_susceptible_ratio(self): return math.inf def step(self): - self.agents.shuffle().do("step") + self.agents.shuffle_do("step") # collect data self.datacollector.collect(self)