|
| 1 | +# Jaxplorer |
| 2 | + |
| 3 | +Jaxplorer is a Jax reinforcement learning framework for **exploring** new ideas. |
| 4 | +For PyTorch reinforcement learning framework, please check [Explorer](https://github.com/qlan3/Explorer). |
| 5 | + |
| 6 | +Note: this repo is still under development and in its early stage. |
| 7 | + |
| 8 | +## Requirements |
| 9 | + |
| 10 | +- Python: 3.11 |
| 11 | +- [Jax](https://jax.readthedocs.io/en/latest/installation.html): >=0.4.20 |
| 12 | +- [Gymnasium](https://github.com/Farama-Foundation/Gymnasium): pip install gymnasium==0.29.1 |
| 13 | +- [Mujoco](https://github.com/google-deepmind/mujoco): pip install mujoco==2.3.7 |
| 14 | +- [Gymnasium(mujoco)](https://gymnasium.farama.org/environments/mujoco/): pip install gymnasium[mujoco] |
| 15 | +- Others: Please check `requirements.txt`. |
| 16 | + |
| 17 | + |
| 18 | +## Implemented algorithms |
| 19 | + |
| 20 | +- [Deep Q-Learning (DQN)](https://users.cs.duke.edu/~pdinesh/sources/MnihEtAlHassibis15NatureControlDeepRL.pdf) |
| 21 | +- [Double Deep Q-learning (DDQN)](https://arxiv.org/pdf/1509.06461.pdf) |
| 22 | +- [Maxmin Deep Q-learning (MaxminDQN)](https://arxiv.org/pdf/2002.06487.pdf) |
| 23 | +- [Proximal Policy Optimisation (PPO)](https://arxiv.org/pdf/1707.06347.pdf) |
| 24 | +- [Soft Actor-Critic (SAC)](https://arxiv.org/pdf/1812.05905.pdf) |
| 25 | +- [Deep Deterministic Policy Gradients (DDPG)](https://arxiv.org/pdf/1509.02971.pdf) |
| 26 | +- [Twin Delayed Deep Deterministic Policy Gradients (TD3)](https://arxiv.org/pdf/1802.09477.pdf) |
| 27 | +- [Continuous Deep Q-Learning with Model-based Acceleration (NAF)](https://arxiv.org/pdf/1603.00748.pdf): model-free version; a different exploration strategy is applied for simplicity. |
| 28 | + |
| 29 | +TODO: add more algorithms and improve the performance of PPO. |
| 30 | + |
| 31 | +## Experiments |
| 32 | + |
| 33 | +### Train && Test |
| 34 | + |
| 35 | +All hyperparameters including parameters for grid search are stored in a configuration file in directory `configs`. To run an experiment, a configuration index is first used to generate a configuration dict corresponding to this specific configuration index. Then we run an experiment defined by this configuration dict. All results including log files are saved in directory `logs`. Please refer to the code for details. |
| 36 | + |
| 37 | +For example, run the experiment with configuration file `classic_dqn.json` and configuration index `1`: |
| 38 | + |
| 39 | +```python main.py --config_file ./configs/classic_dqn.json --config_idx 1``` |
| 40 | + |
| 41 | +The models are tested for one episode after every `test_per_episodes` training episodes which can be set in the configuration file. |
| 42 | + |
| 43 | + |
| 44 | +### Grid Search (Optional) |
| 45 | + |
| 46 | +First, we calculate the number of total combinations in a configuration file (e.g. `classic_dqn.json`): |
| 47 | + |
| 48 | +`python utils/sweeper.py` |
| 49 | + |
| 50 | +The output will be: |
| 51 | + |
| 52 | +`Number of total combinations in classic_dqn.json: 18` |
| 53 | + |
| 54 | +Then we run through all configuration indexes from `1` to `18`. The simplest way is using a bash script: |
| 55 | + |
| 56 | +``` bash |
| 57 | +for index in {1..18} |
| 58 | +do |
| 59 | + python main.py --config_file ./configs/classic_dqn.json --config_idx $index |
| 60 | +done |
| 61 | +``` |
| 62 | + |
| 63 | +[Parallel](https://www.gnu.org/software/parallel/) is usually a better choice to schedule a large number of jobs: |
| 64 | + |
| 65 | +``` bash |
| 66 | +parallel --eta --ungroup python main.py --config_file ./configs/classic_dqn.json --config_idx {1} ::: $(seq 1 18) |
| 67 | +``` |
| 68 | + |
| 69 | +Any configuration index that has the same remainder (divided by the number of total combinations) should have the same configuration dict. So for multiple runs, we just need to add the number of total combinations to the configuration index. For example, 5 runs for configuration index `1`: |
| 70 | + |
| 71 | +``` |
| 72 | +for index in 1 19 37 55 73 |
| 73 | +do |
| 74 | + python main.py --config_file ./configs/classic_dqn.json --config_idx $index |
| 75 | +done |
| 76 | +``` |
| 77 | + |
| 78 | +Or a simpler way: |
| 79 | +``` |
| 80 | +parallel --eta --ungroup python main.py --config_file ./configs/classic_dqn.json --config_idx {1} ::: $(seq 1 18 90) |
| 81 | +``` |
| 82 | + |
| 83 | +### Slurm (Optional) |
| 84 | + |
| 85 | +Slurm is supported as well. Please check `submit.py`. |
| 86 | +TODO: add more details. |
| 87 | + |
| 88 | + |
| 89 | +### Analysis (Optional) |
| 90 | + |
| 91 | +To analyze the experimental results, just run: |
| 92 | + |
| 93 | +`python analysis.py` |
| 94 | + |
| 95 | +Inside `analysis.py`, `unfinished_index` will print out the configuration indexes of unfinished jobs based on the existence of the result file. `memory_info` will print out the memory usage information and generate a histogram to show the distribution of memory usages in directory `logs/classic_dqn/0`. Similarly, `time_info` will print out the time information and generate a histogram to show the distribution of time in directory `logs/classic_dqn/0`. Finally, `analyze` will generate `csv` files that store training and test results. Please check `analysis.py` for more details. More functions are available in `utils/plotter.py`. |
| 96 | + |
| 97 | +TODO: add more details about hyper-parameter comparison. |
| 98 | + |
| 99 | + |
| 100 | +## Cite |
| 101 | + |
| 102 | +If you find this repo useful to your research, please cite my paper if related. Otherwise, please cite this repo: |
| 103 | + |
| 104 | +~~~bibtex |
| 105 | +@misc{Jaxplorer, |
| 106 | + author = {Lan, Qingfeng}, |
| 107 | + title = {A Jax Reinforcement Learning Framework for Exploring New Ideas}, |
| 108 | + year = {2024}, |
| 109 | + publisher = {GitHub}, |
| 110 | + journal = {GitHub Repository}, |
| 111 | + howpublished = {\url{https://github.com/qlan3/Jaxplorer}} |
| 112 | +} |
| 113 | +~~~ |
| 114 | + |
| 115 | +# Acknowledgements |
| 116 | + |
| 117 | +- [Explorer](https://github.com/qlan3/Explorer) |
| 118 | +- [Jax RL](https://github.com/ikostrikov/jaxrl) |
| 119 | +- [CleanRL](https://github.com/vwxyzjn/cleanrl) |
0 commit comments