Creating Your Environment
Getting Started
We will call the original Gym environment the base environment in this tutorial.
There are three components in an aiVLE Gym environment:
- serializer (
EnvSerializer
): translates certain non-JSON compatible Python objects into compatible ones, and in reverse - agent env (
AgentEnv
): agent-side Gym-compatible class that communicates with the judge-side (simulation-side) - judge env (
JudgeEnv
/JudgeMultiEnv
): simulation environment, you may reuse existing Gym environment with little modification
You will create concrete class of corresponding abstract base class by implementing certain abstract methods. (Also
remember to call the base class constructor in __init__
method)
Single-agent task
We'll use Gym's built-in cart pole environment as an example:
Serializer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Agent Environment
1 2 3 4 5 6 7 8 9 |
|
Judge Environment
As shown below, if you don't have special requirements, simply calling the corresponding methods in the base environment is good enough.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Agent
Note that CartPoleAgentEnv()
and gym.make('CartPole-v0')
are designed to be interchangable in the agent code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Execution
These code can be found under ./example. To execute this concrete example:
python judge.py
to start the simulation process firstpython agent.py
to run the agent code
Multi-agent task
Multi-agent case is very similar to single-agent case, differences are:
- agent env:
action_space
,observation_space
andreward_range
need to be that of this specific agentuid
needs to be meaningful (i.e. unique among all participating agents, etc.)
- judge env: additional constructor params:
n_agents
: number of agentsuid_to_idx
: map from uid to agent index (0-indexed)
A concrete example can be found under ./example/multi_agent.py and ./example/multi_judge.py