def get_next_id(self):
        try:
            query = {'_id': 'last_id'}
            update = {'$inc': {'id': 1}}
            fn = self.db.internal.find_and_modify
            row = fn(query, update, upsert=True, new=True)
        except Exception as e:
            raise DatabaseException(e)
        return row['id']
def _compute_reg_grads(gen_grads, disc_vars):
  """Compute gradients norm (this is an upper-bpund of the full-batch norm)."""
  gen_norm = tf.accumulate_n([tf.reduce_sum(u * u) for u in gen_grads])
  disc_reg_grads = tf.gradients(gen_norm, disc_vars)
  return disc_reg_grads