# rl-env

> A grid world in pure Python and a loop of 20 episodes with a seeded policy, and its recording.

A reinforcement-learning environment in pure Python, and a loop that runs episodes of it. `env.py` has `GridEnv`, a 6 by 6 grid with walls: a courier starts at the depot `(0, 0)` and walks to a customer at `(5, 5)`. `reset()` gives the first observation; `step(action)` gives `(observation, reward, done)`. The reward is 10 at the customer, and otherwise a cost of 0.1 for every cell still to walk. An episode ends at the customer or after 30 steps. `run.py` runs 20 episodes with a seeded policy that walks towards the customer and sometimes explores.

- Source: [`ormaos-examples/use-cases/rl-env`](https://github.com/ormaos/ormaos-examples/tree/6e27be59220856263a6a5905400d8630dafe73dd/use-cases/rl-env)
- Guide: [RL environment](/python/guides/rl-environment.md)

## Run it

```bash
python run.py
```

```console
$ python run.py
20 episodes, mean return -10.55
```

## Recorded

```bash
ormaos run -- python run.py
```

```console
$ ormaos run -- python run.py
20 episodes, mean return -10.55
ormaos: r1 exit 0 in …: 1 Python process, 1969 calls, 0 exceptions
ormaos: saved in .ormaos/r1, next: ormaos tree r1:c1
```

```console
$ ormaos show
r1 exit 0 in …: 1 Python process, 1969 calls, 0 exceptions (0 swallowed, 0 uncaught)
command: python run.py
code: git commit not read (the working directory is not inside a git repository)
never recorded: values, and 20 more kinds of things (`ormaos show --full` lists them with the reason)
next: ormaos tree r1:c1
```

---

Source: https://docs.ormaos.com/examples/rl-env/ · ormaos 0.0.1 · ormaos-python 968f69776c · ormaos-examples 6e27be5922
