class_docstr: A DDPG Agent.
code: def _train(self, experience, weights=None):
      transition = self._as_transition(experience)
      time_steps, policy_steps, next_time_steps = transition
      actions = policy_steps.action
  
      # TODO(b/124382524): Apply a loss mask or filter boundary transitions.
      trainable_critic_variables = (
          self._critic_network.trainable_variables
      )
      with tf.GradientTape(watch_accessed_variables=False) as tape:
          assert (
              trainable_critic_variables
          ), "No trainable critic variables to optimize."
          tape.watch(trainable_critic_variables)
          critic_loss = self.critic_loss(
              time_steps,
              actions,
              next_time_steps,
              weights=weights,
              training=True,
          )
      tf.debugging.check_numerics(
          critic_loss, "Critic loss is inf or nan."
      )
      critic_grads = tape.gradient(
          critic_loss, trainable_critic_variables
      )
      self._apply_gradients(
          critic_grads,
          trainable_critic_variables,
          self._critic_optimizer,
      )
  
      trainable_actor_variables = (
          self._actor_network.trainable_variables
      )
      with tf.GradientTape(watch_accessed_variables=False) as tape:
          assert (
              trainable_actor_variables
          ), "No trainable actor variables to optimize."
          tape.watch(trainable_actor_variables)
          actor_loss = self.actor_loss(
              time_steps, weights=weights, training=True
          )
      tf.debugging.check_numerics(
          actor_loss, "Actor loss is inf or nan."
      )
      actor_grads = tape.gradient(actor_loss, trainable_actor_variables)
      self._apply_gradients(
          actor_grads, trainable_actor_variables, self._actor_optimizer
      )
  
      self.train_step_counter.assign_add(1)
      self._update_target()
  
      # TODO(b/124382360): Compute per element TD loss and return in loss_info.
      total_loss = actor_loss + critic_loss
      return tf_agent.LossInfo(
          total_loss, DdpgInfo(actor_loss, critic_loss)
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from typing import Optional, Text
  import gin
  import tensorflow
  from tf_agents.agents import data_converter
  from tf_agents.agents import tf_agent
  from tf_agents.networks import network
  from tf_agents.policies import actor_policy
  from tf_agents.policies import ou_noise_policy
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tf_agents.utils import common
  from tf_agents.utils import eager_utils
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 4 for calling the DdpgAgent obj's underlying member method code with example usage: obj._train(experience, weights) and returns: tf_agent