Skip to content

Commit

Permalink
Adding a "should_update" parameter in the EnvironmentLoop, controllin…
Browse files Browse the repository at this point in the history
…g wether to update the agent in the loop or not.

PiperOrigin-RevId: 328309700
Change-Id: I88347e2d7b8a4bf4c2dee05ce1d68b010e94df84
  • Loading branch information
leonardhussenot authored and Copybara-Service committed Aug 25, 2020
1 parent 5537cc8 commit c69c50e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions acme/environment_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EnvironmentLoop(core.Worker):
"""A simple RL environment loop.
This takes `Environment` and `Actor` instances and coordinates their
interaction. This can be used as:
interaction. Agent is updated if `should_update=True`. This can be used as:
loop = EnvironmentLoop(environment, actor)
loop.run(num_episodes)
Expand All @@ -52,13 +52,15 @@ def __init__(
actor: core.Actor,
counter: counting.Counter = None,
logger: loggers.Logger = None,
should_update: bool = True,
label: str = 'environment_loop',
):
# Internalize agent and environment.
self._environment = environment
self._actor = actor
self._counter = counter or counting.Counter()
self._logger = logger or loggers.make_default_logger(label)
self._should_update = should_update

def run_episode(self) -> loggers.LoggingData:
"""Run one episode.
Expand Down Expand Up @@ -87,7 +89,8 @@ def run_episode(self) -> loggers.LoggingData:

# Have the agent observe the timestep and let the actor update itself.
self._actor.observe(action, next_timestep=timestep)
self._actor.update()
if self._should_update:
self._actor.update()

# Book-keeping.
episode_steps += 1
Expand Down

0 comments on commit c69c50e

Please sign in to comment.