From 3b726dd3e43c2b565139f8fa4915528a856ca82e Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Fri, 20 Sep 2024 14:20:49 +0200 Subject: [PATCH] Explicit datacollector import --- examples/bank_reserves/bank_reserves/model.py | 2 +- examples/bank_reserves/batch_run.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 | 2 +- .../epstein_civil_violence/epstein_civil_violence/model.py | 2 +- examples/forest_fire/forest_fire/model.py | 2 +- examples/pd_grid/pd_grid/model.py | 2 +- examples/schelling/model.py | 2 +- examples/schelling_experimental/model.py | 2 +- examples/sugarscape_cg/sugarscape_cg/model.py | 2 +- examples/sugarscape_g1mt/sugarscape_g1mt/model.py | 2 +- examples/virus_on_network/virus_on_network/model.py | 2 +- examples/wolf_sheep/wolf_sheep/model.py | 2 +- gis/agents_and_networks/src/model/model.py | 4 ++-- gis/geo_schelling/model.py | 2 +- gis/geo_schelling_points/geo_schelling_points/model.py | 2 +- gis/geo_sir/model.py | 2 +- gis/rainfall/rainfall/model.py | 2 +- 22 files changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/bank_reserves/bank_reserves/model.py b/examples/bank_reserves/bank_reserves/model.py index 9fc78750..0c6eb820 100644 --- a/examples/bank_reserves/bank_reserves/model.py +++ b/examples/bank_reserves/bank_reserves/model.py @@ -122,7 +122,7 @@ def __init__( self.rich_threshold = rich_threshold self.reserve_percent = reserve_percent # see datacollector functions above - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={ "Rich": get_num_rich_agents, "Poor": get_num_poor_agents, diff --git a/examples/bank_reserves/batch_run.py b/examples/bank_reserves/batch_run.py index 9b06ce3c..a69d920c 100644 --- a/examples/bank_reserves/batch_run.py +++ b/examples/bank_reserves/batch_run.py @@ -133,7 +133,7 @@ def __init__( self.rich_threshold = rich_threshold self.reserve_percent = reserve_percent # see datacollector functions above - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={ "Rich": get_num_rich_agents, "Poor": get_num_poor_agents, diff --git a/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py b/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py index 5c6d1f88..27b44503 100644 --- a/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py +++ b/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py @@ -22,7 +22,7 @@ def __init__(self, N=100, width=10, height=10): self.num_agents = N self.grid = mesa.space.MultiGrid(width, height, True) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"} ) # Create agents diff --git a/examples/boltzmann_wealth_model_experimental/model.py b/examples/boltzmann_wealth_model_experimental/model.py index 5c6d1f88..27b44503 100644 --- a/examples/boltzmann_wealth_model_experimental/model.py +++ b/examples/boltzmann_wealth_model_experimental/model.py @@ -22,7 +22,7 @@ def __init__(self, N=100, width=10, height=10): self.num_agents = N self.grid = mesa.space.MultiGrid(width, height, True) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"} ) # Create agents 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..2d1a9924 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 @@ -20,7 +20,7 @@ def __init__(self, num_agents=7, num_nodes=10): self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=0.5) self.grid = mesa.space.NetworkGrid(self.G) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": lambda _: _.wealth}, ) diff --git a/examples/caching_and_replay/model.py b/examples/caching_and_replay/model.py index 50c15caf..b70ab4d0 100644 --- a/examples/caching_and_replay/model.py +++ b/examples/caching_and_replay/model.py @@ -72,7 +72,7 @@ def __init__( self.grid = mesa.space.SingleGrid(width, height, torus=True) self.happy = 0 - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={"happy": "happy"}, # Model-level count of happy agents ) diff --git a/examples/charts/charts/model.py b/examples/charts/charts/model.py index c1bfb2e8..0c65695d 100644 --- a/examples/charts/charts/model.py +++ b/examples/charts/charts/model.py @@ -105,7 +105,7 @@ def __init__( self.rich_threshold = rich_threshold self.reserve_percent = reserve_percent # see datacollector functions above - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={ "Rich": get_num_rich_agents, "Poor": get_num_poor_agents, diff --git a/examples/el_farol/el_farol/model.py b/examples/el_farol/el_farol/model.py index c3c08b3c..c0e73a5f 100644 --- a/examples/el_farol/el_farol/model.py +++ b/examples/el_farol/el_farol/model.py @@ -26,7 +26,7 @@ def __init__( for _ in range(self.num_agents): BarCustomer(self, memory_size, crowd_threshold, num_strategies) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={"Customers": "attendance"}, agent_reporters={"Utility": "utility", "Attendance": "attend"}, ) diff --git a/examples/epstein_civil_violence/epstein_civil_violence/model.py b/examples/epstein_civil_violence/epstein_civil_violence/model.py index 75b7791c..84bfa9c2 100644 --- a/examples/epstein_civil_violence/epstein_civil_violence/model.py +++ b/examples/epstein_civil_violence/epstein_civil_violence/model.py @@ -75,7 +75,7 @@ def __init__( "condition": lambda a: getattr(a, "condition", None), "arrest_probability": lambda a: getattr(a, "arrest_probability", None), } - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters=model_reporters, agent_reporters=agent_reporters ) if self.cop_density + self.citizen_density > 1: diff --git a/examples/forest_fire/forest_fire/model.py b/examples/forest_fire/forest_fire/model.py index f035df6e..3d308902 100644 --- a/examples/forest_fire/forest_fire/model.py +++ b/examples/forest_fire/forest_fire/model.py @@ -21,7 +21,7 @@ def __init__(self, width=100, height=100, density=0.65): self.grid = mesa.space.SingleGrid(width, height, torus=False) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( { "Fine": lambda m: self.count_type(m, "Fine"), "On Fire": lambda m: self.count_type(m, "On Fire"), diff --git a/examples/pd_grid/pd_grid/model.py b/examples/pd_grid/pd_grid/model.py index cf3512ad..1d710a8b 100644 --- a/examples/pd_grid/pd_grid/model.py +++ b/examples/pd_grid/pd_grid/model.py @@ -41,7 +41,7 @@ def __init__( self.grid.place_agent(agent, (x, y)) self.schedule.add(agent) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( { "Cooperating_Agents": lambda m: len( [a for a in m.schedule.agents if a.move == "C"] diff --git a/examples/schelling/model.py b/examples/schelling/model.py index aec6d5b5..6621ba09 100644 --- a/examples/schelling/model.py +++ b/examples/schelling/model.py @@ -70,7 +70,7 @@ def __init__( self.grid = mesa.space.SingleGrid(width, height, torus=True) self.happy = 0 - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={"happy": "happy"}, # Model-level count of happy agents ) diff --git a/examples/schelling_experimental/model.py b/examples/schelling_experimental/model.py index 5358eb64..dc99cace 100644 --- a/examples/schelling_experimental/model.py +++ b/examples/schelling_experimental/model.py @@ -43,7 +43,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily= self.grid = mesa.space.SingleGrid(width, height, torus=True) self.happy = 0 - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( {"happy": "happy"}, # Model-level count of happy agents ) diff --git a/examples/sugarscape_cg/sugarscape_cg/model.py b/examples/sugarscape_cg/sugarscape_cg/model.py index 1436adb9..7d9a35b6 100644 --- a/examples/sugarscape_cg/sugarscape_cg/model.py +++ b/examples/sugarscape_cg/sugarscape_cg/model.py @@ -39,7 +39,7 @@ def __init__(self, width=50, height=50, initial_population=100): self.schedule = mesa.time.RandomActivationByType(self) self.grid = mesa.space.MultiGrid(self.width, self.height, torus=False) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( {"SsAgent": lambda m: m.schedule.get_type_count(SsAgent)} ) diff --git a/examples/sugarscape_g1mt/sugarscape_g1mt/model.py b/examples/sugarscape_g1mt/sugarscape_g1mt/model.py index 91bb001d..cdaf4090 100644 --- a/examples/sugarscape_g1mt/sugarscape_g1mt/model.py +++ b/examples/sugarscape_g1mt/sugarscape_g1mt/model.py @@ -71,7 +71,7 @@ def __init__( # initiate mesa grid class self.grid = mesa.space.MultiGrid(self.width, self.height, torus=False) # initiate datacollector - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={ "Trader": lambda m: len(m.agents_by_type[Trader]), "Trade Volume": lambda m: sum( diff --git a/examples/virus_on_network/virus_on_network/model.py b/examples/virus_on_network/virus_on_network/model.py index 2df667bc..5f9fb796 100644 --- a/examples/virus_on_network/virus_on_network/model.py +++ b/examples/virus_on_network/virus_on_network/model.py @@ -56,7 +56,7 @@ def __init__( self.recovery_chance = recovery_chance self.gain_resistance_chance = gain_resistance_chance - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( { "Infected": number_infected, "Susceptible": number_susceptible, diff --git a/examples/wolf_sheep/wolf_sheep/model.py b/examples/wolf_sheep/wolf_sheep/model.py index 85b60b73..681845eb 100644 --- a/examples/wolf_sheep/wolf_sheep/model.py +++ b/examples/wolf_sheep/wolf_sheep/model.py @@ -88,7 +88,7 @@ def __init__( if grass: collectors["Grass"] = lambda m: len(m.agents_by_type[GrassPatch]) - self.datacollector = mesa.DataCollector(collectors) + self.datacollector = mesa.datacollection.DataCollector(collectors) # Create sheep: for i in range(self.initial_sheep): diff --git a/gis/agents_and_networks/src/model/model.py b/gis/agents_and_networks/src/model/model.py index 4fad3fe0..53920092 100644 --- a/gis/agents_and_networks/src/model/model.py +++ b/gis/agents_and_networks/src/model/model.py @@ -58,7 +58,7 @@ class AgentsAndNetworks(mesa.Model): day: int hour: int minute: int - datacollector: mesa.DataCollector + datacollector: mesa.datacollection.DataCollector def __init__( self, @@ -114,7 +114,7 @@ def __init__( self._load_lakes_and_rivers_from_file(lakes_file, crs=model_crs) self._load_lakes_and_rivers_from_file(rivers_file, crs=model_crs) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( model_reporters={ "time": get_time, "status_home": partial(get_num_commuters_by_status, status="home"), diff --git a/gis/geo_schelling/model.py b/gis/geo_schelling/model.py index 613a7e59..d063cb2b 100644 --- a/gis/geo_schelling/model.py +++ b/gis/geo_schelling/model.py @@ -81,7 +81,7 @@ def __init__(self, density=0.6, minority_pc=0.2, export_data=False): self.space = mg.GeoSpace(warn_crs_conversion=False) self.happy = 0 - self.datacollector = mesa.DataCollector({"happy": "happy"}) + self.datacollector = mesa.datacollection.DataCollector({"happy": "happy"}) self.running = True diff --git a/gis/geo_schelling_points/geo_schelling_points/model.py b/gis/geo_schelling_points/geo_schelling_points/model.py index 5031eb1e..deff5e03 100644 --- a/gis/geo_schelling_points/geo_schelling_points/model.py +++ b/gis/geo_schelling_points/geo_schelling_points/model.py @@ -21,7 +21,7 @@ def __init__(self, red_percentage=0.5, similarity_threshold=0.5): self.schedule = mesa.time.RandomActivation(self) self.space = Nuts2Eu() - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( {"unhappy": "unhappy", "happy": "happy"} ) diff --git a/gis/geo_sir/model.py b/gis/geo_sir/model.py index 093cd236..866423b4 100644 --- a/gis/geo_sir/model.py +++ b/gis/geo_sir/model.py @@ -42,7 +42,7 @@ def __init__( self.infection_risk = infection_risk self.running = True - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( { "infected": get_infected_count, "susceptible": get_susceptible_count, diff --git a/gis/rainfall/rainfall/model.py b/gis/rainfall/rainfall/model.py index 36d363ab..f33a7cc9 100644 --- a/gis/rainfall/rainfall/model.py +++ b/gis/rainfall/rainfall/model.py @@ -68,7 +68,7 @@ def __init__(self, rain_rate=500, water_height=5, export_data=False, num_steps=2 self.space = CraterLake(crs="epsg:4326", water_height=water_height, model=self) self.schedule = mesa.time.RandomActivation(self) - self.datacollector = mesa.DataCollector( + self.datacollector = mesa.datacollection.DataCollector( { "Total Amount of Water": "water_amount", "Total Contained": "contained",