Gymnasium Utility Methods¶
Velora uses the Gymnasium [] package as it's main environment provider, which is used to train agents and view their performance.
Normally, you would use the make()
method to create an environment, like so:
Python | |
---|---|
1 2 3 |
|
We've removed the need to do this to simplify the implementation and to allow us to easily integrate the environment with our agents.
Instead, now we pass in the env_id
to the agent of our choice:
Python | |
---|---|
1 2 3 |
|
Unfortunately, this takes away a lot of your freedom for adding custom wrappers and we are looking at ways to incorporate this in a future release. For now, we want to keep things simple while we fully flesh out the agents implementation details.
Utility Methods¶
Under rare circumstances you might want to use a Gymnasium environment to quickly explore it before using a Velora agent.
To help with this, we've added some utility methods that you might find useful.
Wrapping Gymnasium Environments¶
wrap_gym_env
is a quick way to create new environments with wrappers automatically applied. Normally, you'd have to apply wrappers, one by one like this:
Python | |
---|---|
1 2 3 4 5 6 7 |
|
It's pretty tedious, so we've simplified it a little with the wrap_gym_env
method:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
This code should work 'as is'.
Now, you just supply the environment name
and a of List[gym.Wrappers]
or List[partial]
wrappers and your environment is good to go! 😎
Core Wrappers¶
We've also added a add_core_env_wrappers
method that applies specific wrappers required by every Velora agent.
It applies the following wrappers (in order):
- RecordEpisodeStatistics [] - for easily retrieving episode statistics.
- NumpyToTorch [] - for turning environment feedback into
PyTorch
tensors.
Here's an example:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
In previous versions, you would manually need to use this yourself when working with the predict()
method to quickly convert the environment from numpy
arrays to torch
tensors.
We found this to be very tedious and quite confusing in some instances, so instead, we've simplified this process by adding a .eval_env
attribute to every agent to remove this process:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 |
|
You can see an example of this in the Agent Basics - Making Predictions section.
Finding Environments¶
We've also added a unique approach to quickly finding a specific environment at it's latest version without having to search through the Gymnasium [] documentation.
You can do this with a utility class called EnvSearch
.
Every method attached to the class returns a List[EnvResult]
where EnvResult
are objects that have a name
and type
to help you quickly determine which environment fits your use case.
There are three search methods split into two categories:
- Searching for a specific environment
- Getting a list of available environments by type
Specific One¶
API Docs
Let's say you want to quickly find the latest LunarLander
environment, specifically the continuous
one.
You can use the find()
method:
Python | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
This code should work 'as is'.
Given a query
string (part of the name or the full name), it will give you a list of relevant results.
By Type¶
Not sure what environments are available? Looking for your next discrete
one or continuous
one? We've got you covered! 😉
Simply use the discrete()
or continuous()
methods to get a complete list of available options:
Python | |
---|---|
1 2 3 4 5 6 7 |
|
Python | |
---|---|
1 2 3 4 5 6 7 |
|
This code should work 'as is'.
Warning
Environments are split into two categories discrete
or continuous
based on their action_space
:
discrete
requires agym.spaces.Discrete
spacecontinuous
requires agym.spaces.Box
space
Any other action_space
type is ignored.
Up next, we'll take a look at the generic utility methods Velora has to offer 👋.