class_docstr: Program definition for distributed DDPG (D3PG).
class_docstr_tok: ["Program","definition","for","distributed","DDPG","(","D3PG",")","."]
docstr: The Learning part of the agent.
docstr_tok: ["The","Learning","part","of","the","agent","."]
code: def learner(
      self,
      replay: reverb.Client,
      counter: counting.Counter,
  ):
      """The Learning part of the agent."""
  
      act_spec = self._environment_spec.actions
      obs_spec = self._environment_spec.observations
  
      # Create the networks to optimize (online) and target networks.
      online_networks = self._network_factory(act_spec)
      target_networks = self._network_factory(act_spec)
  
      # Make sure observation network is a Sonnet Module.
      observation_network = online_networks.get(
          "observation", tf.identity
      )
      target_observation_network = target_networks.get(
          "observation", tf.identity
      )
      observation_network = tf2_utils.to_sonnet_module(
          observation_network
      )
      target_observation_network = tf2_utils.to_sonnet_module(
          target_observation_network
      )
  
      # Get embedding spec and create observation network variables.
      emb_spec = tf2_utils.create_variables(
          observation_network, [obs_spec]
      )
  
      # Create variables.
      tf2_utils.create_variables(online_networks["policy"], [emb_spec])
      tf2_utils.create_variables(
          online_networks["critic"], [emb_spec, act_spec]
      )
      tf2_utils.create_variables(target_networks["policy"], [emb_spec])
      tf2_utils.create_variables(
          target_networks["critic"], [emb_spec, act_spec]
      )
      tf2_utils.create_variables(target_observation_network, [obs_spec])
  
      # The dataset object to learn from.
      dataset = datasets.make_reverb_dataset(
          server_address=replay.server_address,
          batch_size=self._batch_size,
          prefetch_size=self._prefetch_size,
      )
  
      # Create optimizers.
      policy_optimizer = snt.optimizers.Adam(learning_rate=1e-4)
      critic_optimizer = snt.optimizers.Adam(learning_rate=1e-4)
  
      counter = counting.Counter(counter, "learner")
      logger = loggers.make_default_logger(
          "learner",
          time_delta=self._log_every,
          steps_key="learner_steps",
      )
  
      # Return the learning agent.
      return learning.DDPGLearner(
          policy_network=online_networks["policy"],
          critic_network=online_networks["critic"],
          observation_network=observation_network,
          target_policy_network=target_networks["policy"],
          target_critic_network=target_networks["critic"],
          target_observation_network=target_observation_network,
          discount=self._discount,
          target_update_period=self._target_update_period,
          dataset=dataset,
          policy_optimizer=policy_optimizer,
          critic_optimizer=critic_optimizer,
          clipping=self._clipping,
          counter=counter,
          logger=logger,
      )
  
imports: from typing import Callable, Dict, Optional
  import acme
  from acme import datasets
  from acme import specs
  from acme.adders import reverb
  from acme.agents.tf import actors
  from acme.agents.tf.ddpg import learning
  from acme.tf import networks
  from acme.tf import savers
  from acme.tf import utils
  from acme.tf import variable_utils
  from acme.utils import counting
  from acme.utils import loggers
  from acme.utils import lp_utils
  import dm_env
  import launchpad
  import reverb
  import sonnet
  import tensorflow
label_desc: Use image node_id 5 for calling the DistributedDDPG obj's underlying member method code with example usage: obj.learner(replay, counter) and returns: learning