This repository contains the code to reproduce the experimental results of CMLO algorithm in the paper When to Update Your Model: Constrained Model-based Reinforcement Learning.
Our paper proposes a general scheme for the monotonicity of MBRL methods considering the often-neglected issue of model shifts. The algorithm CMLO (Constrained Model-shift Lower-bound Optimization), stemming from the follow-up constrained optimization problem, has asymptotic performance rivaling the best model-free algorithms and boasts better monotonicity. CMLO introduces an event-triggered mechanism that flexibly determines when to update the model. Brief overview and more information refer to Project website.
Depending on your preferred interface for running this code, there are two primary methods available:
-
Run CMLO under Cat-Runner: We offer Cat-Runner, a lightweight, interactive training task manager that allows you to run and manage tasks without the need for writing code. You can also use the command-line interface to run and manage your CMLO tasks.
-
Quick Run CMLO without Cat-Runner: If you prefer not to set up Cat-Runner, we also provide a quick and easy way to run tasks without it.
Install mbrl
and packages listed in the requirements folder by:
pip install -e ".[dev]"
If you prefer not to use Cat-Runner, you can run the code from the command line directly. Use the following command:
cd cat-mbrl-lib/ &&
CUDA_VISIBLE_DEVICES=%s // gpu_id
des=%s // run_id
algo=%s //algo_name
freq=fixed // freq_name
seed_override=%s // seed
python -m mbrl.examples.main
algorithm=mbpo
overrides=%s // hyperparamters
Here is an example:
cd cat-mbrl-lib/
CUDA_VISIBLE_DEVICES=0 seed_override=0 des=test algo=cmlo freq=fixed python -m mbrl.examples.main algorithm=mbpo overrides=mbpo_halfcheetah
How to Start Cat-Runner Platform
-
Prerequisites (Cat-Runner only runs on Linux)
- Install
gcc
andnodejs
. - Compile the following helper programs.
gcc tools/do_run.c -O2 -o tools/do_run.exe gcc cat-runner/c/check_running.c -O2 -o cat-runner/c/check_running.exe gcc cat-runner/c/run.c -O2 -o cat-runner/c/run.exe
- Install node dependencies.
cd cat-runner npm install
- Install
-
Start Cat-Runner Server
-
Run
start_server.sh
incat-runner
directory. The server will bind on127.0.0.1:20001
. -
To choose different binding address and port, invoke
node index.js <address> <port>
-
-
Start Tensorboard Server
-
Run
start_tensorboard.sh
to start tensorboard server. The server will bind on127.0.0.1:20002
. -
To choose different binding address and port, invoke
tensorboard --logdir tensorboard_logdir/ --host <address> --port <port>
Note: There are links to the tensorboard server on Cat-Runner pages. Changing the binding address or port may break these links.
-
How to Run CMLO under Cat-Runner
-
Cat-Runner Command-Line Interface
- Initiate Cat-Runner, but without opening the webpage. Instead, use the terminal to control it with the following scripts:
tools/run
: Start a new task.tools/stop
: Stop a running task.tools/add_to_tensorboard
: Add a task to the Tensorboard listtools/del_from_tensorboard
: Remove a task from the Tensorboard list.
- Initiate Cat-Runner, but without opening the webpage. Instead, use the terminal to control it with the following scripts:
-
Cat-Runner Webpage Interface
- Initiate Cat-Runner, open the webpage, then you can iteract with the webpage to start your training tasks.
If you find our work useful, please consider citing the paper as follows:
@inproceedings{cmlo,
title={When to Update Your Model: Constrained Model-based Reinforcement Learning},
author={Ji, Tianying and Luo, Yu and Sun, Fuchun and Jing, Mingxuan and He, Fengxiang and Huang, Wenbing},
booktitle={Advances in Neural Information Processing Systems},
year={2022}
}