title: Basic function minimisation and variable tracking in TensorFlow 2.0
body: <p>I am trying to perform the most basic function minimisation possible in TensorFlow 2.0, exactly as in the question <a href="https://stackoverflow.com/q/55552715/1447953">Tensorflow 2.0: minimize a simple function</a>, however I cannot get the solution described there to work. Here is my attempt, mostly copy-pasted but with some bits that seemed to be missing added in.</p>
  
  <pre><code>import tensorflow as tf
  
  x = tf.Variable(2, name='x', trainable=True, dtype=tf.float32)
  with tf.GradientTape() as t:
      y = tf.math.square(x)
  
  # Is the tape that computes the gradients!
  trainable_variables = [x]
  
  #### Option 2
  # To use minimize you have to define your loss computation as a funcction
  def compute_loss():
      y = tf.math.square(x)
      return y
  
  opt = tf.optimizers.Adam(learning_rate=0.001)
  train = opt.minimize(compute_loss, var_list=trainable_variables)
  
  print("x:", x)
  print("y:", y)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>x: &lt;tf.Variable 'x:0' shape=() dtype=float32, numpy=1.999&gt;
  y: tf.Tensor(4.0, shape=(), dtype=float32)
  </code></pre>
  
  <p>So it says the minimum is at <code>x=1.999</code>, but obviously that is wrong. So what happened? I suppose it only performed one loop of the minimiser or something? If so then "minimize" seems like a terrible name for the function. How is this supposed to work?</p>
  
  <p>On a side note, I also need to know the values of intermediate variables that are calculated in the loss function (the example only has <code>y</code>, but imagine that it took several steps to compute <code>y</code> and I want all those numbers). I don't think I am using the gradient tape correctly either, it is not obvious to me that it has anything to do with the computations in the loss function (I just copied this stuff from the other question).</p>