input: Write a python function to optimize a state using simulated annealing.
  assert optimize([1.0, 1.0, 1.0, 1.0]) == -4.0
  assert optimize([0.0, 0.0, 0.0, 0.0]) == 0.0
  assert optimize([2.0, 2.0, 2.0, 2.0]) == -12.0
output: import math
  import random
  
  def optimize(state):
      def objective_function(state):
          return -sum(x**2 for x in state)
  
      def neighbor(state):
          idx = random.randint(0, len(state) - 1)
          new_state = state[:]
          new_state[idx] += random.uniform(-1, 1)
          return new_state
  
      def acceptance_probability(old_cost, new_cost, temperature):
          if new_cost < old_cost:
              return 1.0
          return math.exp((old_cost - new_cost) / temperature)
  
      temperature = 1.0
      cooling_rate = 0.99
      current_state = state
      current_cost = objective_function(current_state)
  
      while temperature > 0.01:
          new_state = neighbor(current_state)
          new_cost = objective_function(new_state)
  
          if acceptance_probability(current_cost, new_cost, temperature) > random.random():
              current_state = new_state
              current_cost = new_cost
  
          temperature *= cooling_rate
  
      return current_cost