-
Notifications
You must be signed in to change notification settings - Fork 294
CLI documentation #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
CLI documentation #743
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
354d73d
First draft of CLI documentation (WIP)
ernestum 722b252
Add more examples for the CLI, improve some wording, add a overview t…
ernestum c2d2d44
Add documentation of the script output format.
ernestum 6596b3f
Remove comment from command line example.
ernestum 80a4ca5
Add table for the utility scripts.
ernestum f47d6e7
Improve ingredient documentation.
ernestum b5cc7b6
Fix formatting issues.
ernestum c021627
Use .. note:: sections where appropriate.
ernestum 1d2c188
Use double backticks for literals.
ernestum 32582eb
Merge branch 'master' into 726-documentation-for-the-cli
ernestum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| ====================== | ||
| Command Line Interface | ||
| ====================== | ||
|
|
||
| Many features of the core library are accessible via the command line interface built | ||
| using the `Sacred <https://github.com/idsia/sacred>`_ package. | ||
|
|
||
| Sacred is used to configure and run the algorithms. | ||
| It is centered around the concept of `experiments <https://sacred.readthedocs.io/en/stable/experiment.html>`_ | ||
| which are composed of reusable `ingredients <https://sacred.readthedocs.io/en/stable/ingredients.html>`_. | ||
| Each experiment and each ingredient has its own configuration namespace. | ||
| Named configurations are used to specify a coherent set of configuration values. | ||
| It is recommended to at least read the | ||
| `Sacred documentation about the command line interface <https://sacred.readthedocs.io/en/stable/command_line.html>`_. | ||
|
|
||
| The :py:mod:`scripts <imitation.scripts>` package contains a number of sacred experiments to either execute algorithms or perform utility tasks. | ||
| The most important :py:mod:`ingredients <imitation.scripts.ingredients>` for imitation learning are: | ||
|
|
||
| - :py:mod:`Environments <imitation.scripts.ingredients.environment>` | ||
| - :py:mod:`Expert Policies <imitation.scripts.ingredients.expert>` | ||
| - :py:mod:`Expert Demonstrations <imitation.scripts.ingredients.demonstrations>` | ||
| - :py:mod:`Reward Functions <imitation.scripts.ingredients.reward>` | ||
|
|
||
|
|
||
| Usage Examples | ||
| ============== | ||
|
|
||
| Here we demonstrate some usage examples for the command line interface. | ||
| You can always find out all the configurable values by running: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m imitation.scripts.<script> print_config | ||
|
|
||
| Run BC on the ``CartPole-v1`` environment with a pre-trained PPO policy as expert: | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. note:: Here the cartpole environment is specified via a named configuration. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m imitation.scripts.train_imitation bc with \ | ||
| cartpole \ | ||
| demonstrations.n_expert_demos=50 \ | ||
| bc.train_kwargs.n_batches=2000 \ | ||
| expert.policy_type=ppo \ | ||
| expert.loader_kwargs.path=tests/testdata/expert_models/cartpole_0/policies/final/model.zip | ||
|
|
||
| 50 expert demonstrations are sampled from the PPO policy that is included in the testdata folder. | ||
| 2000 batches are enough to train a good policy. | ||
|
|
||
| Run DAgger on the ``CartPole-v0`` environment with a random policy as expert: | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m imitation.scripts.train_imitation dagger with \ | ||
| cartpole \ | ||
| dagger.total_timesteps=2000 \ | ||
| demonstrations.n_expert_demos=10 \ | ||
| expert.policy_type=random | ||
|
|
||
| This will not produce any meaningful results, since a random policy is not a good expert. | ||
|
|
||
|
|
||
| Run AIRL on the ``MountainCar-v0`` environment with a expert from the HuggingFace model hub: | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m imitation.scripts.train_adversarial airl with \ | ||
| seals_mountain_car \ | ||
| total_timesteps=5000 \ | ||
| expert.policy_type=ppo-huggingface \ | ||
| demonstrations.n_expert_demos=500 | ||
|
|
||
| .. note:: The small number of total timesteps is only for demonstration purposes and will not produce a good policy. | ||
|
|
||
|
|
||
| Run GAIL on the ``seals/Swimmer-v0`` environment | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| Here we do not use the named configuration for the seals environment, but instead specify the gym_id directly. | ||
| The ``seals:`` prefix ensures that the seals package is imported and the environment is registered. | ||
|
|
||
| .. note:: The Swimmer environment needs `mujoco_py` to be installed. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m imitation.scripts.train_adversarial gail with \ | ||
| environment.gym_id="seals:seals/Swimmer-v0" \ | ||
| total_timesteps=5000 \ | ||
| demonstrations.n_expert_demos=50 | ||
|
|
||
|
|
||
| Algorithm Scripts | ||
| ================= | ||
|
|
||
| Call the algorithm scripts like this: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m imitation.scripts.<script> [command] with <named_config> <config_values> | ||
|
|
||
| +---------------------------------+------------------------------+----------+ | ||
| | algorithm | script | command | | ||
| +=================================+==============================+==========+ | ||
| | BC | train_imitation | bc | | ||
| +---------------------------------+------------------------------+----------+ | ||
| | DAgger | train_imitation | dagger | | ||
| +---------------------------------+------------------------------+----------+ | ||
| | AIRL | train_adversarial | airl | | ||
| +---------------------------------+------------------------------+----------+ | ||
| | GAIL | train_adversarial | gail | | ||
| +---------------------------------+------------------------------+----------+ | ||
| | Preference Comparison | train_preference_comparisons | - | | ||
| +---------------------------------+------------------------------+----------+ | ||
| | MCE IRL | none | - | | ||
| +---------------------------------+------------------------------+----------+ | ||
| | Density Based Reward Estimation | none | - | | ||
| +---------------------------------+------------------------------+----------+ | ||
|
|
||
| Utility Scripts | ||
| =============== | ||
|
|
||
| Call the utility scripts like this: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python -m imitation.scripts.<script> | ||
|
|
||
| +-----------------------------------------+-----------------------------------------------------------+ | ||
| | Functionality | Script | | ||
| +=========================================+===========================================================+ | ||
| | Reinforcement Learning | :py:mod:`train_rl <imitation.scripts.train_rl>` | | ||
| +-----------------------------------------+-----------------------------------------------------------+ | ||
| | Evaluating a Policy | :py:mod:`eval_policy <imitation.scripts.eval_policy>` | | ||
| +-----------------------------------------+-----------------------------------------------------------+ | ||
| | Parallel Execution of Algorithm Scripts | :py:mod:`parallel <imitation.scripts.parallel>` | | ||
| +-----------------------------------------+-----------------------------------------------------------+ | ||
| | Converting Trajectory Formats | :py:mod:`convert_trajs <imitation.scripts.convert_trajs>` | | ||
| +-----------------------------------------+-----------------------------------------------------------+ | ||
| | Analyzing Experimental Results | :py:mod:`analyze <imitation.scripts.analyze>` | | ||
| +-----------------------------------------+-----------------------------------------------------------+ | ||
|
|
||
|
|
||
| Output Directories | ||
| ================== | ||
|
|
||
| The results of the script runs are stored in the following directory structure: | ||
|
|
||
| .. code-block:: | ||
|
|
||
| output | ||
| ├── <algo> | ||
| │ └── <environment> | ||
| │ └── <timestamp> | ||
| │ ├── log | ||
| │ ├── monitor | ||
| │ └── sacred -> ../../../sacred/<script_name>/1 | ||
| └── sacred | ||
| └── <script_name> | ||
| ├── 1 | ||
| └── _sources | ||
|
|
||
| It contains the final model, tensorboard logs, sacred logs and the sacred source files. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| """Ingredients for scripts.""" | ||
| """Ingredients for Sacred experiments.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make these some kind of doc test so that they run during the build phase? I'm worried they will end up getting out of sync with the CI over time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right with this concern!
Unfortunately this is not so easy to do. See https://stackoverflow.com/questions/71497528/can-i-modify-doctest-to-test-bash-inside-sphinx-doc
We would either have to use python code and run the commands via subprocess or use some alpha-stage python module also does not quite exactly do what we need (we would have to re-write the documentation in Markdown).
Given that the CLI is going to change soon anyway, I would not put in the effort to test it right now. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The python module in question: https://github.com/jamesbehr/docshtest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good lets just make sure to add a task to the issue tracker for the CI overall to update this part of the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it to the bottom of the description here: #703