code: def maxcut_qaoa(
          graph,
          steps=DEFAULT_STEPS,
          learning_rate=LEARNING_RATE,
          verbose=False):
      
  
      if not isinstance(graph, nx.Graph):
          graph = nx.from_edgelist(graph)
  
      init_scale = 0.01
      init_bias = 0.5
  
      init_beta = normal(loc=init_bias, scale=init_scale, size=[steps])
      init_gamma = normal(loc=init_bias, scale=init_scale, size=[steps])
  
      beta = tf.get_variable('beta', initializer=init_beta)
      gamma = tf.get_variable('gamma', initializer=init_gamma)
  
      circ = qubo_circuit(graph, steps, beta, gamma)
      cuts = graph_cuts(graph)
      maxcut = cuts.max()
      expect = circ.run().expectation(cuts)
      loss = - expect
  
      # === Optimization ===
      opt = tf.train.GradientDescentOptimizer(learning_rate=learning_rate)
      train = opt.minimize(loss, var_list=[beta, gamma])
  
      with tf.Session() as sess:
          init_op = tf.global_variables_initializer()
          sess.run(init_op)
  
          block = 10
          min_difference = 0.0001
          last_ratio = -1
          for step in range(0, MAX_OPT_STEPS, block):
              for _ in range(block):
                  sess.run(train)
              ratio = sess.run(expect) / maxcut
              if ratio - last_ratio < min_difference:
                  break
              last_ratio = ratio
  
              if verbose:
                  print("# step: {}  ratio: {:.4f}%".format(step, ratio))
  
          opt_beta = sess.run(beta)
          opt_gamma = sess.run(gamma)
  
      return ratio, opt_beta, opt_gamma
docs: QAOA Maxcut using tensorflow