Skip to content

Commit a63349a

Browse files
authored
Add docs for logging and plotting (#2147)
* Add docs for logging and plotting * Fix grammer error * Fix isort
1 parent 792771d commit a63349a

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ and how to implement new MDPs and new algorithms.
7272
user/environment_libraries
7373
user/concept_experiment
7474
user/sampling
75+
user/logging_plotting
7576
7677
.. toctree::
7778
:maxdepth: 2

docs/user/logging_plotting.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Logging and plotting
2+
3+
## Logging
4+
5+
garage supports convenient and useful logging. garage uses [dowel](https://github.com/rlworkgroup/dowel)
6+
for logging. The `logger` supports many outputs, including
7+
8+
- Std output
9+
- Text output
10+
- Csv output
11+
- TensorBoard output
12+
13+
In garage's experiment, the `logger` will output to all of these.
14+
15+
Here is an example of logging in garage.
16+
17+
```py
18+
from garage import wrap_experiment
19+
from dowel import logger, tabular
20+
21+
@wrap_experiment
22+
def log_experiment(ctxt=None):
23+
for i in range(100):
24+
# Log str directly
25+
logger.log('Logging messages:')
26+
# Log scalar values with the key 'AverageReturn'
27+
tabular.record('AverageReturn', i)
28+
29+
# The Trainer will do these steps for you, if you log things in
30+
# the algorithms.
31+
logger.log(tabular)
32+
logger.dump_all()
33+
34+
log_experiment()
35+
```
36+
37+
Running the example will generate outputs like:
38+
39+
```sh
40+
2020-10-21 14:06:04 | [log_experiment] Logging to [CUR_DIR]/data/local/experiment/log_experiment
41+
2020-10-21 14:06:04 | [log_experiment] Logging messages:
42+
------------- -
43+
AverageReturn 0
44+
------------- -
45+
2020-10-21 14:06:04 | [log_experiment] Logging messages:
46+
------------- -
47+
AverageReturn 1
48+
------------- -
49+
2020-10-21 14:06:04 | [log_experiment] Logging messages:
50+
------------- -
51+
AverageReturn 2
52+
------------- -
53+
```
54+
55+
To look at outputs with TensorBoard, you can refer to this [page](monitor_experiments_with_tensorboard).
56+
57+
To set a customized log directory, just pass a `log_dir` argument to the
58+
experiment.
59+
60+
```py
61+
@wrap_experiment(log_dir='my_custom_log_fir')
62+
```
63+
64+
## Plotting
65+
66+
In garage, as long as the environment implement the `visualize()` method, is
67+
it easy to plot a policy running in the environment when training.
68+
69+
To visualize an experiment, just set the `plot` argument to `True` in the
70+
[`train`](../_autoapi/garage/index.html#garage.Trainer.train) method of
71+
`Trainer`. For example, in [example/tf/trpo_cartpole.py](https://github.com/rlworkgroup/garage/blob/master/examples/tf/trpo_cartpole.py),
72+
change the train line into:
73+
74+
```py
75+
trainer.train(n_epochs=100, batch_size=4000, plot=True)
76+
```
77+
78+
If you want to pause in every epoch, just set `pause_for_plot` to `True`.
79+
80+
----
81+
82+
*This page was authored by Ruofu Wang ([@yeukfu](https://github.com/yeukfu)).*

src/garage/__init__.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
"""Garage Base."""
22
# yapf: disable
3-
from garage._dtypes import (EpisodeBatch,
4-
InOutSpec,
5-
StepType,
6-
TimeStep,
3+
from garage._dtypes import (EpisodeBatch, InOutSpec, StepType, TimeStep,
74
TimeStepBatch)
85
from garage._environment import Environment, EnvSpec, EnvStep, Wrapper
9-
from garage._functions import (_Default,
10-
log_multitask_performance,
11-
log_performance,
12-
make_optimizer,
13-
obtain_evaluation_episodes,
14-
rollout)
6+
from garage._functions import (_Default, log_multitask_performance,
7+
log_performance, make_optimizer,
8+
obtain_evaluation_episodes, rollout)
159
from garage.experiment.experiment import wrap_experiment
10+
from garage.trainer import TFTrainer, Trainer
1611

1712
# yapf: enable
1813

@@ -33,4 +28,6 @@
3328
'Wrapper',
3429
'rollout',
3530
'obtain_evaluation_episodes',
31+
'Trainer',
32+
'TFTrainer',
3633
]

0 commit comments

Comments
 (0)