kaggle-environments 1.20.0__py3-none-any.whl → 1.20.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kaggle-environments might be problematic. Click here for more details.

@@ -0,0 +1,315 @@
1
+ Metadata-Version: 2.4
2
+ Name: kaggle-environments
3
+ Version: 1.20.1
4
+ Summary: Kaggle Environments
5
+ Keywords: Kaggle
6
+ Author-email: Kaggle <support@kaggle.com>
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: accelerate
11
+ Requires-Dist: bitsandbytes
12
+ Requires-Dist: Chessnut >= 0.4.1
13
+ Requires-Dist: Flask >= 1.1.2
14
+ Requires-Dist: gymnasium == 1.2.0
15
+ Requires-Dist: gymnax==0.0.8
16
+ Requires-Dist: jax
17
+ Requires-Dist: jsonschema >= 3.0.1
18
+ Requires-Dist: litellm
19
+ Requires-Dist: numpy >= 2.2.6
20
+ Requires-Dist: open_spiel >= 1.6.2
21
+ Requires-Dist: pettingzoo == 1.24.0
22
+ Requires-Dist: requests >= 2.25.1
23
+ Requires-Dist: scipy >= 1.15.3
24
+ Requires-Dist: shimmy >= 1.2.1
25
+ Requires-Dist: stable-baselines3 == 2.7.0
26
+ Requires-Dist: transformers >= 4.33.1
27
+ Project-URL: Homepage, https://github.com/Kaggle/kaggle-environments
28
+
29
+ # [<img src="https://kaggle.com/static/images/site-logo.png" height="50" style="margin-bottom:-15px" />](https://kaggle.com) Environments
30
+
31
+ ```bash
32
+ uv pip install kaggle-environments
33
+ ```
34
+
35
+ # TLDR;
36
+
37
+ ```python
38
+ from kaggle_environments import make
39
+
40
+ # Setup a tictactoe environment.
41
+ env = make("tictactoe")
42
+
43
+ # Basic agent which marks the first available cell.
44
+ def my_agent(obs):
45
+ return [c for c in range(len(obs.board)) if obs.board[c] == 0][0]
46
+
47
+ # Run the basic agent against a default agent which chooses a "random" move.
48
+ env.run([my_agent, "random"])
49
+
50
+ # Render an html ipython replay of the tictactoe game.
51
+ env.render(mode="ipython")
52
+ ```
53
+
54
+ # Overview
55
+
56
+ Kaggle Environments was created to evaluate episodes. While other libraries have set interface precedents (such as Open.ai Gym), the emphasis of this library focuses on:
57
+
58
+ 1. Episode evaluation (compared to training agents).
59
+ 2. Configurable environment/agent lifecycles.
60
+ 3. Simplified agent and environment creation.
61
+ 4. Cross language compatible/transpilable syntax/interfaces.
62
+
63
+ ## Help Documentation
64
+
65
+ ```python
66
+ # Additional documentation (especially interfaces) can be found on all public functions:
67
+ from kaggle_environments import make
68
+ help(make)
69
+ env = make("tictactoe")
70
+ dir(env)
71
+ help(env.reset)
72
+ ```
73
+
74
+ # Agents
75
+
76
+ > A function which given an observation generates an action.
77
+
78
+ ## Writing
79
+
80
+ Agent functions can have observation and configuration parameters and must return a valid action. Details about the observation, configuration, and actions can seen by viewing the specification.
81
+
82
+ ```python
83
+ from kaggle_environments import make
84
+ env = make("connectx", {"rows": 10, "columns": 8, "inarow": 5})
85
+
86
+ def agent(observation, configuration):
87
+ print(observation) # {board: [...], mark: 1}
88
+ print(configuration) # {rows: 10, columns: 8, inarow: 5}
89
+ return 3 # Action: always place a mark in the 3rd column.
90
+
91
+ # Run an episode using the agent above vs the default random agent.
92
+ env.run([agent, "random"])
93
+
94
+ # Print schemas from the specification.
95
+ print(env.specification.observation)
96
+ print(env.specification.configuration)
97
+ print(env.specification.action)
98
+ ```
99
+
100
+ ## Loading Agents
101
+
102
+ Agents are always functions, however there are some shorthand syntax options to make generating/using them easier.
103
+
104
+ ```python
105
+ # Agent def accepting an observation and returning an action.
106
+ def agent1(obs):
107
+ return [c for c in range(len(obs.board)) if obs.board[c] == 0][0]
108
+
109
+ # Load a default agent called "random".
110
+ agent2 = "random"
111
+
112
+ # Load an agent from source.
113
+ agent3 = """
114
+ def act(obs):
115
+ return [c for c in range(len(obs.board)) if obs.board[c] == 0][0]
116
+ """
117
+
118
+ # Load an agent from a file.
119
+ agent4 = "C:\path\file.py"
120
+
121
+ # Return a fixed action.
122
+ agent5 = 3
123
+
124
+ # Return an action from a url.
125
+ agent6 = "http://localhost:8000/run/agent"
126
+ ```
127
+
128
+ ## Default Agents
129
+
130
+ Most environments contain default agents to play against. To see the list of available agents for a specific environment run:
131
+
132
+ ```python
133
+ from kaggle_environments import make
134
+ env = make("tictactoe")
135
+
136
+ # The list of available default agents.
137
+ print(*env.agents)
138
+
139
+ # Run random agent vs reaction agent.
140
+ env.run(["random", "reaction"])
141
+ ```
142
+
143
+ ## Training
144
+
145
+ Open AI Gym interface is used to assist with training agents. The `None` keyword is used below to denote which agent to train (i.e. train as first or second player of connectx).
146
+
147
+ ```python
148
+ from kaggle_environments import make
149
+
150
+ env = make("connectx", debug=True)
151
+
152
+ # Training agent in first position (player 1) against the default random agent.
153
+ trainer = env.train([None, "random"])
154
+
155
+ obs = trainer.reset()
156
+ for _ in range(100):
157
+ env.render()
158
+ action = 0 # Action for the agent being trained.
159
+ obs, reward, done, info = trainer.step(action)
160
+ if done:
161
+ obs = trainer.reset()
162
+ ```
163
+
164
+ ## Debugging
165
+
166
+ There are 3 types of errors which can occur from agent execution:
167
+
168
+ 1. **Timeout** - the agent runtime exceeded the allowed limit. There are 2 timeouts:
169
+ 1. `agentTimeout` - Used for initialization of an agent on first "act".
170
+ 2. `actTimeout` - Used for obtaining an action.
171
+ 2. **Error** - the agent raised and error during execution.
172
+ 3. **Invalid** - the agent action response didn't match the action specification or the environment deemed it invalid (i.e. playing twice in the same cell in tictactoe).
173
+
174
+ To help debug your agent and why it threw the errors above, add the `debug` flag when setting up the environment.
175
+
176
+ ```python
177
+ from kaggle_environments import make
178
+
179
+ def agent():
180
+ return "Something Bad"
181
+
182
+ env = make("tictactoe", debug=True)
183
+
184
+ env.run([agent, "random"])
185
+ # Prints: "Invalid Action: Something Bad"
186
+ ```
187
+
188
+ # Environments
189
+
190
+ > A function which given a state and agent actions generates a new state.
191
+
192
+ | Name | Description | Make |
193
+ | --------- | ------------------------------------ | ------------------------- |
194
+ | connectx | Connect 4 in a row but configurable. | `env = make("connectx")` |
195
+ | tictactoe | Classic Tic Tac Toe | `env = make("tictactoe")` |
196
+ | identity | For debugging, action is the reward. | `env = make("identity")` |
197
+
198
+ ## Making
199
+
200
+ An environment instance can be made from an existing specification (such as those listed above).
201
+
202
+ ```python
203
+ from kaggle_environments import make
204
+
205
+ # Create an environment instance.
206
+ env = make(
207
+ # Specification or name to registered specification.
208
+ "connectx",
209
+
210
+ # Override default and environment configuration.
211
+ configuration={"rows": 9, "columns": 10},
212
+
213
+ # Initialize the environment from a prior state (episode resume).
214
+ steps=[],
215
+
216
+ # Enable verbose logging.
217
+ debug=True
218
+ )
219
+ ```
220
+
221
+ ## Configuration
222
+
223
+ There are two types of configuration: Defaults applying to every environment and those specific to the environment. The following is a list of the default configuration:
224
+
225
+ | Name | Description |
226
+ | ------------ | --------------------------------------------------------------- |
227
+ | episodeSteps | Maximum number of steps in the episode. |
228
+ | agentTimeout | Maximum runtime (seconds) to initialize an agent. |
229
+ | actTimeout | Maximum runtime (seconds) to obtain an action from an agent. |
230
+ | runTimeout | Maximum runtime (seconds) of an episode (not necessarily DONE). |
231
+ | maxLogLength | Maximum log length (number of characters, `None` -> no limit) |
232
+
233
+ ```python
234
+ env = make("connectx", configuration={
235
+ "columns": 19, # Specific to ConnectX.
236
+ "actTimeout": 10,
237
+ })
238
+ ```
239
+
240
+ ## Resetting
241
+
242
+ Environments are reset by default after "make" (unless starting steps are passed in) as well as when calling "run". Reset can be called at anytime to clear the environment.
243
+
244
+ ```python
245
+ num_agents = 2
246
+ reset_state = env.reset(num_agents)
247
+ ```
248
+
249
+ ## Running
250
+
251
+ Execute an episode against the environment using the passed in agents until they are no longer running (i.e. status != ACTIVE).
252
+
253
+ ```python
254
+ steps = env.run([agent1, agent2])
255
+ print(steps)
256
+ ```
257
+
258
+ ## Evaluating
259
+
260
+ Evaluation is used to run an episode (environment + agents) multiple times and just return the rewards.
261
+
262
+ ```python
263
+ from kaggle_environments import evaluate
264
+
265
+ # Same definitions as "make" above.
266
+ environment = "connectx"
267
+ configuration = {"rows": 10, "columns": 8, "inarow": 5}
268
+ steps = []
269
+
270
+ # Which agents to run repeatedly. Same as env.run(agents)
271
+ agents = ["random", agent1]
272
+
273
+ # How many times to run them.
274
+ num_episodes = 10
275
+
276
+ rewards = evaluate(environment, agents, configuration, steps, num_episodes)
277
+ ```
278
+
279
+ ## Stepping
280
+
281
+ Running above essentially just steps until no agent is still active. To execute a singular game loop, pass in actions directly for each agent. Note that this is normally used for training agents (most useful in a single agent setup such as using the gym interface).
282
+
283
+ ```python
284
+ agent1_action = agent1(env.state[0].observation)
285
+ agent2_action = agent2(env.state[1].observation)
286
+ state = env.step([agent1_action, agent2_action])
287
+ ```
288
+
289
+ ## Playing
290
+
291
+ A few environments offer an interactive play against agents within jupyter notebooks. An example of this is using connectx:
292
+
293
+ ```python
294
+ from kaggle_environments import make
295
+
296
+ env = make("connectx")
297
+ # None indicates which agent will be manually played.
298
+ env.play([None, "random"])
299
+ ```
300
+
301
+ ## Rendering
302
+
303
+ The following rendering modes are supported:
304
+
305
+ - json - Same as doing a json dump of `env.toJSON()`
306
+ - ansi - Ascii character representation of the environment.
307
+ - human - ansi just printed to stdout
308
+ - html - HTML player representation of the environment.
309
+ - ipython - html just printed to the output of a ipython notebook.
310
+
311
+ ```python
312
+ out = env.render(mode="ansi")
313
+ print(out)
314
+ ```
315
+
@@ -204,8 +204,8 @@ kaggle_environments/envs/tictactoe/tictactoe.js,sha256=NZDT-oSG0a6a-rso9Ldh9qkJw
204
204
  kaggle_environments/envs/tictactoe/tictactoe.json,sha256=zMXZ8-fpT7FBhzz2FFBvRLn4XwtngjEqOieMvI6cCj8,1121
205
205
  kaggle_environments/envs/tictactoe/tictactoe.py,sha256=uq3sTHWNMg0dxX2v9pTbJAKM7fwerxQt7OQjCX96m-Y,3657
206
206
  kaggle_environments/static/player.html,sha256=ek33T_8ecmWuxE5dWKO7jlYWLTPXru-cs0PrkBlNjAM,26749
207
- kaggle_environments-1.20.0.dist-info/entry_points.txt,sha256=h03sq76TdcHvXKcsre1Qm3lIni9dkWehu61xJqI-p8k,69
208
- kaggle_environments-1.20.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
209
- kaggle_environments-1.20.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
210
- kaggle_environments-1.20.0.dist-info/METADATA,sha256=YD_4-4v2-2XEn-OMcKxMYKbsahUZULIiuhWv-OwO5to,784
211
- kaggle_environments-1.20.0.dist-info/RECORD,,
207
+ kaggle_environments-1.20.1.dist-info/entry_points.txt,sha256=h03sq76TdcHvXKcsre1Qm3lIni9dkWehu61xJqI-p8k,69
208
+ kaggle_environments-1.20.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
209
+ kaggle_environments-1.20.1.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
210
+ kaggle_environments-1.20.1.dist-info/METADATA,sha256=dmUGa79-cAbQc3GVcoYwpUk84R8FGrWl3pSOgpn2zuc,9378
211
+ kaggle_environments-1.20.1.dist-info/RECORD,,
@@ -1,25 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: kaggle-environments
3
- Version: 1.20.0
4
- Summary: Kaggle Environments
5
- Author-email: Kaggle <support@kaggle.com>
6
- Requires-Python: >=3.10
7
- License-File: LICENSE
8
- Requires-Dist: accelerate
9
- Requires-Dist: bitsandbytes
10
- Requires-Dist: Chessnut >= 0.4.1
11
- Requires-Dist: Flask >= 1.1.2
12
- Requires-Dist: gymnasium == 1.2.0
13
- Requires-Dist: gymnax==0.0.8
14
- Requires-Dist: jax
15
- Requires-Dist: jsonschema >= 3.0.1
16
- Requires-Dist: litellm
17
- Requires-Dist: numpy >= 2.2.6
18
- Requires-Dist: open_spiel >= 1.6.2
19
- Requires-Dist: pettingzoo == 1.24.0
20
- Requires-Dist: requests >= 2.25.1
21
- Requires-Dist: scipy >= 1.15.3
22
- Requires-Dist: shimmy >= 1.2.1
23
- Requires-Dist: stable-baselines3 == 2.7.0
24
- Requires-Dist: transformers >= 4.33.1
25
- Project-URL: Homepage, https://github.com/Kaggle/kaggle-environments