import argparse

from sigopt import Connection

# Take a suggestion from sigopt and evaluate your function
def evaluate_metric(assignments):
  x = assignments['x']
  raise NotImplementedError("Return a number, which represents your metric evaluated at x")

if __name__ == '__main__':
  parser = argparse.ArgumentParser()
  parser.add_argument('--iterations', type=int, default=20)
  parser.add_argument('--client_token', required=True, help="Find your CLIENT_TOKEN at https://sigopt.com/user/profile")
  the_args = parser.parse_args()

  connection = Connection(client_token=the_args.client_token)

  # Create an experiment with one paramter, x
  experiment = connection.experiments().create(
    name="Basic Test experiment",
    parameters=[{'name': 'x', 'bounds': {'max': 50.0, 'min': 0.0}, 'type': 'double'}],
  )
  print('Created experiment id {0}'.format(experiment.id))

  # In a loop: receive a suggestion, evaluate the metric, report an observation
  for _ in range(the_args.iterations):
    suggestion = connection.experiments(experiment.id).suggestions().create()
    print('Evaluating at suggested assignments: {0}'.format(suggestion.assignments))
    value = evaluate_metric(suggestion.assignments)
    print('Reporting observation of value: {0}'.format(value))
    connection.experiments(experiment.id).observations().create(
      suggestion=suggestion.id,
      value=value,
    )

@@ -807,16 +807,60 @@
 ble'%7D%5D,%0A
+    observation_budget=the_args.iterations,%0A
   )%0A  pr
@@ -1012,35 +1012,45 @@
 n range(
-the_args.it
+experiment.obs
 er
+v
 ation
-s
+_budget
 ):%0A    s

Add budget to example