Skip to content

Commit b25e8ca

Browse files
committed
Add docstrings and comments
1 parent 1db02a9 commit b25e8ca

File tree

2 files changed

+21
-73
lines changed

2 files changed

+21
-73
lines changed

pettingzoo-unity/Colab_PettingZoo.ipynb

+5-65
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
11
{
2-
"nbformat": 4,
3-
"nbformat_minor": 0,
4-
"metadata": {
5-
"colab": {
6-
"name": "Colab-PettingZoo-Unity.ipynb",
7-
"private_outputs": true,
8-
"provenance": [],
9-
"collapsed_sections": [],
10-
"toc_visible": true
11-
},
12-
"kernelspec": {
13-
"name": "python3",
14-
"display_name": "Python 3.7.11 64-bit ('pettingzoo': conda)",
15-
"metadata": {
16-
"interpreter": {
17-
"hash": "5d8bf1ccad4050d475e9ef008ff2de5ee0b8bb440e3e2ef203ad7e8f5a9e706b"
18-
}
19-
}
20-
},
21-
"pycharm": {
22-
"stem_cell": {
23-
"cell_type": "raw",
24-
"source": [],
25-
"metadata": {
26-
"collapsed": false
27-
}
28-
}
29-
}
30-
},
312
"cells": [
323
{
334
"cell_type": "markdown",
@@ -45,32 +16,9 @@
4516
},
4617
{
4718
"cell_type": "code",
48-
"execution_count": 1,
49-
"metadata": {
50-
"tags": []
51-
},
52-
"outputs": [
53-
{
54-
"data": {
55-
"text/html": [
56-
"\n",
57-
" <progress\n",
58-
" value='100'\n",
59-
" max='100',\n",
60-
" style='width: 100%'\n",
61-
" >\n",
62-
" 100\n",
63-
" </progress>\n",
64-
" "
65-
],
66-
"text/plain": [
67-
"<IPython.core.display.HTML object>"
68-
]
69-
},
70-
"metadata": {},
71-
"output_type": "display_data"
72-
}
73-
],
19+
"execution_count": null,
20+
"metadata": {},
21+
"outputs": [],
7422
"source": [
7523
"#@title Install Rendering Dependencies { display-mode: \"form\" }\n",
7624
"#@markdown (You only need to run this code when using Colab's hosted runtime)\n",
@@ -156,17 +104,9 @@
156104
},
157105
{
158106
"cell_type": "code",
159-
"execution_count": 2,
107+
"execution_count": null,
160108
"metadata": {},
161-
"outputs": [
162-
{
163-
"name": "stdout",
164-
"output_type": "stream",
165-
"text": [
166-
"ml-agents already installed\n"
167-
]
168-
}
169-
],
109+
"outputs": [],
170110
"source": [
171111
"try:\n",
172112
" import mlagents\n",

pettingzoo-unity/pettingzoo_unity/envs/__init__.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,25 @@
1515
logging_util.set_log_level(logging_util.WARNING)
1616

1717

18-
class petting_zoo_env:
19-
def __init__(self, env_id):
18+
class PettingZooEnv:
19+
def __init__(self, env_id: str) -> None:
2020
self.env_id = env_id
2121

22-
def env(self, seed: Optional[int] = None, **kwargs):
22+
def env(self, seed: Optional[int] = None, **kwargs) -> UnityToPettingZooWrapper:
23+
"""
24+
Creates the environment with env_id from unity's default_registry and wraps it in a UnityToPettingZooWrapper
25+
:param seed: The seed for the action spaces of the agents.
26+
:param kwargs: Any argument accepted by `UnityEnvironment`class except file_name
27+
"""
28+
# If not side_channels specified, add the followings
2329
if "side_channels" not in kwargs:
2430
kwargs["side_channels"] = [
2531
EngineConfigurationChannel(),
2632
EnvironmentParametersChannel(),
2733
StatsSideChannel(),
2834
]
2935
_env = None
36+
# If no base port argument is provided, try ports starting at 6000 until one is free
3037
if "base_port" not in kwargs:
3138
port = 6000
3239
while _env is None:
@@ -41,12 +48,13 @@ def env(self, seed: Optional[int] = None, **kwargs):
4148
return UnityToPettingZooWrapper(_env, seed)
4249

4350

44-
for env_id in default_registry:
45-
env_id = env_id.replace("3", "Three")
46-
if not env_id.isidentifier():
51+
# Register each environment in default_registry as a PettingZooEnv
52+
for key in default_registry:
53+
key = key.replace("3", "Three")
54+
if not key.isidentifier():
4755
logger.warning(
48-
f"Environment id {env_id} can not be registered since it is"
56+
f"Environment id {key} can not be registered since it is"
4957
f"not a valid identifier name."
5058
)
5159
continue
52-
locals()[env_id] = petting_zoo_env(env_id)
60+
locals()[key] = PettingZooEnv(key)

0 commit comments

Comments
 (0)