- Python 3.10
- Dependencies from
Requirements/requirements.txt
Run the following command (adjust parameters as needed):
python train.py --agent PPO --env MiniGrid-Empty-5x5-v0 --seed 123123 --num_runs 3 --num_episodes 200 --episode_max_steps 500 --num_envs 1 --render_mode None
- agent: Type of agent (list of all agents in config.py).
- env: Environment name.
- seed: Random seed.
- num_runs: Number of independent runs.
- num_episodes: Episodes per run. (EITHER CHOOSE THIS OR total_steps)
- total_steps: Maximum number of environment-action interactions. (EITHER CHOOSE THIS OR num_episodes)
- episode_max_steps: Maximum steps per episode.
- num_envs: Number of parallel environments.
- render_mode: Rendering mode (None, human, rgb_array_list): rgb_array_list will store the frames in experiment directory which takes a lot of space
- store_transitions: Boolean indication to save all the transition in the result directory which takes a lot of space (by default false)
- checkpoint_freq: Frequency of saving checkpoints (by default only the last policy will be saved)
You can modify the config.py to set specific hyper parameters or change the wrappers on the environment.
Trained models, metrics, and logs are saved under Runs/Train/. To view logs with TensorBoard, run:
tensorboard --logdir=Runs/Train/
To tune hyper-parameters using Optuna, run the tune_hp.py script. For example:
python tune_hp.py --agent PPO --env MiniGrid-Empty-5x5-v0 --seed 1 --num_configs 300 --num_runs 2 --num_episodes 200 --episode_max_steps 200 --num_envs 1 --metric_ratio 0.5
- You can modify the search ranges for each hyper-parameter in
tune_hp.py
.
Similarly You can modify the config.py to change default hyper parameters (search starting point) or change the wrappers on the environment.
To add a new agent to the framework, follow these simple steps:
-
Create your agent file:
Place your new agent implementation (e.g.,MyAgent.py
) in an appropriate subfolder ofAgents/
. -
Implement the agent class:
ExtendBaseAgent
(or a suitable base class) and implement the required methods such asact()
,update()
, andreset()
. -
Register your agent: Update the
__init__.py
of the new agent directory. -
Set default parameters: Update the agent dictionary (
config.py
) by adding a new entry inAGENT_DICT
. For example:
```python
"MyAgent": lambda env: MyAgent(
get_env_action_space(env),
get_env_observation_space(env),
HyperParameters(your_params_here),
get_num_envs(env),
YourFeatureExtractor,
)
```
To add a new environment to the framework, follow these steps:
-
Register the Environment: Ensure your environment is registered with Gymnasium.
-
Implement the Wrappers: Implement the wrappers using the Gymnasium observation, reward, action wrappers.
-
Implement Environment Creation Functions:
In the appropriate folder (e.g.,Environments/NewEnv/``), create
get_single_env()and
get_parallel_env()` to properly instantiate your environment and apply any necessary wrappers. -
Update the Global Factory:
InEnvironments/__init__.py
, add your new environment to the combined environment list (ENV_LST
) and ensure theget_env()
function can instantiate it with the correct parameters and wrappers.
After these steps, your environment will be available for training and evaluation through the framework.