Skip to content

Commit 24ed675

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1ce0453 commit 24ed675

4 files changed

Lines changed: 18 additions & 20 deletions

File tree

examples/dining_philosophers/dining_philosophers/model.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,13 @@ def __init__(
7979
p_id = i * 2
8080

8181
# Use default argument in lambda to capture the current value of p_id
82-
model_reporters[f"P{i}"] = lambda m, pid=p_id: (
83-
next(
84-
(
85-
p.total_eaten
86-
for p in m.agents_by_type[PhilosopherAgent]
87-
if p.position == pid
88-
),
89-
0,
90-
)
82+
model_reporters[f"P{i}"] = lambda m, pid=p_id: next(
83+
(
84+
p.total_eaten
85+
for p in m.agents_by_type[PhilosopherAgent]
86+
if p.position == pid
87+
),
88+
0,
9189
)
9290

9391
self.datacollector = mesa.DataCollector(model_reporters=model_reporters)

examples/forest_fire/Forest Fire Model.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
"evalue": "cannot import name 'BatchRunner' from 'mesa.batchrunner' (/Users/jhkwakkel/Documents/GitHub/mesa/mesa/batchrunner.py)",
3737
"output_type": "error",
3838
"traceback": [
39-
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
40-
"\u001B[0;31mImportError\u001B[0m Traceback (most recent call last)",
41-
"Cell \u001B[0;32mIn[2], line 7\u001B[0m\n\u001B[1;32m 4\u001B[0m get_ipython()\u001B[38;5;241m.\u001B[39mrun_line_magic(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mmatplotlib\u001B[39m\u001B[38;5;124m'\u001B[39m, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124minline\u001B[39m\u001B[38;5;124m'\u001B[39m)\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mmesa\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m Model\n\u001B[0;32m----> 7\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mmesa\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mbatchrunner\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m BatchRunner\n\u001B[1;32m 8\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mmesa\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mdatacollection\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m DataCollector\n",
42-
"\u001B[0;31mImportError\u001B[0m: cannot import name 'BatchRunner' from 'mesa.batchrunner' (/Users/jhkwakkel/Documents/GitHub/mesa/mesa/batchrunner.py)"
39+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
40+
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
41+
"Cell \u001b[0;32mIn[2], line 7\u001b[0m\n\u001b[1;32m 4\u001b[0m get_ipython()\u001b[38;5;241m.\u001b[39mrun_line_magic(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmatplotlib\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124minline\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmesa\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Model\n\u001b[0;32m----> 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmesa\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mbatchrunner\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BatchRunner\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmesa\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdatacollection\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m DataCollector\n",
42+
"\u001b[0;31mImportError\u001b[0m: cannot import name 'BatchRunner' from 'mesa.batchrunner' (/Users/jhkwakkel/Documents/GitHub/mesa/mesa/batchrunner.py)"
4343
]
4444
}
4545
],
@@ -348,7 +348,7 @@
348348
"source": [
349349
"# At the end of each model run, calculate the fraction of trees which are Burned Out\n",
350350
"model_reporter = {\n",
351-
" \"BurnedOut\": lambda m: (ForestFire.count_type(m, \"Burned Out\") / len(m.agents))\n",
351+
" \"BurnedOut\": lambda m: ForestFire.count_type(m, \"Burned Out\") / len(m.agents)\n",
352352
"}"
353353
]
354354
},

rl/epstein_civil_violence/train_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def env_creator(_):
2929
"policy_cop": PolicySpec(config=PPOConfig.overrides(framework_str="torch")),
3030
"policy_citizen": PolicySpec(config=PPOConfig.overrides(framework_str="torch")),
3131
},
32-
"policy_mapping_fn": lambda agent_id, *args, **kwargs: "policy_cop"
33-
if agent_id[0:3] == "cop"
34-
else "policy_citizen",
32+
"policy_mapping_fn": lambda agent_id, *args, **kwargs: (
33+
"policy_cop" if agent_id[0:3] == "cop" else "policy_citizen"
34+
),
3535
"policies_to_train": ["policy_cop", "policy_citizen"],
3636
"num_gpus": int(os.environ.get("RLLIB_NUM_GPUS", "1")),
3737
"num_learners": 50,

rl/wolf_sheep/train_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def env_creator(_):
3131
"policy_sheep": PolicySpec(config=PPOConfig.overrides(framework_str="torch")),
3232
"policy_wolf": PolicySpec(config=PPOConfig.overrides(framework_str="torch")),
3333
},
34-
"policy_mapping_fn": lambda agent_id, *args, **kwargs: "policy_sheep"
35-
if agent_id[0:5] == "sheep"
36-
else "policy_wolf",
34+
"policy_mapping_fn": lambda agent_id, *args, **kwargs: (
35+
"policy_sheep" if agent_id[0:5] == "sheep" else "policy_wolf"
36+
),
3737
"policies_to_train": ["policy_sheep", "policy_wolf"],
3838
"num_gpus": int(os.environ.get("RLLIB_NUM_GPUS", "1")),
3939
"num_learners": 50, # Assuming a default value, adjust as necessary

0 commit comments

Comments
 (0)