|
6 | 6 | "source": [
|
7 | 7 | "# Tutorial: Reinforcement Learning with Mesa Environments\n",
|
8 | 8 | "\n",
|
9 |
| - "# Welcome to this comprehensive guide on integrating reinforcement learning (RL) with Mesa environments. \n", |
10 |
| - "# Mesa, an agent-based modeling framework, offers an excellent platform to experiment with RL algorithms. \n", |
11 |
| - "# In this tutorial, we'll explore several examples of how RL can be applied to various Mesa environments, \n", |
12 |
| - "# starting with the **Epstein Civil Violence model**.\n", |
13 |
| - "\n", |
14 |
| - "# ## Getting Started\n", |
| 9 | + "Welcome to this comprehensive guide on integrating reinforcement learning (RL) with Mesa environments. \n", |
| 10 | + "Mesa, an agent-based modeling framework, offers an excellent platform to experiment with RL algorithms. \n", |
| 11 | + "In this tutorial, we'll explore several examples of how RL can be applied to various Mesa environments, \n", |
| 12 | + "starting with the **Epstein Civil Violence model**." |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "markdown", |
| 17 | + "metadata": {}, |
| 18 | + "source": [ |
| 19 | + "## Getting Started\n", |
15 | 20 | "\n",
|
16 |
| - "# Before diving into the implementation, take a moment to familiarize yourself with the Epstein Civil Violence model.\n", |
17 |
| - "# This will give you a solid understanding of the environment we’ll be working with.\n", |
| 21 | + "Before diving into the implementation, take a moment to familiarize yourself with the Epstein Civil Violence model.\n", |
| 22 | + "This will give you a solid understanding of the environment we’ll be working with.\n", |
18 | 23 | "\n",
|
19 |
| - "# Next, ensure all dependencies are installed by following the instructions in the `README.md`.\n" |
| 24 | + "Next, ensure all dependencies are installed by following the instructions in the `README.md`." |
20 | 25 | ]
|
21 | 26 | },
|
22 | 27 | {
|
23 | 28 | "cell_type": "code",
|
24 |
| - "execution_count": null, |
| 29 | + "execution_count": 1, |
25 | 30 | "metadata": {},
|
26 |
| - "outputs": [], |
| 31 | + "outputs": [ |
| 32 | + { |
| 33 | + "name": "stdout", |
| 34 | + "output_type": "stream", |
| 35 | + "text": [ |
| 36 | + "WARNING:tensorflow:From C:\\Users\\thoma\\miniconda3\\envs\\mesa_dev\\Lib\\site-packages\\ray\\rllib\\utils\\framework.py:130: The name tf.logging.set_verbosity is deprecated. Please use tf.compat.v1.logging.set_verbosity instead.\n", |
| 37 | + "\n" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "ename": "ModuleNotFoundError", |
| 42 | + "evalue": "No module named 'mesa_models.epstein_civil_violence'", |
| 43 | + "output_type": "error", |
| 44 | + "traceback": [ |
| 45 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 46 | + "\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", |
| 47 | + "Cell \u001b[1;32mIn[1], line 5\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# ### Step 1: Importing the Necessary Modules\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# To begin, let’s import the required modules for the Epstein Civil Violence model:\u001b[39;00m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mepstein_civil_violence\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodel\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m EpsteinCivilViolenceRL\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mepstein_civil_violence\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mserver\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m run_model\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mepstein_civil_violence\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtrain_config\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m config\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtrain\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m train_model\n", |
| 48 | + "File \u001b[1;32m~\\Documents\\GitHub\\dev\\mesa-examples\\rl\\epstein_civil_violence\\server.py:4\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mnp\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mray\u001b[39;00m\n\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmesa_models\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mepstein_civil_violence\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mportrayal\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m citizen_cop_portrayal\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mray\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m tune\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mray\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mrllib\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01malgorithms\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01malgorithm\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Algorithm\n", |
| 49 | + "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'mesa_models.epstein_civil_violence'" |
| 50 | + ] |
| 51 | + } |
| 52 | + ], |
27 | 53 | "source": [
|
28 | 54 | "# ### Step 1: Importing the Necessary Modules\n",
|
29 | 55 | "# To begin, let’s import the required modules for the Epstein Civil Violence model:\n",
|
|
122 | 148 | "cell_type": "markdown",
|
123 | 149 | "metadata": {},
|
124 | 150 | "source": [
|
125 |
| - "# ### Alternative Approach: Using Stable-Baselines with Mesa\n", |
| 151 | + "# Alternative Approach: Using Stable-Baselines with Mesa\n", |
126 | 152 | "\n",
|
127 |
| - "# In the example above, we utilized RLlib to integrate reinforcement learning algorithms with the Mesa environment, \n", |
128 |
| - "# which is particularly useful when you want different policies for different agents. \n", |
129 |
| - "# However, if your use case requires a simpler setup where all agents follow the same policy, \n", |
130 |
| - "# you can opt for Stable-Baselines. An example of integrating Stable-Baselines with Mesa can be found in the Boltzmann Money model.\n", |
| 153 | + "In the example above, we utilized RLlib to integrate reinforcement learning algorithms with the Mesa environment, which is particularly useful when you want different policies for different agents. \n", |
| 154 | + "However, if your use case requires a simpler setup where all agents follow the same policy, you can opt for Stable-Baselines. An example of integrating Stable-Baselines with Mesa can be found in the Boltzmann Money model.\n", |
131 | 155 | "\n",
|
132 |
| - "# You can explore more on how to use Stable-Baselines with Mesa by following the respective documentation.\n" |
| 156 | + "You can explore more on how to use Stable-Baselines with Mesa by following the respective documentation.\n" |
133 | 157 | ]
|
134 | 158 | },
|
135 | 159 | {
|
136 | 160 | "cell_type": "markdown",
|
137 | 161 | "metadata": {},
|
138 | 162 | "source": [
|
139 |
| - "# ### Implementing Your Own Cases\n", |
| 163 | + "# Implementing Your Own RL Models\n", |
140 | 164 | "\n",
|
141 |
| - "# If you're ready to explore RL in different agent-based scenarios, you can start by experimenting with various examples we provide at Mesa-Examples:\n", |
142 |
| - "# Link: https://github.com/projectmesa/mesa-examples\n", |
| 165 | + "If you're ready to explore RL in different agent-based scenarios, you can start by experimenting with various examples we provide at Mesa-Examples:\n", |
| 166 | + "Link: https://github.com/projectmesa/mesa-examples\n", |
143 | 167 | "\n",
|
144 |
| - "# These examples cover a range of scenarios and offer a great starting point for understanding how to apply RL within Mesa environments.\n", |
| 168 | + "These examples cover a range of scenarios and offer a great starting point for understanding how to apply RL within Mesa environments.\n", |
145 | 169 | "\n",
|
146 |
| - "# If you have your own scenario in mind, you can create it as a Mesa model by following this series of Tutorials:\n", |
147 |
| - "# Link: https://mesa.readthedocs.io/en/stable/tutorials/intro_tutorial.html\n", |
| 170 | + "If you have your own scenario in mind, you can create it as a Mesa model by following this series of Tutorials:\n", |
| 171 | + "Link: https://mesa.readthedocs.io/en/stable/tutorials/intro_tutorial.html\n", |
148 | 172 | "\n",
|
149 |
| - "# Once your scenario is set up as a Mesa model, you can refer to the code in the provided implementations to see how the RL components are built on top of the respective Mesa models.\n" |
| 173 | + "Once your scenario is set up as a Mesa model, you can refer to the code in the provided implementations to see how the RL components are built on top of the respective Mesa models.\n" |
150 | 174 | ]
|
| 175 | + }, |
| 176 | + { |
| 177 | + "cell_type": "code", |
| 178 | + "execution_count": null, |
| 179 | + "metadata": {}, |
| 180 | + "outputs": [], |
| 181 | + "source": [] |
151 | 182 | }
|
152 | 183 | ],
|
153 | 184 | "metadata": {
|
154 | 185 | "kernelspec": {
|
155 |
| - "display_name": "test", |
| 186 | + "display_name": "Python 3 (ipykernel)", |
156 | 187 | "language": "python",
|
157 | 188 | "name": "python3"
|
158 | 189 | },
|
|
166 | 197 | "name": "python",
|
167 | 198 | "nbconvert_exporter": "python",
|
168 | 199 | "pygments_lexer": "ipython3",
|
169 |
| - "version": "3.10.0" |
| 200 | + "version": "3.12.5" |
170 | 201 | }
|
171 | 202 | },
|
172 | 203 | "nbformat": 4,
|
173 |
| - "nbformat_minor": 2 |
| 204 | + "nbformat_minor": 4 |
174 | 205 | }
|
0 commit comments