Repository: rlworkgroup/garage

Issue:
Cannot plot during training
```
from garage.experiment import LocalRunner, run_experiment
from garage.np.baselines import LinearFeatureBaseline
from garage.tf.algos import TRPO
from garage.tf.envs import TfEnv
from garage.tf.policies import CategoricalMLPPolicy

def run_task(*_):
    with LocalRunner() as runner:
        env = TfEnv(env_name='CartPole-v1')

        policy = CategoricalMLPPolicy(
            name='policy', env_spec=env.spec, hidden_sizes=(32, 32))

        baseline = LinearFeatureBaseline(env_spec=env.spec)

        algo = TRPO(
            env_spec=env.spec,
            policy=policy,
            baseline=baseline,
            max_path_length=100,
            discount=0.99,
            max_kl_step=0.01)

        runner.setup(algo, env)
        runner.train(n_epochs=100, batch_size=4000,plot=True)


run_experiment(
    run_task,
    snapshot_mode='last',
    seed=4,
    n_parallel=4,
    plot=True,
    use_tf=False,
    use_gpu=False
)
```
##########################################################
3) Why we removed viskit? I cannot find it in garage. 

Thanks！ I really like rllab and garage.



Discussion:
Please file different issues for different problems. This isn't a conversation forum, after all, this is a tool for developing software. I have forked your second issue into #698

viskit can be found at https://github.com/rlworkgroup/viskit or by installing using `pip install viskit` 

Can you please provide a specific launcher script which reproduces the problem you're describing (cannot plot during training)?

I tried these scripts in garage/example/tf/: trpo_cartpole.py, trpo_gym_cartpole.py, vpg_cartpole.py.
I set 
    `runner.train(n_epochs=100, batch_size=4000,plot=True)`
and 
    ```
    run_experiment(
    run_task,
    snapshot_mode='last',
    seed=1,
    plot=True
    )
    ```
but all of these scripts cannot plot during training.
I was able to confirm this bug.

For a hotfix, you can add `self.plot = plot` at the top of `LocalRunner._train()`:
```python
    def _train(self,
               n_epochs,
               n_epoch_cycles,
               batch_size,
               plot,
               store_paths,
               pause_for_plot,
               start_epoch=0):
        """Start actual training.

        Args:
            n_epochs(int): Number of epochs.
            n_epoch_cycles(int): Number of batches of samples in each epoch.
                This is only useful for off-policy algorithm.
                For on-policy algorithm this value should always be 1.
            batch_size(int): Number of steps in batch.
            plot(bool): Visualize policy by doing rollout after each epoch.
            store_paths(bool): Save paths in snapshot.
            pause_for_plot(bool): Pause for plot.
            start_epoch: (internal) The starting epoch.
                Use for experiment resuming.

        Returns:
            The average return in last epoch cycle.

        """
        assert self.has_setup, ('Use Runner.setup() to setup runner before '
                                'training.')

        # Save arguments for restore
        self.train_args = SimpleNamespace(
            n_epochs=n_epochs,
            n_epoch_cycles=n_epoch_cycles,
            batch_size=batch_size,
            plot=plot,
            store_paths=store_paths,
            pause_for_plot=pause_for_plot,
            start_epoch=start_epoch)

        self.plot = plot  # here
        self.start_worker()
```

@zequnyu @naeioi can you send in a fix?
Sure, I’ll do that.

Resolving patch:
diff --git a/src/garage/experiment/local_tf_runner.py b/src/garage/experiment/local_tf_runner.py
--- a/src/garage/experiment/local_tf_runner.py
+++ b/src/garage/experiment/local_tf_runner.py
@@ -388,6 +388,7 @@ def _train(self,
             pause_for_plot=pause_for_plot,
             start_epoch=start_epoch)
 
+        self.plot = plot
         self.start_worker()
 
         self.start_time = time.time()


Test patch:
diff --git a/tests/garage/experiment/test_local_tf_runner.py b/tests/garage/experiment/test_local_tf_runner.py
--- a/tests/garage/experiment/test_local_tf_runner.py
+++ b/tests/garage/experiment/test_local_tf_runner.py
@@ -5,6 +5,7 @@
 from garage.sampler import singleton_pool
 from garage.tf.algos import VPG
 from garage.tf.envs import TfEnv
+from garage.tf.plotter import Plotter
 from garage.tf.policies import CategoricalMLPPolicy
 from garage.tf.samplers import BatchSampler
 from tests.fixtures import TfGraphTestCase
@@ -45,7 +46,6 @@ def test_batch_sampler(self):
                 policy=policy,
                 baseline=baseline,
                 max_path_length=1,
-                whole_paths=True,
                 discount=0.99)
 
             runner.setup(
@@ -62,7 +62,8 @@ def test_batch_sampler(self):
 
             runner.start_worker()
 
-            paths = runner.sampler.obtain_samples(0, 8)
+            paths = runner.sampler.obtain_samples(
+                0, batch_size=8, whole_paths=True)
             self.assertGreaterEqual(
                 len(paths), max_cpus, 'BatchSampler should sample more than '
                 'max_cpus={} trajectories'.format(max_cpus))
@@ -103,3 +104,27 @@ def test_external_sess(self):
                 pass
             # sess should still be the default session here.
             tf.no_op().run()
+
+    def test_set_plot(self):
+        with LocalRunner() as runner:
+            env = TfEnv(env_name='CartPole-v1')
+
+            policy = CategoricalMLPPolicy(
+                name='policy', env_spec=env.spec, hidden_sizes=(8, 8))
+
+            baseline = LinearFeatureBaseline(env_spec=env.spec)
+
+            algo = VPG(
+                env_spec=env.spec,
+                policy=policy,
+                baseline=baseline,
+                max_path_length=100,
+                discount=0.99,
+                optimizer_args=dict(
+                    tf_optimizer_args=dict(learning_rate=0.01, )))
+
+            runner.setup(algo, env)
+            runner.train(n_epochs=1, batch_size=100, plot=True)
+
+            assert isinstance(runner.plotter, Plotter), (
+                'self.plotter in LocalRunner should be set to Plotter.')