code: def core_update(self):
      zero = tf_util.constant(value=0, dtype="int")
      one = tf_util.constant(value=1, dtype="int")
      true = tf_util.constant(value=True, dtype="bool")
  
      # Retrieve batch
      batch_size = self.update_batch_size.value()
      if self.update_unit == "timesteps":
          # Timestep-based batch
          # Dependency horizon
          past_horizon = tf.math.maximum(
              x=self.policy.past_horizon(on_policy=False),
              y=self.baseline.past_horizon(on_policy=False),
          )
          if self.predict_horizon_values != "late":
              future_horizon = zero
          elif self.reward_horizon == "episode":
              future_horizon = tf_util.constant(
                  value=self.max_episode_timesteps, dtype="int"
              )
          else:
              future_horizon = self.reward_horizon.value()
          indices = self.memory.retrieve_timesteps(
              n=batch_size,
              past_horizon=past_horizon,
              future_horizon=future_horizon,
          )
      elif self.update_unit == "episodes":
          # Episode-based batch
          indices = self.memory.retrieve_episodes(n=batch_size)
  
      # Retrieve states and internals
      policy_horizon = self.policy.past_horizon(on_policy=False)
      if self.separate_baseline and self.baseline_optimizer is None:
          assertions = list()
          if self.config.create_tf_assertions:
              assertions.append(
                  tf.debugging.assert_equal(
                      x=policy_horizon,
                      y=self.baseline.past_horizon(on_policy=False),
                      message="Policy and baseline cannot depend on a different number of previous "
                      "states if baseline_optimizer is None.",
                  )
              )
          with tf.control_dependencies(control_inputs=assertions):
              (
                  policy_horizons,
                  sequence_values,
                  initial_values,
              ) = self.memory.predecessors(
                  indices=indices,
                  horizon=policy_horizon,
                  sequence_values=("states",),
                  initial_values=("internals",),
              )
              baseline_horizons = policy_horizons
              baseline_states = policy_states = sequence_values[
                  "states"
              ]
              internals = policy_internals = initial_values["internals"]
              if self.separate_baseline:
                  baseline_internals = policy_internals["baseline"]
              else:
                  baseline_internals = policy_internals
      else:
          if self.baseline_optimizer is None:
              (
                  policy_horizons,
                  sequence_values,
                  initial_values,
              ) = self.memory.predecessors(
                  indices=indices,
                  horizon=policy_horizon,
                  sequence_values=("states",),
                  initial_values=("internals",),
              )
              policy_states = sequence_values["states"]
              internals = policy_internals = initial_values["internals"]
          elif len(self.internals_spec["policy"]) > 0:
              (
                  policy_horizons,
                  sequence_values,
                  initial_values,
              ) = self.memory.predecessors(
                  indices=indices,
                  horizon=policy_horizon,
                  sequence_values=("states",),
                  initial_values=("internals/policy",),
              )
              policy_states = sequence_values["states"]
              internals = initial_values["internals"]
              policy_internals = initial_values["internals/policy"]
          else:
              (
                  policy_horizons,
                  sequence_values,
              ) = self.memory.predecessors(
                  indices=indices,
                  horizon=policy_horizon,
                  sequence_values=("states",),
                  initial_values=(),
              )
              policy_states = sequence_values["states"]
              internals = policy_internals = TensorDict()
          # Optimize !!!!!
          baseline_horizon = self.baseline.past_horizon(on_policy=False)
          if self.separate_baseline:
              if len(self.internals_spec["baseline"]) > 0:
                  (
                      baseline_horizons,
                      sequence_values,
                      initial_values,
                  ) = self.memory.predecessors(
                      indices=indices,
                      horizon=baseline_horizon,
                      sequence_values=("states",),
                      initial_values=("internals/baseline",),
                  )
                  baseline_states = sequence_values["states"]
                  internals = initial_values["internals"]
                  baseline_internals = initial_values[
                      "internals/baseline"
                  ]
              else:
                  (
                      baseline_horizons,
                      sequence_values,
                  ) = self.memory.predecessors(
                      indices=indices,
                      horizon=baseline_horizon,
                      sequence_values=("states",),
                      initial_values=(),
                  )
                  baseline_states = sequence_values["states"]
                  internals = baseline_internals = TensorDict()
          else:
              if len(self.internals_spec["policy"]) > 0:
                  (
                      baseline_horizons,
                      sequence_values,
                      initial_values,
                  ) = self.memory.predecessors(
                      indices=indices,
                      horizon=baseline_horizon,
                      sequence_values=("states",),
                      initial_values=("internals/policy",),
                  )
                  baseline_states = sequence_values["states"]
                  internals = initial_values["internals"]
                  baseline_internals = initial_values[
                      "internals/policy"
                  ]
              else:
                  (
                      baseline_horizons,
                      sequence_values,
                  ) = self.memory.predecessors(
                      indices=indices,
                      horizon=baseline_horizon,
                      sequence_values=("states",),
                      initial_values=(),
                  )
                  baseline_states = sequence_values["states"]
                  internals = baseline_internals = TensorDict()
  
      # Retrieve auxiliaries, actions, reward
      if self.gae_decay.is_constant(value=0.0):
          values = self.memory.retrieve(
              indices=indices,
              values=("auxiliaries", "actions", "reward"),
          )
      else:
          values = self.memory.retrieve(
              indices=indices,
              values=("auxiliaries", "actions", "reward", "terminal"),
          )
          terminal = values["terminal"]
      auxiliaries = values["auxiliaries"]
      actions = values["actions"]
      reward = values["reward"]
  
      # Return estimation
      if self.predict_horizon_values == "late":
          reward = self._complete_horizon_values(
              indices=indices, internals=internals, reward=reward
          )
  
      dependencies = [reward]
      if (
          self.summaries == "all"
          or "reward" in self.summaries
          or self.tracking == "all"
          or "reward" in self.tracking
      ):
          if self.summaries == "all" or "reward" in self.summaries:
              summarizer = self.summarizer.as_default()
              summarizer.__enter__()
          else:
              summarizer = None
          x = tf.math.reduce_mean(input_tensor=reward, axis=0)
          if summarizer is not None:
              dependencies.append(
                  tf.summary.scalar(
                      name="update-return", data=x, step=self.updates
                  )
              )
          dependencies.extend(
              self.track(label="reward", name="update-return", data=x)
          )
          if summarizer is not None:
              summarizer.__exit__(None, None, None)
  
      if self.return_processing is not None:
          with tf.control_dependencies(control_inputs=dependencies):
              reward = self.return_processing.apply(
                  x=reward, deterministic=true, independent=False
              )
  
              dependencies = [reward]
              if (
                  self.summaries == "all"
                  or "reward" in self.summaries
                  or self.tracking == "all"
                  or "reward" in self.tracking
              ):
                  if (
                      self.summaries == "all"
                      or "reward" in self.summaries
                  ):
                      summarizer = self.summarizer.as_default()
                      summarizer.__enter__()
                  else:
                      summarizer = None
                  x = tf.math.reduce_mean(input_tensor=reward, axis=0)
                  if summarizer is not None:
                      dependencies.append(
                          tf.summary.scalar(
                              name="update-processed-return",
                              data=x,
                              step=self.updates,
                          )
                      )
                  dependencies.extend(
                      self.track(
                          label="reward",
                          name="update-processed-return",
                          data=x,
                      )
                  )
                  if summarizer is not None:
                      summarizer.__exit__(None, None, None)
  
      baseline_arguments = TensorDict(
          states=baseline_states,
          horizons=baseline_horizons,
          internals=baseline_internals,
          auxiliaries=auxiliaries,
          actions=actions,
          reward=reward,
      )
      if self.baseline_objective is not None:
          baseline_arguments[
              "reference"
          ] = self.baseline_objective.reference(
              states=baseline_states,
              horizons=baseline_horizons,
              internals=baseline_internals,
              auxiliaries=auxiliaries,
              actions=actions,
              policy=self.baseline,
          )
  
      if (
          self.baseline_optimizer is not None
          and self.estimate_advantage != "early"
      ):
  
          def fn_kl_divergence(
              *,
              states,
              horizons,
              internals,
              auxiliaries,
              actions,
              reward,
              reference,
          ):
              reference = self.baseline.kldiv_reference(
                  states=states,
                  horizons=horizons,
                  internals=internals,
                  auxiliaries=auxiliaries,
              )
              return self.baseline.kl_divergence(
                  states=states,
                  horizons=horizons,
                  internals=internals,
                  auxiliaries=auxiliaries,
                  reference=reference,
              )
  
          variables = tuple(self.baseline.trainable_variables)
  
          kwargs = dict()
          try:
              ordered_names = [variable.name for variable in variables]
              kwargs["source_variables"] = tuple(
                  sorted(
                      self.policy.trainable_variables,
                      key=(
                          lambda x: ordered_names.index(
                              x.name.replace("/policy/", "/baseline/")
                          )
                      ),
                  )
              )
          except ValueError:
              pass
  
          dependencies.extend(baseline_arguments.flatten())
  
          # Optimization
          with tf.control_dependencies(control_inputs=dependencies):
              optimized = self.baseline_optimizer.update(
                  arguments=baseline_arguments,
                  variables=variables,
                  fn_loss=self.baseline_loss,
                  fn_kl_divergence=fn_kl_divergence,
                  **kwargs,
              )
              dependencies = [optimized]
  
      with tf.control_dependencies(control_inputs=dependencies):
          if (
              self.estimate_advantage is not False
              and not self.advantage_in_loss
          ):
              if self.predict_action_values:
                  # Use past actions since advantage R(s,a) - Q(s,a)
                  baseline_prediction = self.baseline.action_value(
                      states=baseline_states,
                      horizons=baseline_horizons,
                      internals=baseline_internals,
                      auxiliaries=auxiliaries,
                      actions=actions,
                  )
              else:
                  baseline_prediction = self.baseline.state_value(
                      states=baseline_states,
                      horizons=baseline_horizons,
                      internals=baseline_internals,
                      auxiliaries=auxiliaries,
                  )
              reward = reward - baseline_prediction
  
              dependencies = [reward]
              if (
                  self.summaries == "all"
                  or "reward" in self.summaries
                  or self.tracking == "all"
                  or "reward" in self.tracking
              ):
                  if (
                      self.summaries == "all"
                      or "reward" in self.summaries
                  ):
                      summarizer = self.summarizer.as_default()
                      summarizer.__enter__()
                  else:
                      summarizer = None
                  x = tf.math.reduce_mean(input_tensor=reward, axis=0)
                  if summarizer is not None:
                      dependencies.append(
                          tf.summary.scalar(
                              name="update-advantage",
                              data=x,
                              step=self.updates,
                          )
                      )
                  dependencies.extend(
                      self.track(
                          label="reward",
                          name="update-advantage",
                          data=x,
                      )
                  )
                  if summarizer is not None:
                      summarizer.__exit__(None, None, None)
  
              if self.advantage_processing is not None:
                  with tf.control_dependencies(
                      control_inputs=dependencies
                  ):
                      reward = self.advantage_processing.apply(
                          x=reward,
                          deterministic=true,
                          independent=False,
                      )
  
                      dependencies = [reward]
                      if (
                          self.summaries == "all"
                          or "reward" in self.summaries
                          or self.tracking == "all"
                          or "reward" in self.tracking
                      ):
                          if (
                              self.summaries == "all"
                              or "reward" in self.summaries
                          ):
                              summarizer = self.summarizer.as_default()
                              summarizer.__enter__()
                          else:
                              summarizer = None
                          x = tf.math.reduce_mean(
                              input_tensor=reward, axis=0
                          )
                          if summarizer is not None:
                              dependencies.append(
                                  tf.summary.scalar(
                                      name="update-processed-advantage",
                                      data=x,
                                      step=self.updates,
                                  )
                              )
                          dependencies.extend(
                              self.track(
                                  label="reward",
                                  name="update-processed-advantage",
                                  data=x,
                              )
                          )
                          if summarizer is not None:
                              summarizer.__exit__(None, None, None)
  
              if not self.gae_decay.is_constant(value=0.0):
                  with tf.control_dependencies(
                      control_inputs=dependencies
                  ):
                      # Requires consistent batch!!!
                      zero_float = tf_util.constant(
                          value=0.0, dtype="float"
                      )
                      reward_discount = self.reward_discount.value()
                      gae_decay = self.gae_decay.value()
  
                      # Discounted cumulative sum
                      def recursive_gae(next_gae, advantage_terminal):
                          (
                              current_advantage,
                              current_terminal,
                          ) = advantage_terminal
                          next_gae = tf.where(
                              condition=(current_terminal == zero),
                              x=next_gae,
                              y=zero_float,
                          )
                          return (
                              current_advantage
                              + reward_discount * gae_decay * next_gae
                          )
  
                      reward = tf.scan(
                          fn=recursive_gae,
                          elems=(reward, terminal),
                          initializer=zero_float,
                          reverse=True,
                      )
  
                      dependencies = [reward]
                      if (
                          self.summaries == "all"
                          or "reward" in self.summaries
                          or self.tracking == "all"
                          or "reward" in self.tracking
                      ):
                          if (
                              self.summaries == "all"
                              or "reward" in self.summaries
                          ):
                              summarizer = self.summarizer.as_default()
                              summarizer.__enter__()
                          else:
                              summarizer = None
                          x = tf.math.reduce_mean(
                              input_tensor=reward, axis=0
                          )
                          if summarizer is not None:
                              dependencies.append(
                                  tf.summary.scalar(
                                      name="update-gae",
                                      data=x,
                                      step=self.updates,
                                  )
                              )
                          dependencies.extend(
                              self.track(
                                  label="reward",
                                  name="update-gae",
                                  data=x,
                              )
                          )
                          if summarizer is not None:
                              summarizer.__exit__(None, None, None)
  
      if self.baseline_optimizer is None:
          policy_only_internals = policy_internals["policy"]
      else:
          policy_only_internals = policy_internals
      reference = self.objective.reference(
          states=policy_states,
          horizons=policy_horizons,
          internals=policy_only_internals,
          auxiliaries=auxiliaries,
          actions=actions,
          policy=self.policy,
      )
      if (
          self.baseline_objective is not None
          and self.baseline_loss_weight is not None
          and not self.baseline_loss_weight.is_constant(value=0.0)
      ):
          reference = TensorDict(
              policy=reference, baseline=baseline_arguments["reference"]
          )
  
      policy_arguments = TensorDict(
          states=policy_states,
          horizons=policy_horizons,
          internals=policy_internals,
          auxiliaries=auxiliaries,
          actions=actions,
          reward=reward,
          reference=reference,
      )
  
      if (
          self.estimate_advantage is not False
          and self.advantage_in_loss
      ):
          variables = tuple(self.trainable_variables)
  
          def fn_loss(
              *,
              states,
              horizons,
              internals,
              auxiliaries,
              actions,
              reward,
              reference,
          ):
              assertions = list()
              if self.config.create_tf_assertions:
                  past_horizon = self.baseline.past_horizon(
                      on_policy=False
                  )
                  # TODO: remove restriction
                  assertions.append(
                      tf.debugging.assert_less_equal(
                          x=(horizons[:, 1] - one),
                          y=past_horizon,
                          message="Baseline horizon cannot be greater than policy horizon.",
                      )
                  )
              with tf.control_dependencies(control_inputs=assertions):
                  if self.predict_action_values:
                      # Use past actions since advantage R(s,a) - Q(s,a)
                      baseline_prediction = self.baseline.action_value(
                          states=states,
                          horizons=horizons,
                          internals=internals["baseline"],
                          auxiliaries=auxiliaries,
                          actions=actions,
                      )
                  else:
                      baseline_prediction = self.baseline.state_value(
                          states=states,
                          horizons=horizons,
                          internals=internals["baseline"],
                          auxiliaries=auxiliaries,
                      )
                  reward = reward - baseline_prediction
  
                  def fn_summary1():
                      return tf.math.reduce_mean(
                          input_tensor=reward, axis=0
                      )
  
                  dependencies = self.summary(
                      label="reward",
                      name="update-advantage",
                      data=fn_summary1,
                      step="updates",
                  )
                  dependencies.extend(
                      self.track(
                          label="reward",
                          name="update-advantage",
                          data=fn_summary1,
                      )
                  )
  
                  if self.advantage_processing is not None:
                      with tf.control_dependencies(
                          control_inputs=dependencies
                      ):
                          reward = self.advantage_processing.apply(
                              x=reward,
                              deterministic=true,
                              independent=False,
                          )
  
                          def fn_summary2():
                              return tf.math.reduce_mean(
                                  input_tensor=reward, axis=0
                              )
  
                          dependencies = self.summary(
                              label="reward",
                              name="update-processed-advantage",
                              data=fn_summary2,
                              step="updates",
                          )
                          dependencies.extend(
                              self.track(
                                  label="reward",
                                  name="update-processed-advantage",
                                  data=fn_summary2,
                              )
                          )
  
              with tf.control_dependencies(control_inputs=dependencies):
                  return self.loss(
                      states=states,
                      horizons=horizons,
                      internals=internals,
                      auxiliaries=auxiliaries,
                      actions=actions,
                      reward=reward,
                      reference=reference,
                  )
  
      else:
          variables = tuple(self.policy.trainable_variables)
          fn_loss = self.loss
  
      def fn_kl_divergence(
          *,
          states,
          horizons,
          internals,
          auxiliaries,
          actions,
          reward,
          reference,
      ):
          if self.baseline_optimizer is None:
              internals = internals["policy"]
          # TODO: Policy require
          reference = self.policy.kldiv_reference(
              states=states,
              horizons=horizons,
              internals=internals,
              auxiliaries=auxiliaries,
          )
          return self.policy.kl_divergence(
              states=states,
              horizons=horizons,
              internals=internals,
              auxiliaries=auxiliaries,
              reference=reference,
          )
  
      kwargs = dict()
      if self.separate_baseline:
          try:
              ordered_names = [variable.name for variable in variables]
              kwargs["source_variables"] = tuple(
                  sorted(
                      self.baseline.trainable_variables,
                      key=(
                          lambda x: ordered_names.index(
                              x.name.replace("/baseline/", "/policy/")
                          )
                      ),
                  )
              )
          except ValueError:
              pass
      # if self.global_model is not None:
      #     assert 'global_variables' not in kwargs
      #     kwargs['global_variables'] = tuple(self.global_model.trainable_variables)
  
      dependencies.extend(policy_arguments.flatten())
  
      # Hack: KL divergence summary: reference before update
      if isinstance(self.policy, StochasticPolicy) and (
          self.summaries == "all"
          or "kl-divergence" in self.summaries
          or self.tracking == "all"
          or "kl-divergence" in self.tracking
      ):
          kldiv_reference = self.policy.kldiv_reference(
              states=policy_states,
              horizons=policy_horizons,
              internals=policy_only_internals,
              auxiliaries=auxiliaries,
          )
          dependencies.extend(kldiv_reference.flatten())
  
      # Optimization
      with tf.control_dependencies(control_inputs=dependencies):
          optimized = self.optimizer.update(
              arguments=policy_arguments,
              variables=variables,
              fn_loss=fn_loss,
              fn_kl_divergence=fn_kl_divergence,
              **kwargs,
          )
          dependencies = [optimized]
  
      if (
          self.baseline_optimizer is not None
          and self.estimate_advantage == "early"
      ):
  
          def fn_kl_divergence(
              *,
              states,
              horizons,
              internals,
              auxiliaries,
              actions,
              reward,
              reference,
          ):
              reference = self.baseline.kldiv_reference(
                  states=states,
                  horizons=horizons,
                  internals=internals,
                  auxiliaries=auxiliaries,
              )
              return self.baseline.kl_divergence(
                  states=states,
                  horizons=horizons,
                  internals=internals,
                  auxiliaries=auxiliaries,
                  reference=reference,
              )
  
          variables = tuple(self.baseline.trainable_variables)
  
          kwargs = dict()
          try:
              ordered_names = [variable.name for variable in variables]
              kwargs["source_variables"] = tuple(
                  sorted(
                      self.policy.trainable_variables,
                      key=(
                          lambda x: ordered_names.index(
                              x.name.replace("/policy/", "/baseline/")
                          )
                      ),
                  )
              )
          except ValueError:
              pass
  
          dependencies.extend(baseline_arguments.flatten())
  
          # Optimization
          with tf.control_dependencies(control_inputs=dependencies):
              optimized = self.baseline_optimizer.update(
                  arguments=baseline_arguments,
                  variables=variables,
                  fn_loss=self.baseline_loss,
                  fn_kl_divergence=fn_kl_divergence,
                  **kwargs,
              )
              dependencies = [optimized]
  
      # Update summaries
      with tf.control_dependencies(control_inputs=dependencies):
          dependencies = list()
  
          # Entropy summaries
          if isinstance(self.policy, StochasticPolicy) and (
              self.summaries == "all"
              or "entropy" in self.summaries
              or self.tracking == "all"
              or "entropy" in self.tracking
          ):
              if self.summaries == "all" or "entropy" in self.summaries:
                  summarizer = self.summarizer.as_default()
                  summarizer.__enter__()
              else:
                  summarizer = None
              if len(self.actions_spec) > 1:
                  entropies = self.policy.entropies(
                      states=policy_states,
                      horizons=policy_horizons,
                      internals=policy_only_internals,
                      auxiliaries=auxiliaries,
                  )
                  for name, spec in self.actions_spec.items():
                      entropies[name] = tf.reshape(
                          tensor=entropies[name], shape=(-1,)
                      )
                      entropy = tf.math.reduce_mean(
                          input_tensor=entropies[name], axis=0
                      )
                      if summarizer is not None:
                          dependencies.append(
                              tf.summary.scalar(
                                  name=("entropies/" + name),
                                  data=entropy,
                                  step=self.updates,
                              )
                          )
                      dependencies.extend(
                          self.track(
                              label="entropy",
                              name=("entropies/" + name),
                              data=entropy,
                          )
                      )
                  entropy = tf.concat(
                      values=tuple(entropies.values()), axis=0
                  )
              else:
                  entropy = self.policy.entropy(
                      states=policy_states,
                      horizons=policy_horizons,
                      internals=policy_only_internals,
                      auxiliaries=auxiliaries,
                  )
              entropy = tf.math.reduce_mean(
                  input_tensor=entropy, axis=0
              )
              if summarizer is not None:
                  dependencies.append(
                      tf.summary.scalar(
                          name="entropy",
                          data=entropy,
                          step=self.updates,
                      )
                  )
              dependencies.extend(
                  self.track(
                      label="entropy", name="entropy", data=entropy
                  )
              )
              if summarizer is not None:
                  summarizer.__exit__(None, None, None)
  
          # KL divergence summaries
          if isinstance(self.policy, StochasticPolicy) and (
              self.summaries == "all"
              or "kl-divergence" in self.summaries
              or self.tracking == "all"
              or "kl-divergence" in self.tracking
          ):
              if (
                  self.summaries == "all"
                  or "kl-divergence" in self.summaries
              ):
                  summarizer = self.summarizer.as_default()
                  summarizer.__enter__()
              else:
                  summarizer = None
              if len(self.actions_spec) > 1:
                  kl_divs = self.policy.kl_divergences(
                      states=policy_states,
                      horizons=policy_horizons,
                      internals=policy_only_internals,
                      auxiliaries=auxiliaries,
                      reference=kldiv_reference,
                  )
                  for name, spec in self.actions_spec.items():
                      kl_divs[name] = tf.reshape(
                          tensor=kl_divs[name], shape=(-1,)
                      )
                      kl_div = tf.math.reduce_mean(
                          input_tensor=kl_divs[name], axis=0
                      )
                      if summarizer is not None:
                          dependencies.append(
                              tf.summary.scalar(
                                  name=("kl-divergences/" + name),
                                  data=kl_div,
                                  step=self.updates,
                              )
                          )
                      dependencies.extend(
                          self.track(
                              label="kl-divergence",
                              name=("kl-divergences/" + name),
                              data=kl_div,
                          )
                      )
                  kl_div = tf.concat(
                      values=tuple(kl_divs.values()), axis=0
                  )
              else:
                  kl_div = self.policy.kl_divergence(
                      states=policy_states,
                      horizons=policy_horizons,
                      internals=policy_only_internals,
                      auxiliaries=auxiliaries,
                      reference=kldiv_reference,
                  )
              kl_div = tf.math.reduce_mean(input_tensor=kl_div, axis=0)
              if summarizer is not None:
                  dependencies.append(
                      tf.summary.scalar(
                          name="kl-divergence",
                          data=kl_div,
                          step=self.updates,
                      )
                  )
              dependencies.extend(
                  self.track(
                      label="kl-divergence",
                      name="kl-divergence",
                      data=kl_div,
                  )
              )
              if summarizer is not None:
                  summarizer.__exit__(None, None, None)
  
      # Increment update
      with tf.control_dependencies(control_inputs=dependencies):
          assignment = self.updates.assign_add(
              delta=one, read_value=False
          )
  
      with tf.control_dependencies(control_inputs=(assignment,)):
          dependencies = list()
  
          # Variables summaries
          if self.summaries == "all" or "variables" in self.summaries:
              with self.summarizer.as_default():
                  for variable in self.trainable_variables:
                      name = variable.name
                      assert name[-2] == ":"
                      if name.startswith(self.name + "/"):
                          name = (
                              "variables/"
                              + name[len(self.name) + 1 : -2]
                          )
                      else:
                          name = name[:-2]
                      x = tf.math.reduce_mean(input_tensor=variable)
                      dependencies.append(
                          tf.summary.scalar(
                              name=name, data=x, step=self.updates
                          )
                      )
  
      with tf.control_dependencies(control_inputs=dependencies):
          return tf_util.identity(input=optimized)
  
imports: import logging
  import tensorflow
  from tensorforce import TensorforceError
  from tensorforce.core import ModuleDict, memory_modules, optimizer_modules, parameter_modules, SignatureDict, TensorDict, TensorSpec, TensorsSpec, tf_function, tf_util, VariableDict
  from tensorforce.core.models import Model
  from tensorforce.core.networks import Preprocessor
  from tensorforce.core.objectives import objective_modules
  from tensorforce.core.policies import policy_modules, StochasticPolicy
label_desc: Use image node_id 18 for calling the TensorforceModel obj's underlying member method code with example usage: obj.core_update() and returns: self, tf_util, self, self, self, tf, unknown, tf